Im trying to create an SEIR Model for a covid simulation and keep getting the following error messages. The error seems to come in when I make beta dependent on R (that is it everything functions properly with no errors when I make beta a constant), which turns it into a 1 by 365 matrix. I thought that when this happens, I need to change the code in my ode equation to include a " .* " after the matrix beta to do it sort of piece wise, but I keep getting these errors. Any help would be appreciated.
Here is the code:
%To find Ri value from data, which is assumed to fit an exponential model
day35=1:1:35;Italy35=[3 3 3 17 79 132 229 322 400 650 888 1128 1689 2036 2502 3089 3858 4636 5883 7375 9172 10149 12462 15113 17660 21157 23980 27980 31506 35713 41035 47021 53578 59138 63927];%Using cftool and creating an exponential fit gives a growth rate in the data of
r=0.1387;%Parameters
t=linspace(0,365,365); %set to give days after initial infection
sigma=1/3; %exposure rate
gamma=1/10; %recovery rate
alpha=1/20; %death rate
Ri=[[(r^2)+r*(sigma+gamma)]/(sigma*gamma)]+1 ; %Initial basic reproduction number, as determined above
Rf=2.3; %Estimated final basic reproduction number
L=75; %Day of extreme quarantine measures
w=0.5; %Determines quarantine rate
R=((Ri-Rf)./[1+exp(-w*(-t+L))])+Rf; %Changing basic reproduction number
%birth and death rates, respectively:
mu=0.005;nu=0.002;%Total population-S, E, I, R sum to this:
N=50000;beta=R*gamma; %Infectious rate
%Initial Conditions
Eo=5;Io=1;Ro=0;Do=0;%ODE Equation Solver
f = @(t,x) [mu*N-nu*x(1)-beta.*(x(1)*x(3)/N);beta.*(x(1)*x(3)/N)-(nu+sigma)*x(2);sigma*x(2)-(gamma+alpha)*x(3);gamma*x(3);alpha*x(3)];%The @(t,x) term is just the function handle. Here I have created a function with four pieces, each representing the right sides of the SEIR equations.
%In place, I have x(1)=S, x(2)=E, x(3)=I, x(4)=R, and x(5)=D
[t,xa]=ode45(f,[0 365], [N Eo Io Ro Do]);%ode45 takes each term in the function f and integrates the function from 0 to 365. [N Eo Io Ro Do] represents the inital conditions for SEIRD respectively
a1=plot(t,xa(:,1),'b'); M1='S';hold on%Hold allows for the addition of more plots without deleting the first
a2=plot(t,xa(:,2),'k'); M2='E';a3=plot(t,xa(:,3),'r'); M3='I';a4=plot(t,xa(:,4),'g'); M4='R';a5=plot(t,xa(:,5),'y'); M5='D';hold offlegend([a1, a2 a3 a4 a5], M1, M2, M3, M4, M5)
And here is the error message:
Best Answer