Effacer les filtres
Effacer les filtres

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

7 vues (au cours des 30 derniers jours)
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

Réponse acceptée

Star Strider
Star Strider le 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
.

Plus de réponses (0)

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by