How I can check the system solution with a Matlab ODE function.

1 vue (au cours des 30 derniers jours)
Camilo Sánchez
Camilo Sánchez le 10 Juin 2018
Commenté : Camilo Sánchez le 11 Juin 2018
dydt(1) = 1.3*(y(3) - y(1)) + 10400*exp(20.7 - 1500/y(1))*y(2);
dydt(2) = 1880 * (y(4) - y(2) * (1+exp(20.7 - 1500/y(1))));
dydt(3) = 1752 - 269*y(3) + 267*y(1);
dydt(4) = 0.1 + 320*y(2) - 321*y(4)
y(t0)= [50,0,600,1]

Réponse acceptée

Jan
Jan le 11 Juin 2018
function main
t0 = 0;
y0= [50,0,600,1]
[t,y] = ode45(@fcn, [t0, 7], y0);
plot(t, y);
end
function dydt = fcn(t, y)
dydt = zeros(4,1);
dydt(1) = 1.3*(y(3) - y(1)) + 10400*exp(20.7 - 1500/y(1))*y(2);
dydt(2) = 1880 * (y(4) - y(2) * (1+exp(20.7 - 1500/y(1))));
dydt(3) = 1752 - 269*y(3) + 267*y(1);
dydt(4) = 0.1 + 320*y(2) - 321*y(4);
end
  3 commentaires
Jan
Jan le 11 Juin 2018
I guessed the endpoint 7. This takes a long time, in fact. If you use 2, ODE45 can solve this in seconds. ODE45 is designed to integrate non-stiff ODEs. If your system is stiff, use e.g. ode23s.
tic
[t,y] = ode23s(@fcn, [t0, 7], y0);
toc
% Elapsed time is 0.045184 seconds.
Camilo Sánchez
Camilo Sánchez le 11 Juin 2018
Thank for your answer. I already assumed it was something like that and I used ODE15S. Thanks for your support.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by