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!