Matlab functions of functions
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Adin
le 21 Avr 2014
Commenté : Walter Roberson
le 22 Avr 2014
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 commentaires
Réponse acceptée
Walter Roberson
le 21 Avr 2014
That is not Gamma, that is Incomplete Gamma. See http://www.mathworks.com/help/matlab/ref/gammainc.html
2 commentaires
Walter Roberson
le 22 Avr 2014
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))
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Numerical Integration and Differential Equations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!