필터 지우기
필터 지우기

error of plot vectors not the same size

조회 수: 1 (최근 30일)
Kirsty James
Kirsty James 2013년 3월 4일
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
Jan
Jan 2013년 3월 4일
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.

댓글을 달려면 로그인하십시오.

답변 (1개)

Jan
Jan 2013년 3월 4일
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
Kirsty James
Kirsty James 2013년 3월 4일
sorry i mean to plot the ground cover Y, against L the luminosity so when i enter plot ( Y, L) that is the error code i get. I am unsure how to make these two inputs the same size.
Jan
Jan 2013년 3월 4일
편집: Jan 2013년 3월 4일
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.

댓글을 달려면 로그인하십시오.

카테고리

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