필터 지우기
필터 지우기

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 CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by