Can't figure out why my ODE solver is producing a straight line

7 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Star Strider
Star Strider il 11 Mag 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
.

Più risposte (0)

Categorie

Scopri di più su Programming in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by