ode45 returns NaN for a system of differential equations?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am attempting to generate two vectors, tv and Yv, to plot a series of differential equations. Given my funciton:
function dydt=Tcells(t,y)
dydt(1,1)=(10 + 0.03*y(1)*(1-y(1)/t) - 0.02*y(1) - (2.4e-5)*y(4)*y(1));
dydt(2,1)=(2.4e-5)*y(4)*y(1) - 0.02*y(2) - (3e-3)*y(2);
dydt(3,1)=(3e-3)*y(2) - 0.24*y(3);
dydt(4,1)=1400*y(3) - 2.4e-5*y(4)*y(1) - 2.4*y(4);
and the following ode45 script entry:
[tv, Yv]=ode45('Tcells',[0 1500],[500, 0, 0, 1000]);
I cannot figure out why all entries of Yv, save the first row, return NaN as their values.
Any and all help is appreciated.
0 commentaires
Réponse acceptée
Mischa Kim
le 22 Fév 2014
Modifié(e) : Mischa Kim
le 22 Fév 2014
Evan, the issue is the term
(1-y(1)/t)
at t=0. If you set t0 for the integration time span slightly differently, such as
[tv, Yv] = ode45('Tcells',[0.1 1500],[500, 0, 0, 1000]); % 0.1 instead of 0.0
you should get it to work. Also, to improve readability and performance (especially for more complex, non-linear ODEs):
function dydt = Tcells(t,y)
y1 = y(1);
y2 = y(2);
y3 = y(3);
y4 = y(4);
dydt = [10 + 0.03*y1*(1-y1/t) - 0.02*y1 - (2.4e-5)*y4*y1; ...
(2.4e-5)*y4*y1 - 0.02*y2 - (3e-3)*y2; ...
(3e-3)*y2 - 0.24*y3; ...
1400*y3 - 2.4e-5*y4*y1 - 2.4*y4];
end
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Ordinary Differential Equations 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!