title: MATLAB - Optimization of SIR epidemic model
body: <p>I'm trying to model a flu epidemic using the SIR model: <a href="http://en.wikipedia.org/wiki/Epidemic_model#The_SIR_Model" rel="nofollow">http://en.wikipedia.org/wiki/Epidemic_model#The_SIR_Model</a>.</p>
  
  <p>It basically requires me to solve 3 differential equations simultaneously.</p>
  
  <p>My task is to fit a graph to a set of data and I was just wondering how I should go about doing this.</p>
  
  <p>I've managed to setup a system to solve the ODEs like this:</p>
  
  <pre><code>function dydt = sir_ode(t,y,p)
  B = p(1);
  r = p(2);
  S = y(1);
  I = y(2);
  R = y(3);
  dydt = [-B*I*S; B*I*S - r*I; r*I];
  </code></pre>
  
  <p>and the m file to call it:</p>
  
  <pre><code>time = 1:24;
  y0 = [400 1 0];
  tspan = time;
  p0 = [.01 .5];
  [t,y] = ode45(@sir_ode,tspan,y0,[],p0);
  </code></pre>
  
  <p>so I have a tspan, I have a y0 matrix for S, I and R. For my function, the output contains 3 of the differential equations so I can solve them together with the ode45 function.</p>
  
  <p>Now all I need to do now is find the appropriate p0 matrix so I can fit the curves to my data.</p>
  
  <p>Firstly, can anyone see any flaws in my solving method and secondly, who would have any suggestions on how I would go about finding the best p0 matrix?</p>
  
  <p>Thanks!!</p>