Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3459382
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:05:58+00:00 2026-05-18T10:05:58+00:00

I am trying to create a simple simulation program of SIR-epidemics model in java.

  • 0

I am trying to create a simple simulation program of SIR-epidemics model in java.

Basically, SIR is defined by a system of three differential equations:
S'(t) = – l(t) * S(t)
I'(t) = l(t) * S(t) – g(t) * I(t)
R'(t) = g(t) * I(t)

S – susceptible people, I – infected people, R – recovered people.

l(t) = [c * x * I(t)] / N(T)

c – number of contacts, x – infectiveness (probability to get sick after contact with sick person), N(t) – total population (which is constant).

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.

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 < 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); 
    }
}

}

I would greatly appreciate any help, many thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T10:05:59+00:00Added an answer on May 18, 2026 at 10:05 am

    Time-series differential equations can be simulated numerically by taking dt = a small number, and using one of several numerical integration techniques e.g. Euler’s method, or Runge-Kutta. Euler’s method may be primitive but it works OK for some equations and it’s simple enough that you might give it a try. e.g.:

    S'(t) = – l(t) * S(t)

    I'(t) = l(t) * S(t) – g(t) * I(t)

    R'(t) = g(t) * I(t)

    int N = 100;
    double[] S = new double[N+1];
    double[] I = new double[N+1];
    double[] R = new double[N+1];
    
    S[0] = /* initial value */
    I[0] = /* initial value */
    R[0] = /* initial value */
    
    double dt = total_time / N;
    
    for (int i = 0; i < 100; ++i)
    {
       double t = i*dt;
       double l = /* compute l here */
       double g = /* compute g here */
    
       /* calculate derivatives */
       double dSdt = - I[i] * S[i];
       double dIdt = I[i] * S[i] - g * I[i];
       double dRdt = g * I[i];
    
       /* now integrate using Euler */
       S[i+1] = S[i] + dSdt * dt;
       I[i+1] = I[i] + dIdt * dt;
       R[i+1] = R[i] + dRdt * dt;
    }
    

    The tough part is figuring out how many steps to use. You should read one of the articles I have linked to. More sophisticated differential equation solvers use variable step sizes that adapt to accuracy/stability for each step.

    I would actually recommend using numerical software like R or Mathematica or MATLAB or Octave, as they include ODE solvers and you wouldn’t need to go to all the trouble yourself. But if you need to do this as part of a larger Java application, at least try it out first with math software, then get a sense of what the step sizes are and what solvers work.

    Good luck!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a simple program using Gstreamer to take the input
So my situation is simple (IMHO): I am trying to create web-esque Java application
I'm trying to create simple script that subscribes a user to a company calendar.
I'm studying webrat and cucumber and trying to create simple example. Here is my
I setup a Paypal Sandbox account and am trying to create simple purchases through
Im trying to create a simple pan and zoom app using silverlight 4, but
Im trying to create a simple input box with form validation, but im not
I'm trying to create a simple widget to retrieve a users feeds, I have
I am trying to create a simple about page that uses JQuery click to
I'm trying to create a simple web page that resembles the following: I've got

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.