How to get plot from code using the two given differential equations and initial conditions and time?

1 view (last 30 days)
Function below
function yprime = meen668_project5_3(t,tm,y)
yprime(1,1)=15-((3*(y(1))*t)/800); %%Equation 1, Example 2 1000 gallon holding tank from Paul's Online Math Notes
yprime(2,1)=(2*(y(2))*t)/(400-(t-tm)); %Equation 2, Example 2 1000 gallon holding tank from Paul's Online Math Notes
Script below
y0(1,1)=2; y0(2,1)=500;
%Numerical solution
tspan1=[0,35.475];
tspan2=[35.475,435.4758];
[t,tm,y]=ode45('meen668_project5_3',tspan1,tspan2,y0);
%Analytical solution
%Plot
figure(1)
Y1=y(:,1);
Y2=y(:,2);
plot(t,Y1,'b-',t,Y2,'g*')
title('Example 2 1000 gallon holding tank from Paul''s Online Math Notes')
xlabel('Time')
ylabel('Pollution')
legend('Numerical')
Error below
Attempted to access y(1); index out of bounds because numel(y)=0.
Error in meen668_project5_3 (line 3) yprime(1,1)=15-((3*(y(1))*t)/800); %%Equation 1, Example 2 1000 gallon holding tank from Paul's Online Math Notes
Error in odearguments (line 87) f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 113) [neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...
Error in figure1_meen668_proj5_3 (line 7) [t,tm,y]=ode45('meen668_project5_3',tspan1,tspan2,y0);

Accepted Answer

Walter Roberson
Walter Roberson on 13 Nov 2015
Strangely, you and Stephen have identical code and identical posting style. Rather than answer both of you individually, please see his posting http://uk.mathworks.com/matlabcentral/answers/254562-error-in-code-trying-to-get-plot

More Answers (0)

Categories

Find more on Function Creation in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!