How to get plot from code using the two given differential equations and initial conditions and time?
2 次查看(过去 30 天)
显示 更早的评论
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);
0 个评论
采纳的回答
Walter Roberson
2015-11-13
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
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Function Creation 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!