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?
Best Answer