Answer To: Macm 316 Computing Assignment #6 Submit on Crowdmark by Wednesday, August 5, 2020, 11pm Upload one...
Kshitij answered on Aug 06 2021
renewode/Question2Solution.m
% At first, use constant R0 and run your code with different values of R0: 3.5, 2.5, 1.25, 0.9. For
% the constant R0 case summarize your observations, but only report the results corresponding
% to R0 = 3.5. R0 = 3.5 is your Scenario 1.
% Test the function
% Run your codes with N=5 Million people
% (BC scenario), and ? = 1/5.2 and
% gamma=1/10.
N=5e6;
a=1/5.2;
gamma=1/10;
R0=[3.5, 2.5, 1.25, 0.9];
for ii=1:length(R0)
b=gamma*R0(ii);
I0=40;
E0=20*I0;
S0=N-I0-E0-R0(ii);
% The simulation of question 1:
yinit=[S0,E0,I0,R0(ii)]' % Initial Conditions
rtol =1.e-6; atol=1.e-5;
options=odeset('AbsTol', atol,'RelTol',rtol,'MaxOrder',5);
[t,y] =ode45(@(t,y)seir(t,y,a,b,gamma,N),[0,180],yinit,options)
figure(),
subplot(4,1,1),plot(t,y(:,1),'b','linewidth',2); grid on
xlabel('Time'); ylabel('S(t)');
str=['The initial condtion of R0=', num2str(R0(ii))];
title(str)
subplot(4,1,2),plot(t,y(:,2),'b','linewidth',2); grid on
xlabel('Time'); ylabel('E(t)');
subplot(4,1,3),plot(t,y(:,3),'b','linewidth',2); grid on
xlabel('Time'); ylabel('I(t)');
subplot(4,1,4),plot(t,y(:,4),'b','linewidth',2); grid on
xlabel('Time'); ylabel('R(t)');
end
renewode/Question4Solution.m
% Your Scenarios 2, 3, and 4: Run your code with the time dependent R0 values given in the
% table above. You may simply use the values as a piecewise constant function, or interpolate
% the values using Matlab’s interp1 function. The first row corresponds to a scenario with
% some lock-down measures; the second row shows an effective response; the third row shows
% the consequences of allowing a lapse in prevention measures. You may want to plot your R0
% values agains time.
%Scenario 4
clear all
N=5e6;
a=1/5.2;
gamma=1/10;
T=[0 21 71 85 91 200];
R0=[3.5,2.6,1.9,1,0.55,0.55];
for i=1:5
b=gamma*R0(i);
I0=40;
E0=20*I0;
S0=N-I0-E0-R0(i);
% The simulation of question 1:
yinit=[S0,E0,I0,R0(i)]' ;% Initial Conditions
rtol =1.e-6; atol=1.e-5;
options=odeset('AbsTol', atol,'RelTol',rtol,'MaxOrder',5);
[t,y] =ode45(@(t,y)seir(t,y,a,b,gamma,N),[T(i),T(i+1)],yinit,options);
figure(i)
subplot(4,1,1),plot(t,y(:,1),'b','linewidth',2); grid on
xlabel('Time'); ylabel('S(t)');
str=['The initial condtion of R0=', num2str(R0(i))];
title(str)
hold off
hold on
subplot(4,1,2),plot(t,y(:,2),'b','linewidth',2); grid on
xlabel('Time'); ylabel('E(t)');
hold off
hold on
subplot(4,1,3),plot(t,y(:,3),'b','linewidth',2); grid on
xlabel('Time'); ylabel('I(t)');
hold off
subplot(4,1,4),plot(t,y(:,4),'b','linewidth',2); grid on
xlabel('Time'); ylabel('R(t)');
hold off
end
%% Scenario 3
N=5e6;
a=1/5.2;
gamma=1/10;
T=[0 21 71 85 91 200];
R0=[3,2.2,0.7,0.8,1,0.9];
for i=1:5
b=gamma*R0(i);
I0=40;
E0=20*I0;
S0=N-I0-E0-R0(i);
% The simulation of question 1:
yinit=[S0,E0,I0,R0(i)]' ;% Initial Conditions
rtol =1.e-6; atol=1.e-5;
options=odeset('AbsTol', atol,'RelTol',rtol,'MaxOrder',5);
[t,y] =ode45(@(t,y)seir(t,y,a,b,gamma,N),[T(i),T(i+1)],yinit,options);
figure(i)
subplot(4,1,1),plot(t,y(:,1),'b','linewidth',2); grid on
xlabel('Time'); ylabel('S(t)');
str=['The initial condtion of R0=', num2str(R0(i))];
title(str)
hold off
hold on
subplot(4,1,2),plot(t,y(:,2),'b','linewidth',2); grid on
xlabel('Time'); ylabel('E(t)');
hold off
hold on
subplot(4,1,3),plot(t,y(:,3),'b','linewidth',2); grid on
xlabel('Time'); ylabel('I(t)');
hold off
subplot(4,1,4),plot(t,y(:,4),'b','linewidth',2); grid on
xlabel('Time'); ylabel('R(t)');
hold off
end
%% Scenario 4
N=5e6;
a=1/5.2;
gamma=1/10;
T=[0 21 71 85 91 200];
R0=[3,2.2,0.9,2.5,3.2,0.85];
for i=1:5
b=gamma*R0(i);
I0=40;
E0=20*I0;
S0=N-I0-E0-R0(i);
% The simulation of question 1:
yinit=[S0,E0,I0,R0(i)]' ;% Initial Conditions
rtol =1.e-6; atol=1.e-5;
options=odeset('AbsTol', atol,'RelTol',rtol,'MaxOrder',5);
[t,y] =ode45(@(t,y)seir(t,y,a,b,gamma,N),[T(i),T(i+1)],yinit,options);
figure(i)
subplot(4,1,1),plot(t,y(:,1),'b','linewidth',2); grid on
xlabel('Time'); ylabel('S(t)');
str=['The initial condtion of R0=', num2str(R0(i))];
title(str)
hold off
hold on
subplot(4,1,2),plot(t,y(:,2),'b','linewidth',2); grid on
xlabel('Time'); ylabel('E(t)');
hold off
hold on
subplot(4,1,3),plot(t,y(:,3),'b','linewidth',2); grid on
xlabel('Time'); ylabel('I(t)');
hold off
subplot(4,1,4),plot(t,y(:,4),'b','linewidth',2); grid on
xlabel('Time'); ylabel('R(t)');
hold off
end
renewode/question_5.asv
N=5e6;
a=1/5.2;
gamma=1/10;
T=[0 21 71 85 91 200];
R0=[3.5,2.6,1.9,1,0.55,0.55];
for i=1:5
b=gamma*R0(i);
I0=40;
E0=20*I0;
S0=N-I0-E0-R0(i);
% The simulation of question 1:
yinit=[S0,E0,I0,R0(i)]' ;% Initial Conditions
rtol =1.e-6; atol=1.e-5;
options=odeset('AbsTol', atol,'RelTol',rtol,'MaxOrder',5);
[t,y] =ode45(@(t,y)seir(t,y,a,b,gamma,N),[T(i),T(i+1)],yinit,options);
end
% Death amaong R(t) is 4%
Total_rt1=max(y(:,4));
death1=.04*Total_rt1;
death_per_mil2=death/5;
%%
N=5e6;
a=1/5.2;
gamma=1/10;
T=[0 21 71 85 91 200];
R0=[3,2.2,0.7,0.8,1,0.9];
for i=1:5
b=gamma*R0(i);
I0=40;
E0=20*I0;
S0=N-I0-E0-R0(i);
% The simulation of question 1:
yinit=[S0,E0,I0,R0(i)]' ;% Initial Conditions
rtol =1.e-6; atol=1.e-5;
options=odeset('AbsTol', atol,'RelTol',rtol,'MaxOrder',5);
[t,y] =ode45(@(t,y)seir(t,y,a,b,gamma,N),[T(i),T(i+1)],yinit,options);
end
% Death amaong R(t) is 4%
Total_rt2=max(y(:,4));
death2=.04*Total_rt2;
death_per_mil3=death/5;
%%
N=5e6;
a=1/5.2;
gamma=1/10;
T=[0 21 71 85 91 200];
R0=[3,2.2,0.9,2.5,3.2,0.85];
for i=1:5
b=gamma*R0(i);
I0=40;
E0=20*I0;
S0=N-I0-E0-R0(i);
% The simulation of question 1:
yinit=[S0,E0,I0,R0(i)]' ;% Initial Conditions
rtol =1.e-6; atol=1.e-5;
options=odeset('AbsTol', atol,'RelTol',rtol,'MaxOrder',5);
[t,y] =ode45(@(t,y)seir(t,y,a,b,gamma,N),[T(i),T(i+1)],yinit,options);
end
% Death amaong R(t) is 4%
Total_rt3=max(y(:,4));
death=.04*Total_rt3;
death_per_mil4=death/5;
%%
renewode/question_5.m
N=5e6;
a=1/5.2;
gamma=1/10;
T=[0 21 71 85 91 200];
R0=[3.5,2.6,1.9,1,0.55,0.55];
for i=1:5
b=gamma*R0(i);
I0=40;
E0=20*I0;
S0=N-I0-E0-R0(i);
% The simulation of question 1:
yinit=[S0,E0,I0,R0(i)]' ;% Initial Conditions
rtol =1.e-6; atol=1.e-5;
options=odeset('AbsTol', atol,'RelTol',rtol,'MaxOrder',5);
[t,y] =ode45(@(t,y)seir(t,y,a,b,gamma,N),[T(i),T(i+1)],yinit,options);
end
% Death amaong R(t) is 4%
Total_rt1=max(y(:,4));
death1=.04*Total_rt1;
death_per_mil2=death1/5;
Death_scenerio2=death_per_mil2;
%%
N=5e6;
a=1/5.2;
gamma=1/10;
T=[0 21 71 85 91 200];
R0=[3,2.2,0.7,0.8,1,0.9];
for i=1:5
b=gamma*R0(i);
I0=40;
E0=20*I0;
S0=N-I0-E0-R0(i);
% The simulation of question 1:
yinit=[S0,E0,I0,R0(i)]' ;% Initial Conditions
rtol =1.e-6; atol=1.e-5;
options=odeset('AbsTol', atol,'RelTol',rtol,'MaxOrder',5);
[t,y] =ode45(@(t,y)seir(t,y,a,b,gamma,N),[T(i),T(i+1)],yinit,options);
end
% Death amaong R(t) is 4%
Total_rt2=max(y(:,4));
death2=.04*Total_rt2;
death_per_mil3=death2/5;
Death_scenerio3=death_per_mil3;
%%
N=5e6;
a=1/5.2;
gamma=1/10;
T=[0 21 71 85 91 200];
R0=[3,2.2,0.9,2.5,3.2,0.85];
for i=1:5
b=gamma*R0(i);
I0=40;
E0=20*I0;
S0=N-I0-E0-R0(i);
% The simulation of question 1:
yinit=[S0,E0,I0,R0(i)]' ;% Initial Conditions
rtol =1.e-6; atol=1.e-5;
options=odeset('AbsTol', atol,'RelTol',rtol,'MaxOrder',5);
[t,y] =ode45(@(t,y)seir(t,y,a,b,gamma,N),[T(i),T(i+1)],yinit,options);
end
% Death amaong R(t) is 4%
Total_rt3=max(y(:,4));
death3=.04*Total_rt3;
death_per_mil4=death3/5;
Death_scenerio4=death_per_mil4;
%%
T = table(Death_scenerio2,Death_scenerio3,Death_scenerio4)
renewode/seir.m
function yprime=seir(t,y,a,b,gamma,N)
yprime=zeros(4,1);
% The following are the differential equations
yprime(1)=-b*y(1)*y(3)/N;
yprime(2)=b*y(1)*y(3)/N-a*y(2);
yprime(3)=a*y(2)-gamma*y(3);
yprime(4)=gamma*y(3);
end
renewode/sixth.m
N=5e6;
a=1/5.2;
gamma=1/10;
T=[0 21 71 85 91 200];
R0=[3.5,2.6,1.9,1,0.55,0.55];
for i=1:5
b=gamma*R0(i);
I0=40;
E0=20*I0;
S0=N-I0-E0-R0(i);
% The simulation of question 1:
yinit=[S0,E0,I0,R0(i)]' ;% Initial Conditions
rtol =1.e-6; atol=1.e-5;
options=odeset('AbsTol', atol,'RelTol',rtol,'MaxOrder',5);
[t,y] =ode45(@(t,y)seir(t,y,a,b,gamma,N),[T(i),T(i+1)],yinit,options);
total_infection2= y(:,3)+y(:,4);
total2{i}=total_infection2;
total_time2{i}=t;
end
%%
Total_time2 = cat(1, total_time2{:})
Total_active_case2 = cat(1, total2{:})
figure;
plot(Total_time2,Total_active_case2)
grid on
xlabel('Time in days'); ylabel('Total active cases');
title('scenerio 2')
%%
N=5e6;
a=1/5.2;
gamma=1/10;
T=[0 21 71 85 91 200];
R0=[3,2.2,0.7,0.8,1,0.9];
total=[];
for i=1:5
b=gamma*R0(i);
I0=40;
E0=20*I0;
S0=N-I0-E0-R0(i);
% The simulation of question 1:
yinit=[S0,E0,I0,R0(i)]' ;% Initial Conditions
rtol =1.e-6; atol=1.e-5;
options=odeset('AbsTol', atol,'RelTol',rtol,'MaxOrder',5);
[t,y] =ode45(@(t,y)seir(t,y,a,b,gamma,N),[T(i),T(i+1)],yinit,options);
total_infection= y(:,3)+y(:,4);
total{i}=total_infection;
total_time{i}=t;
end
%%
Total_time = cat(1, total_time{:})
Total_active_case = cat(1, total{:})
figure;
plot(Total_time,Total_active_case)
grid on
xlabel('Time in days'); ylabel('Total active cases');
title('scenerio 3')
%%
N=5e6;
a=1/5.2;
gamma=1/10;
T=[0 21 71 85 91 200];
R0=[3,2.2,0.9,2.5,3.2,0.85];
for i=1:5
b=gamma*R0(i);
I0=40;
E0=20*I0;
S0=N-I0-E0-R0(i);
% The simulation of question 1:
yinit=[S0,E0,I0,R0(i)]' ;% Initial Conditions
rtol =1.e-6; atol=1.e-5;
options=odeset('AbsTol', atol,'RelTol',rtol,'MaxOrder',5);
[t,y] =ode45(@(t,y)seir(t,y,a,b,gamma,N),[T(i),T(i+1)],yinit,options);
total_infection1= y(:,3)+y(:,4);
total1{i}=total_infection1;
total_time1{i}=t;
end
%%
Total_time1 = cat(1, total_time1{:})
Total_active_case1 = cat(1, total1{:})
figure;
plot(Total_time1,Total_active_case1)
grid on
xlabel('Time in days'); ylabel('Total active cases');
title('scenerio 4')
renewode/TestQ1.m
% Test the function
% Run your codes with N=5 Million people
% (BC scenario), and ? = 1/5.2 and
% gamma=1/10.
N=5e6;
a=1/5.2;
gamma=1/10;
R0=0; % We chose R0=0 at first
b=gamma*R0;
I0=40;
E0=20*I0;
S0=N-I0-E0-R0;
% The simulation of question 1:
yinit=[S0,E0,I0,R0]' % Initial Conditions
rtol =1.e-6; atol=1.e-5;
options=odeset('AbsTol', atol,'RelTol',rtol,'MaxOrder',5);
[t,y] =ode45(@(t,y)seir(t,y,a,b,gamma,N),[0,180],yinit,options)
figure(),
subplot(4,1,1),plot(t,y(:,1),'b','linewidth',2); grid on
xlabel('Time'); ylabel('S(t)');
subplot(4,1,2),plot(t,y(:,2),'b','linewidth',2); grid on
xlabel('Time'); ylabel('E(t)');
subplot(4,1,3),plot(t,y(:,3),'b','linewidth',2); grid on
xlabel('Time'); ylabel('I(t)');
subplot(4,1,4),plot(t,y(:,4),'b','linewidth',2); grid on
xlabel('Time'); ylabel('R(t)');
renewode/Untitled.mlx
[Content_Types].xml
_rels/.rels
matlab/document.xml
% Test the function
% Run your codes with N=5 Million people
% (BC scenario), and ? = 1/5.2 and
% gamma=1/10.
N=5e6;
a=1/5.2;
gamma=1/10;
R0=0; % We chose R0=0 at first
b=gamma*R0;
I0=40;
E0=20*I0;
S0=N-I0-E0-R0;
% The simulation of question 1:
yinit=[S0,E0,I0,R0]' % Initial Conditions
rtol =1.e-6; atol=1.e-5;
options=odeset('AbsTol', atol,'RelTol',rtol,'MaxOrder',5);
[t,y] =ode45(@(t,y)seir(t,y,a,b,gamma,N),[0,180],yinit,options)
figure(),
subplot(4,1,1),plot(t,y(:,1),'b','linewidth',2); grid on
xlabel('Time'); ylabel('S(t)');
subplot(4,1,2),plot(t,y(:,2),'b','linewidth',2); grid on
xlabel('Time'); ylabel('E(t)');
subplot(4,1,3),plot(t,y(:,3),'b','linewidth',2); grid on
xlabel('Time'); ylabel('I(t)');
subplot(4,1,4),plot(t,y(:,4),'b','linewidth',2); grid on
xlabel('Time'); ylabel('R(t)'); % At first, use constant R0 and run your code with different values of R0: 3.5, 2.5, 1.25, 0.9. For
% the constant R0 case summarize your observations, but only report the results corresponding
% to R0 = 3.5. R0 = 3.5 is your Scenario 1.
% Test the function
% Run your codes with N=5 Million people
% (BC scenario), and ? = 1/5.2 and
% gamma=1/10.
N=5e6;
a=1/5.2;
gamma=1/10;
R0=[3.5, 2.5, 1.25, 0.9];
for ii=1:length(R0)
b=gamma*R0(ii);
I0=40;
E0=20*I0;
S0=N-I0-E0-R0(ii);
% The simulation of question 1:
yinit=[S0,E0,I0,R0(ii)]' % Initial Conditions
rtol =1.e-6; atol=1.e-5;
options=odeset('AbsTol', atol,'RelTol',rtol,'MaxOrder',5);
[t,y] =ode45(@(t,y)seir(t,y,a,b,gamma,N),[0,180],yinit,options)
figure(),
subplot(4,1,1),plot(t,y(:,1),'b','linewidth',2); grid on
xlabel('Time'); ylabel('S(t)');
str=['The initial condtion of R0=', num2str(R0(ii))];
title(str)
subplot(4,1,2),plot(t,y(:,2),'b','linewidth',2); grid on
xlabel('Time'); ylabel('E(t)');
subplot(4,1,3),plot(t,y(:,3),'b','linewidth',2); grid on
xlabel('Time'); ylabel('I(t)');
subplot(4,1,4),plot(t,y(:,4),'b','linewidth',2); grid on
xlabel('Time'); ylabel('R(t)');
end
% Your Scenarios 2, 3, and 4: Run your code with the time dependent R0 values given in the
% table above. You may simply use the values as a piecewise constant function, or interpolate
% the values using Matlab’s interp1 function. The first row corresponds to a scenario with
% some lock-down measures; the second row shows an effective response; the third row shows
% the consequences of allowing a lapse in prevention measures. You may want to plot your R0
% values agains time.
clear all
N=5e6;
a=1/5.2;
gamma=1/10;
T=[0 21 71 85 91 200];
R0=[3.5,2.6,1.9,1,0.55];
for i=1:5
b=gamma*R0(i);
I0=40;
E0=20*I0;
S0=N-I0-E0-R0(i);
% The simulation of question 1:
yinit=[S0,E0,I0,R0(i)]' % Initial Conditions
rtol =1.e-6; atol=1.e-5;
options=odeset('AbsTol', atol,'RelTol',rtol,'MaxOrder',5);
[t,y] =ode45(@(t,y)seir(t,y,a,b,gamma,N),[T(i),T(i+1)],yinit,options)
hold on
subplot(4,1,1),plot(t,y(:,1),'b','linewidth',2); grid on
xlabel('Time'); ylabel('S(t)');
str=['The initial condtion of R0=', num2str(R0(i))];
title(str)
hold off
hold on
subplot(4,1,2),plot(t,y(:,2),'b','linewidth',2); grid on
xlabel('Time'); ylabel('E(t)');
hold off
hold on
subplot(4,1,3),plot(t,y(:,3),'b','linewidth',2); grid on
xlabel('Time'); ylabel('I(t)');
hold off
subplot(4,1,4),plot(t,y(:,4),'b','linewidth',2); grid on
xlabel('Time'); ylabel('R(t)');
hold off
end function yprime=seir(t,y,a,b,gamma,N)
yprime=zeros(4,1);
% The following are the differential equations
yprime(1)=-b*y(1)*y(3)/N;
yprime(2)=b*y(1)*y(3)/N-a*y(2);
yprime(3)=a*y(2)-gamma*y(3);
yprime(4)=gamma*y(3);
end
matlab/output.xml
manual code ready 0.4 matrix yinit 4×1 4 1 double 4999160
800
40
0
double double [[{"value":"{\"value\":\"4999160\"}"},{"value":"{\"value\":\"800\"}"},{"value":"{\"value\":\"40\"}"},{"value":"{\"value\":\"0\"}"}]] 16 matrix t 285×1 285 1 double 0
0.0034
0.0067
0.0101
0.0135
0.0303
0.0472
0.0640
0.0808
0.1651
double double [[{"value":"{\"value\":\"0\"}"},{"value":"{\"value\":\"0.0034\"}"},{"value":"{\"value\":\"0.0067\"}"},{"value":"{\"value\":\"0.0101\"}"},{"value":"{\"value\":\"0.0135\"}"},{"value":"{\"value\":\"0.0303\"}"},{"value":"{\"value\":\"0.0472\"}"},{"value":"{\"value\":\"0.0640\"}"},{"value":"{\"value\":\"0.0808\"}"},{"value":"{\"value\":\"0.1651\"}"}]] 19 matrix y 285×4 285 4 double 1.0e+06 *
4.9992 0.0008 0.0000 0
4.9992 0.0008 0.0000 0.0000
4.9992 0.0008 0.0000 0.0000
4.9992 0.0008 0.0000 0.0000
4.9992 0.0008 0.0000 0.0000
4.9992 0.0008 0.0000 0.0000
4.9992 0.0008 0.0000 0.0000
4.9992 0.0008 0.0000 0.0000
4.9992 0.0008 0.0001 0.0000
4.9992 0.0008 0.0001 0.0000
double 6 double [[{"value":"{\"value\":\"4.9992\"}"},{"value":"{\"value\":\"0.0008\"}"},{"value":"{\"value\":\"0.0000\"}"},{"value":"{\"value\":\"0\"}"}]] 19 figure ada9e41e-efcc-4eaa-a062-feeb60a7eb6f...