ode45 returns NaN for a system of differential equations?

2 ビュー (過去 30 日間)
Evan
Evan 2014 年 2 月 22 日
編集済み: Mischa Kim 2014 年 2 月 22 日
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
  1 件のコメント
Evan
Evan 2014 年 2 月 22 日
Thank you very much. That change hadn't even occurred to me.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by