Matlab functions of functions
1 次查看(过去 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!