21.06.2014 Views

SIR Model: The Boarding School Example - SAMSI

SIR Model: The Boarding School Example - SAMSI

SIR Model: The Boarding School Example - SAMSI

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Boarding</strong> <strong>School</strong> <strong>Example</strong>:<br />

MATLAB Cost Code<br />

function [Cost]=<strong>SIR</strong>Cost(param, t,Infected, YInit, N)<br />

% param: 2x1 vector of beta and gamma<br />

% t: time data % Infected: infected data<br />

% Cost: value of sum of squared errors<br />

beta=param(1);<br />

gamma=param(2);<br />

options=[];<br />

[t,PredY]=ode15s(@<strong>SIR</strong>ode, t, YInit, options, beta, gamma, N);<br />

PredInfected=PredY(:,2);<br />

DiffY=PredInfected’-Infected;<br />

DiffYsq=(DiffY).ˆ2;<br />

Cost=sum(DiffYsq);<br />

<strong>SIR</strong> <strong>Model</strong>: <strong>The</strong> <strong>Boarding</strong> <strong>School</strong> <strong>Example</strong> – p. 6/8

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!