Вы находитесь на странице: 1из 7

Juei-Sheng Chiu - Module 3,

Computational Methods (EGRB 215)

Table of Contents
Clean Up .......................................................................................................................... 1
Honor Statement ................................................................................................................ 1
Problem 1-2 ...................................................................................................................... 1
Function file ...................................................................................................................... 7

Clean Up
clear all
close all
clc

Honor Statement
On my honor, I have neither given nor received aid on this assignment, and I pledge that I am in compliance
with the VCU Honor System

% signed Joshua Chiu


% Date: 4/19/2015

Problem 1-2
The differential equations are:

beta = [.005 .05 .1];


nu = [.05 .075 .1];

1
Juei-Sheng Chiu - Module 3, Com-
putational Methods (EGRB 215)

data = zeros(9,5);
for i = 1:3
for k = 1:3
n = 3*(i-1)+k;
[t, y] = ode45(@sir, [0 300], [99; 01; 0], [], beta(i), nu(k));
figure(n);
plot(t, y(:,1), t, y(:,2), t, y(:,3))
xlim([0 30]);
ylim([0 100]);
legend('Susceptible','Infected','Recovered')
title(['Beta =' num2str(beta(i)) '; v=' num2str(nu(k))])
xlabel('Time (days)')
ylabel('Population (%)')

data(n,1:2) = [beta(i) nu(k)]; % store beta & mu in appropriate cells


data(n,3:4) = [max(y(:,2)) t(find(max(y(:,2)) == y(:,2)))]; %find max%
% infected and its time, and stores it
data(n,5) = t(min(find(y(:,3)>=50))); % finds & stores 50% recovery time

line([0 data(n,5)], [50 50], 'Color', [1 0 0])


line([data(n,5) data(n,5)], [0 50], 'Color', [1 0 0])
text(data(n,5), 50, '50% Recovered')

line([0 data(n,4)], [data(n,3) data(n,3)], 'Color', [0 1 0])


line([data(n,4) data(n,4)], [0 data(n,3)], 'Color', [0 1 0])
text(data(n,4), data(n,3), 'Max infected')
end
end

fprintf('%8s %7s %11s %12s %10s\n', 'beta', 'nu', 'max %', ...
'max time', 'R=50 time')
disp(data);

beta nu max % max time R=50 time


0.0050 0.0500 67.0834 15.3779 24.5988
0.0050 0.0750 56.6998 15.4761 21.0403
0.0050 0.1000 47.8853 15.8315 20.1101
0.0500 0.0500 94.4053 1.8691 14.9916
0.0500 0.0750 92.2097 1.7800 10.5075
0.0500 0.1000 90.1976 1.7611 7.9223
0.1000 0.0500 96.8550 0.9917 14.4482
0.1000 0.0750 95.5878 0.9579 9.7751
0.1000 0.1000 94.4053 0.9346 7.4958

2
Juei-Sheng Chiu - Module 3, Com-
putational Methods (EGRB 215)

3
Juei-Sheng Chiu - Module 3, Com-
putational Methods (EGRB 215)

4
Juei-Sheng Chiu - Module 3, Com-
putational Methods (EGRB 215)

5
Juei-Sheng Chiu - Module 3, Com-
putational Methods (EGRB 215)

6
Juei-Sheng Chiu - Module 3, Com-
putational Methods (EGRB 215)

Function file
type sir

function [ ydot ] = sir( t, y, b, nu )


%SIR Putputs ydot, rate of change of the three populations, based on the
%current number in each population, beta (b) the contagious constant, and
%nu the recovery constant.
ydot = zeros(3,1);

ydot(1) = -b*y(1)*y(2);
ydot(2) = b*y(1)*y(2) - y(2)*nu;
ydot(3) = y(2)*nu;
end

Published with MATLAB® 7.12

Вам также может понравиться