Can't figure out why my ODE solver is producing a straight line
1 view (last 30 days)
Show older comments
Christopher Arreola
on 11 May 2022
Answered: Star Strider
on 11 May 2022
Here's my code, can't figure out why it's only giving my a straight line, this is supposed to be a system of 3 nonlinear ODE's and produce a periodic graph for all three ODE's
function ODE
f=@(t,x)[x(1).*(0.9842-0.9844.*x(1)-x(3)-0.0004.*x(2));(1+x(2)).*(0.0156.*x(1)-0.0004.*x(2));0.0002.*x(2)-0.0002.*x(3)+x(3).*(0.0156.*x(1)-0.0004.*x(2))];
[t,xa]=ode45(f,[0 50],[0 0 0]);
plot(t,xa(:,1),'r')
hold on
plot(t,xa(:,2),'b')
plot(t,xa(:,3),'g')
hold off
0 Comments
Accepted Answer
Star Strider
on 11 May 2022
It plots a straight line because all the initial conditions arre zero.
Add eps (or some small, non-zero value) to them, and it works —
f=@(t,x)[x(1).*(0.9842-0.9844.*x(1)-x(3)-0.0004.*x(2));(1+x(2)).*(0.0156.*x(1)-0.0004.*x(2));0.0002.*x(2)-0.0002.*x(3)+x(3).*(0.0156.*x(1)-0.0004.*x(2))];
[t,xa]=ode45(f,[0 50],[0 0 0]+eps);
plot(t,xa(:,1),'r')
hold on
plot(t,xa(:,2),'b')
plot(t,xa(:,3),'g')
hold off
legend('x_1','x_2','x_3', 'Location','best')
set(gca, 'YScale','log') % Optional
.
0 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!