Filter löschen
Filter löschen

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

7 Ansichten (letzte 30 Tage)
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

Akzeptierte Antwort

Star Strider
Star Strider am 11 Mai 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
.

Weitere Antworten (0)

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by