Matlab functions of functions
2 ビュー (過去 30 日間)
古いコメントを表示
So I am writing a function to compute the following equations for an SIR model:
So here's my code:
function xdot = sir(t, params)
global h r q;
xdot = zeros(3,1);
SH = params(1);
IH = params(2);
RH = params(3);
xdot(1) = -h*SH + r*IH + gamma(h,t)*RH; % dSh
xdot(2) = h*SH - r*IH - q*IH; %dIh
xdot(3) = q*IH - gamma(h,t)*RH; %dRh
end
And then I would call this function like so:
global h r q;
h = 1;
r = 2;
q = 3;
params(1) = 1;
params(2) = 2;
params(3) = 3;
[t x] = ode45('sir',[0:0.01:30],params);
But I just don't understand how to write the gamma function component inside of sir.m. What I mean is the gamma(h,tau) portion that is a part of the original equation. How exactly would I write this inside the function file sir.m?
0 件のコメント
採用された回答
Walter Roberson
2014 年 4 月 21 日
That is not Gamma, that is Incomplete Gamma. See http://www.mathworks.com/help/matlab/ref/gammainc.html
2 件のコメント
Walter Roberson
2014 年 4 月 22 日
If I read your code correctly, where you have
gamma(h,t)
substitute
gammainc(t, h)
I notice you initialize your h to 1. When you follow through the defining formula for incomplete gamma, the t^(a-1) part will become t^0 so that term will vanish, leaving you with an integral from 0 to x of exp(-t) . The integral of exp(-t) is -exp(-t) so for that case gammainc(t,1) is (1 - exp(-t))
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Ordinary Differential Equations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!