ode45 returns NaN for a system of differential equations?

3 次查看(过去 30 天)
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.

采纳的回答

Mischa Kim
Mischa Kim 2014-2-22
编辑:Mischa Kim 2014-2-22
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by