error of plot vectors not the same size
1 view (last 30 days)
Show older comments
Hi I am having some trouble with some coding i have written, i have no problems getting graphs when plotting T against Y, but i cannot seem to get plots of T against L working. Here are my codes
This file defines my daisyworld1 function 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, local temperature function
g=0.2; %x-value
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
And this file solves it using ode45 clear; % Remove stored variables daisyworldode45
Lt=linspace(0,5000,25); %generate t for L
L=Lt/2500+0; %luminosity function want to keep within a range of 0 and 2 so change depending on tspan
tspan=[0 200]; %solve for values of t
IC = [0.1 0.8]; %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
plot(T,L) % Plots the daisy area coverage against time
% Blue line is white daisies
% Green line is black daisies
I keep getting the error Error using plot Vectors must be the same lengths.
Error in daisyworldode45 (line 13) plot(T,L) % Plots the daisy area coverage against time
I have tried to make them the same size as each other but i still get the same error, any help would be great Thank you
1 Comment
Jan
on 4 Mar 2013
Have you seen the nicely formatted questions posted by others? You can do this also to improve the readability of your question: Add one line before and after the code, mark the code and press the "{} Code" key.
Answers (1)
Jan
on 4 Mar 2013
I do not see any code, which is useful for making T and L the same size. Currently L has 25 elements, and the number of elements of T depends on the stepsize chosen by the integrator.
The general method is either to define the wanted output-points by using a vector as tspan, or by a linear (or other) interpolation or the results. But currently it is not clear, how L and T are related: L goes from 0 to 2, tspan from 0 to 200. Therefore I cannot suggest an explicit solution.
2 Comments
Jan
on 4 Mar 2013
Edited: Jan
on 4 Mar 2013
Yes, but as long as you do not explain the relation between these two vectors, we cannot guess, what you need. Perhaps the shorter vector must be padded with zeros, or the longer must be cut to the length of the shorter one, or one needs a linear or other interpolation. There are many different ways and it is your turn to find out, what you want.
The meaning of the values does not really matter here: "ground cover" or "average income" use exactly the same plot command.
See Also
Categories
Find more on Language Fundamentals in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!