title: Differential Equations in Java
body: <p>I am trying to create a simple simulation program of SIR-epidemics model in java.</p>
  
  <p>Basically, SIR is defined by a system of three differential equations:<br>
  S'(t) = - l(t) * S(t)<br>
  I'(t) = l(t) * S(t) - g(t) * I(t)<br>
  R'(t) = g(t) * I(t)</p>
  
  <p>S - susceptible people, I - infected people, R - recovered people.</p>
  
  <p>l(t) = [c * x * I(t)] / N(T)</p>
  
  <p>c - number of contacts, x - infectiveness (probability to get sick after contact with sick person), N(t) - total population (which is constant).</p>
  
  <p>How can I solve such differential equations in Java? I don't think I know any useful way to do that, so my implementation produces rubbish. </p>
  
  <pre><code>public class Main {
  public static void main(String[] args) {
      int tppl = 100;
      double sppl = 1;
      double hppl = 99;
      double rppl = 0;
      int numContacts = 50;
      double infectiveness = 0.5;
      double lamda = 0;
      double duration = 0.5;
      double gamma = 1 / duration;
      for (int i = 0; i &lt; 40; i++) {
          lamda = (numContacts * infectiveness * sppl) / tppl;
          hppl = hppl - lamda * hppl;
          sppl = sppl + lamda * hppl - gamma * sppl;
          rppl = rppl + gamma * sppl;
          System.out.println (i + " " + tppl + " " + hppl + " " + sppl + " " + rppl); 
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I would greatly appreciate any help, many thanks in advance!</p>