I'm currently going back through old MATLAB university assignments. It's been a while since I used MATLAB, and I'm having trouble figuring out the error with this script that presumably ran OK when I wrote it and submitted it ~4 years ago-- my submission has the correct plots below the code from the output. Maybe MATLAB syntax has changed slightly?
The assignment was running SIR (infectious disease) simulations using the ODE solver. Here's the code below:
%%FUNCTION:
function rhs = SIR_rhs_seasonal(t,u,p,D,G)
%Right-hand side of SIR model
%Assumes 52 weeks in a year
B=((15*(1/7))/3000000)*(1+p*cos(2*pi*t/365));
S = u(1);
E = u(2);
I = u(3);
R = u(4);
rhs = [ -B*S*I; (B*S*I)-(D*E); (D*E)-(G*I); G*I ];
%%ODE SOLVER:
%% parameters
tend = 700;
D=1/7;
G=1/7;
p=.1;
N=3000000
%% initial condition
u = [ N*.99; N*0; N*.01; N*0 ];
%% solve ODE
[T,U] = ode45(@(t,u) SIR_rhs_seasonal(t,u,p,D,G),[0:0.1:tend],u);
%% plot results
figure(1);
plot(T,U(:,1),'b',T,U(:,2),'r',T,U(:,3),'k',T,U(:,4),'g');
axis([0 10 0 3000000]);
xlabel('time = weeks');
ylabel('population');
title('susceptibles (blue), latent (red), infectious (black), recovered/removed (green)');
figure(2);
plot(T,U(:,2)./(U(:,2)+U(:,3)),'b')
axis([0 tend -.25 1]);
xlabel('time = days');
ylabel('E(t)/(E(t)+I(t))');
title('Latent proportion of infectives');
The error currently get is:
SIRmodel2 Not enough input arguments.
Error in SIRmodel2 (line 6) B=((15*(1/7))/3000000)*(1+p*cos(2*pi*t/365));
Any insight is appreciated!
pcos(2*pi*t/365))and notp*cos(2*pi*t/365))? Is this right? - qbzenkercossomehow? - tmpearce*needed escaping as\*) - nekomatic