Hi i have written a for loop for several variables that i have defined in other coding. I cannot seem to get matlab to recognise these vectors that i have already defined, I am relatively new to matlab and i am unsure if i have set up the for loop correctly. Any help would be great
this defines daisyworld 1
function dydt =daisyworld1(t,y,Lt,L) Lint=interp1(Lt,L,t); %interpolate the data set (Lt,L) at time t
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*Lint)/Z)*(1-A)).^(1/4))-273; %plantary temperature
B= 1-0.003265*((22.5-Te).^2); %beta value,
g=0.3; %death term
dydt(1)=y(1)*(( (1-y(1)-y(2)) *B)-g); %black daisy formula
dydt(2)=y(2)*(( (1-y(1)-y(2)) *B)-g); %white daisy formula
I then solve it using ode45clear; % Remove stored variables daisyworldode45
Lt=linspace(0,1000,25); %generate t for L
L=Lt/500+ 0.4; %luminosity function want to keep within a range of 0 and 2 so change depending on tspan
tspan=[0 1000]; %solve for values of t
IC = [0.2 0.3]; %initial conditions of daisy percentage, black then white
[T, Y]=ode45(@(t,y)daisyworld1(t,y,Lt,L),tspan,IC); % solves equation, need capital T and Y
I am trying to extract these values of T and Y, and use the vector T to find values for L and then plot these against Te
N=7269;Te= zeros(1,N);for T=0:N for Y=0:N Te(T,Y)=((917*(T/500+0.4)/(5.67*10^(-8))*(1-(((1-y(1)-y(2))*0.5)+(y(1)*0.25)+(y(2)*0.75))).^(1/4)))-273; endend plot (T,Y);
7269 is the number of y values that ode45 uses i keep getting the error code
Undefined function 'y' for input arguments of type 'double'.Error in daisyworldode45 (line 23) Te(T,Y)=((917*(T/500+0.4)/(5.67*10^(-8))*(1-(((1-y(1)-y(2))*0.5)+(y(1)*0.25)+(y(2)*0.75))).^(1/4)))-273;
Best Answer