Matlab functions of functions

2 visualizaciones (últimos 30 días)
Adin
Adin el 21 de Abr. de 2014
Comentada: Walter Roberson el 22 de Abr. de 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?

Respuesta aceptada

Walter Roberson
Walter Roberson el 21 de Abr. de 2014
That is not Gamma, that is Incomplete Gamma. See http://www.mathworks.com/help/matlab/ref/gammainc.html
  2 comentarios
Adin
Adin el 21 de Abr. de 2014
So what exactly does using gammainc do? Sorry I'm new to matlab so I don't really know too much yet.
Walter Roberson
Walter Roberson el 22 de Abr. de 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))

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Ordinary Differential Equations en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by