I dont understand the vectors and element parts.
1 view (last 30 days)
Show older comments
Nur Athirah Salleh
on 20 Dec 2018
Edited: James Tursa
on 20 Dec 2018
this is the code ( want to plot graph of nonlinear ode)
syms S E I R N a b c d e g h j;
a=0.01;b=0.25;c=0.1;d=0.2;e=0.2;N=520;j=0.167;g=0.8;h=0.02;
f=@(t,y)[((b*N)-(g*y(1))-(j*y(1))-((a*y(1)*y(3))/N)-d*y(1));(j*y*(1)+((a*y(1)*y(3))/N)-(c*y(2))-(d*y(2)));((c*y(2))-(d*y(3))-(h*y(3))-(e*y(3)));((g*y(1))+(e*y(3))-(d*y(4)))];
tspan=[0,100];
xinit=[300 100 75 45];
figure(1)
xlabel('time(years)')
ylabel('population')
ode45(f,tspan,xinit)
legend('S','E','I','R')
this is the error
Error using odearguments (line 95)
@(T,Y)[((B*N)-(G*Y(1))-(J*Y(1))-((A*Y(1)*Y(3))/N)-D*Y(1));(J*Y*(1)+((A*Y(1)*Y(3))/N)-(C*Y(2))-(D*Y(2)));((C*Y(2))-(D*Y(3))-(H*Y(3))-(E*Y(3)));((G*Y(1))+(E*Y(3))-(D*Y(4)))] returns a
vector of length 7, but the length of initial conditions vector is 4. The vector returned by
@(T,Y)[((B*N)-(G*Y(1))-(J*Y(1))-((A*Y(1)*Y(3))/N)-D*Y(1));(J*Y*(1)+((A*Y(1)*Y(3))/N)-(C*Y(2))-(D*Y(2)));((C*Y(2))-(D*Y(3))-(H*Y(3))-(E*Y(3)));((G*Y(1))+(E*Y(3))-(D*Y(4)))] and the
initial conditions vector must have the same number of elements.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in ttvmd (line 9)
ode45(f,tspan,xinit)
Please help me.......
0 Comments
Accepted Answer
James Tursa
on 20 Dec 2018
Edited: James Tursa
on 20 Dec 2018
Typo. This
j*y*(1) <-- Uses the full vector y times the scalar 1
should be this
j*y(1) <-- Uses only the y(1) element
0 Comments
More Answers (0)
See Also
Categories
Find more on Ordinary Differential Equations 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!