File Exchange

image thumbnail

SIR Math Model of Virus Spread (Coronavirus or other)

version 1.0.20 (25.6 KB) by Tom Beekhuysen
Introductory model of infectious disease spread. Social distancing and social isolation affects beta (transmission rate).


Updated 12 Apr 2020

View License

You can change infection rate (transmission rate) and see how spread is affected (flatten the curve). Infection rate = beta = number of social contacts x probability of contracting virus each contact. When we socially isolate we reduce beta and therefore spread.

An individual is infectious for approximately 7 days. During this time they pass covid19 to approximately 2.5 people. These 2 basic parameters determine the model dynamics.

Simulink model is of the following system of three odes:

dS/dt = -β(I/N)S
dI/dt = β(I/N)S – γI
dR/dt = γI

S = Number Susceptible Individuals
I = Number Infectious Individuals
R = Number Recovered Individuals
N= Total Population
β = Ep = Number Social contacts x probability of transmitting disease each contact = Infection rate
γ = Recovery Rate

Key scenarios of dynamics:
If, during 7 days of being infectious, a person passes to 1 person then the disease will not grow, i.e., number of infectious individuals stays the same.
If, during 7 days of being infectious, a person passes to 2 or more people the disease grows, i.e., number of infectious individuals grows.
If, during 7 days of being infectious, a person does not pass to another person (or, say 10 people are sick at exact same time and pass to 9 people over 7 days) the disease will reduce, i.e., number of sick individuals goes to zero.
As individuals recover, the number of susceptible people decline, and therefore spread slows and eventually reduces to zero.

Cite As

Tom Beekhuysen (2020). SIR Math Model of Virus Spread (Coronavirus or other) (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (4)

Very good submission. Shall set it up in VBA and try the model. See what I can learn out of it

Cruz Ek

please save and share it by "Previous Version"

Wu Yue

Could you kindly share the code in Matlab?


Dear Tom Beekhuysen,
I have MatlabR2018b but couldn't open the file. I got a message saying that file has to be opened using Matlab2019b.
Can you help in this regard.
Thank you for your assistance.



Updated file.


Updated file.


Updated preview.


Updated preview.


Exported to R2018a.


Exported to version R2018a.


Corrected parameter.


Preview image.


Updated beta and gamma based on more recent data.


corrected typo.


Updated description.


Corrected typo.


Added notes in description and model about specific parameters to covid19. Typical individual is infectious 2-4 weeks. Rate of recovery is 25 days (3 weeks plus 4 days safety factor). Reported reproduction number is 2-3 (2.5).


Added note in slx model about when beta<gamma (infection rate is less than recovery rate) spread stops.


updated preview image


Exported to earlier version; 2018a.


Update image.


Updated text


Added system of odes to description and updated slx file


Corrected typo

MATLAB Release Compatibility
Created with R2018a
Compatible with any release
Platform Compatibility
Windows macOS Linux