Performance comparison of Python, MATLAB and R for numerical solutions of SI and SIR epidemiological models

This study comprehensively compares the computational efficiency and numerical accuracy of Python, MATLAB, and R in solving SI and SIR epidemiological models using Euler, Runge-Kutta, and Predictor-Corrector methods to guide researchers in selecting optimal tools for epidemic modeling.

Berkay Özışık, Elif Demirci

Published 2026-03-05
📖 5 min read🧠 Deep dive

Imagine you are a doctor trying to predict how a flu virus will spread through a school. You have a mathematical "recipe" (a model) that tells you how the disease moves from healthy kids to sick ones, and then to those who have recovered. This recipe is written in the language of calculus, which is great for theory but impossible to solve with a pencil and paper for real-world scenarios.

To get a prediction, you need a computer to do the heavy lifting. But here's the catch: there are different ways to tell the computer how to calculate the numbers, and there are different "computers" (software programs) you can use to run those calculations.

This paper is essentially a race between three popular software tools (Python, MATLAB, and R) to see which one is the fastest and most accurate at solving these disease models.

Here is the breakdown of the race using some everyday analogies:

1. The Race Track: The Disease Models

The researchers used two specific "tracks" for the race:

  • The SI Track (Susceptible-Infected): Imagine a simple game where people are either healthy or sick, and once they get sick, they stay sick. This track is like a straight line; we actually know the exact answer (the "finish line") beforehand. This allowed the researchers to check how close the software got to the truth.
  • The SIR Track (Susceptible-Infected-Recovered): This is a more complex game. People get sick, but then they recover and become immune. This track is like a winding mountain road with no map. Since there is no "exact answer" to check against, the researchers used a super-precise, high-end calculator (MATLAB's built-in ODE45 solver) as the "Gold Standard" to see how well the other tools performed.

2. The Running Styles: The Numerical Methods

To run the race, the software had to use specific "running styles" (mathematical methods) to take steps forward in time:

  • Euler's Method: Think of this as walking. You take small, simple steps. It's easy to understand, but if you take big steps, you might miss the curve of the road and end up in the wrong place. It's fast, but not very precise.
  • RK4 (Runge-Kutta 4th Order): This is like driving a sports car with a GPS. It doesn't just look ahead; it checks the road in four different directions before deciding where to go. It's much more complex and takes more energy, but it stays on the road perfectly, even on sharp turns.
  • Predictor-Corrector (P-C): This is like taking a guess and then double-checking. You take a step, guess where you'll land, and then immediately correct your path to make sure you're right. It's a middle ground between walking and driving.

3. The Competitors: Python, MATLAB, and R

These are the three "athletes" in the race:

  • Python: The Olympic Sprinter. It is free, very popular, and incredibly fast.
  • MATLAB: The Professional Engineer. It is expensive, widely used in universities, and very reliable, but often a bit heavier and slower than Python.
  • R: The Statistician's Powerhouse. It is amazing for analyzing data and making charts, but when it comes to raw speed in crunching numbers for these specific models, it tends to be the slowest.

4. The Results of the Race

Who was the most accurate?

  • The Winner: RK4 (The Sports Car) won hands down. No matter which software was used, this method got the closest to the "truth." Even when taking big steps, it was almost perfect.
  • The Runner-up: Predictor-Corrector was also very good, almost as accurate as the sports car.
  • The Loser: Euler's Method (The Walker) was the least accurate. If you tried to walk too fast (take big steps), you ended up way off course.

Who was the fastest?

  • The Speed King: Python crushed the competition. Whether the step size was big or tiny, Python finished the calculations significantly faster than the others. It was like a cheetah compared to a house cat.
  • The Middle Ground: MATLAB was decent. It wasn't the fastest, but it was reliable and got the job done in a reasonable time.
  • The Slowpoke: R consistently took the longest to finish the race. While it did the math correctly, it just took its time doing it.

5. The Big Takeaway

The researchers concluded that if you are a scientist or a student trying to model a disease outbreak:

  • Use Python if you want the best balance of speed and accuracy. It's the most efficient tool for the job.
  • Use the RK4 method if you need high precision. Don't rely on the simple "walking" method (Euler) if accuracy matters.
  • Don't worry too much about R for this specific type of heavy number-crunching, as it's slower than the others, though it's still capable of doing the job.

In short: Python + RK4 = The Fastest and Most Accurate Way to Predict Disease Spread.