ode45 returns NaN for a system of differential equations?

1 visualización (últimos 30 días)
Evan
Evan el 22 de Feb. de 2014
Editada: Mischa Kim el 22 de Feb. de 2014
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.

Respuesta aceptada

Mischa Kim
Mischa Kim el 22 de Feb. de 2014
Editada: Mischa Kim el 22 de Feb. de 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
  1 comentario
Evan
Evan el 22 de Feb. de 2014
Thank you very much. That change hadn't even occurred to me.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Ordinary Differential Equations en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by