Matlab does not seem to recognise my inputted commands

1 回表示 (過去 30 日間)
Kirsty James
Kirsty James 2013 年 2 月 20 日
I am currently writing a set of codes but i cannot get Matlab to recognise that i have defined values for t. I have been told to use the "interpl" command but that doesn't seem to work either so i'm unsure how to debug this.
Here are my codes:
This is the file named daisyworld1
Lt=linspace(0,5); %generate t for L
L=5*Lt+2; %luminosity function
f=interpl(Lt,L,t); %interpolate the data set (Lt,L) at time t
function dydt =daisyworld1(t,y,Lt,L);
dydt = [0;0];
A=((1-y(1)-y(2))*0.5)+(y(1)*0.25)+(y(2)*0.75); %albedo
S=917; %constant solar energy
Z=5.67*10^(-8); %Stefan-Boltzmann constant;
Te=((((S*L)/Z)*(1-A)).^(1/4))-273; %plantary temperature
B=1-0.003265*((22.5-Te).^2); %beta value, local temperature function
g=0.2; %x-value
dydt(1)=y(1)*(( (1-y(1)-y(2)) *B)-g);
dydt(2)=y(2)*(( (1-y(1)-y(2)) *B)-g);
And this is the code for solving it using ode45
t0=0; % Start time
tf=0.5; % End time
Lt=linspace(0,5,25); %generate t for L
L=5*Lt+2; %luminosity function
L=interpl(Lt,L,t); %interpolate the data set (Lt,L) at time t
options=odeset('RelTol', 1e-4);% Sets the error tolerance of the ODE solver
aw=0.4; % Initial white daisy area
ab=0.2; % Initial black daisy area
[t, y]=ode45(@(t,y)daisyworld1(t,y,Lt,L),[aw ab],options); % Solves the equations
plot(t,y) % Plots the daisy area coverage against time
% Blue line is white daisies
% Green line is black daisies
The error message i keep getting is
Undefined function or variable 't'.
Error in daisyworldode45 (line 11)
L=interpl(Lt,L,t); %interpolate the data set (Lt,L) at time t
I am trying to plot the coverage of daisies against Luminosity which i am using an increasing function of time for.
Any help would be much appreciated, thank you.

採用された回答

Thorsten
Thorsten 2013 年 2 月 21 日
You have to define t before you can use it
t = ... % whatever you need
L = interpl(Lt,L,t);

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2013 年 2 月 20 日
You seem to have three lines of code before you define your function "daisyworld1". That is a problem.
  1 件のコメント
Kirsty James
Kirsty James 2013 年 2 月 21 日
Hi, I have tried putting those lines of coding beneath defining the function and i still get the same error code of
daisyworldode45 Undefined function or variable 't'.
Error in daisyworldode45 (line 11) L=interpl(Lt,L,t); %interpolate the data set (Lt,L) at time t
When i run daisyworldode45

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLarge Files and Big Data についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by