Effacer les filtres
Effacer les filtres

Matlab does not seem to recognise my inputted commands

1 vue (au cours des 30 derniers jours)
Kirsty James
Kirsty James le 20 Fév 2013
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.

Réponse acceptée

Thorsten
Thorsten le 21 Fév 2013
You have to define t before you can use it
t = ... % whatever you need
L = interpl(Lt,L,t);

Plus de réponses (1)

Walter Roberson
Walter Roberson le 20 Fév 2013
You seem to have three lines of code before you define your function "daisyworld1". That is a problem.
  1 commentaire
Kirsty James
Kirsty James le 21 Fév 2013
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

Connectez-vous pour commenter.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by