This section studies some first order nonlinear ordinary differential equations describing the time evolution (or “motion”) of spreading some deseases, including HIV, SIR, SEIR, and others.

Return to computing page for the first course APMA0330
Return to computing page for the second course APMA0340
Return to Mathematica tutorial for the first course APMA0330
Return to Mathematica tutorial for the second course APMA0340
Return to the main page for the first course APMA0330
Return to the main page for the second course APMA0340
Return to Part V of the course APMA0340
Introduction to Linear Algebra with Mathematica

HIV Models

The interaction of the HIV-1 virus with the body's immune system can be modeled by a system of differential equations similar to a predator-prey system. After an individual is infected with the HIV-1 virus, the amount of the virus in the bloodstream rises dramatically and the person will often suffer from flu-like symptoms. However, these symptoms will disappear after a period of weeks or months as the body begins to manufacture antibodies against the virus. Tests have been developed to determine the presence of HIV-1 antibodies. If a individual has such antibodies, then they are said to be HIV-1 positive. Once infected with the HIV-1 virus, it can be years before an HIV-positive patient exhibits the full symptoms of AIDS. The body's immune system fights the HIV-1 virus with white blood cells. The CD4-positive T-helper cells, a specific type of white blood cell, is especially important since it helps other cells fight the virus. However, the HIV-1 virus can destroy CD4-positive T-helper cells.

We can develop a system of differential equations to better understand the dynamics of the HIV-1 virus. Let V=V(t) be the population of the HIV-1 virus at time t. We will assume that the virus concentration is governed by the following differential equation,

\[ \frac{{\text d} V}{{\text d} t} \equiv \dot{P} = P - c\, V . \]
The first term in the right-hand side, P is some function of t that determines the rate at which new viral particles are created. The term −cV is the death rate for the virus. If someone discovers a drug that blocks the creation of new HIV-1 virions, then P would be zero and the virions would clear the body at the following rate,
\[ \dot{P} = - c\, V , \]
and \( V(t) = V_0 e^{-ct} , \) where V0 is the initial viral population.

Now let us consider a model for the concentration of T=T(t) of (uninfected) CD4-positive T-helper cells,

\[ \dot{T} = s + pT \left( 1- \frac{T}{T_{\max}} \right) - d_T T . \]
As usual, dot denotes derivative with respect to time t: \( \dot{T} = {\text d}T / {\text d} t . \) The constant s represents the rate at which T cells are created from sources in the body, such as the thymus. New CD4-positive T-helper cells can also be created from the proliferation of existing CD4-positive T-helper cells, and the second term in the equation represents the logistic growth of the T cells, where p is the maximum proliferation rate and Tmax is the T cell population density where proliferation ceases. Finally, dT is the death rate of the T cells.

The above equation has two equilibrium solutions:

\[ T = \frac{T_{\max}}{2p} \left( p- d_T \pm \sqrt{\frac{4ps}{T_{\max}} + \left( p -d_T \right)^2} \right) . \]

Like the influenza virus, the HIV-1 virus is an RNA virus. An RNA virus cannot reproduce on its own and must use the DNA from a host cell. To do this, the virus attaches itself to a CD4-positive T-helper cell and injects its RNA into the cell. This way the virus can use the T cell's DNA to replicate itself using a process called reverse transcription, where a DNA copy of the virus's RNA is made. New virus particles are created, and the T cell eventually bursts releasing the virus into the body. If we let I be the concentration of infected T cells, we can model this process with the following system of equations,

\begin{align*} \dot{I} &= k\,TV - \delta\,I , \\ \dot{V} &= N\delta \, I -c\, V , \end{align*}
where δ is the rate of loss of the virus producing T cells and N is the number of version's produced per infected T cell during its lifetime. The term k TV tells us the rate at which the HIV-1 virus infects T cells. This is the same idea as modeling how predators interact with prey in a Lotka--Volterra model. Thus, our complete model becomes
\begin{align*} \dot{T} &= s + pT \left( 1- \frac{T}{T_{\max}} \right) - d_T T -k\,TV , \\ \dot{I} &= k\,TV - \delta\,I , \\ \dot{V} &= N\delta \, I -c\, V . \end{align*}

The above system has one nontrivial critical point:

\[ T = \frac{c}{k\,N} , \quad I = \frac{k^2 N^2 s T_{\max} + ckN p T_{\max} - cd_T kN T_{\max} -c^2 p }{\delta k^2 N^2 T_{\max} } , \quad V = \frac{k^2 N^2 s T_{\max} + ckN p T_{\max} - cd_T kN T_{\max} -c^2 p }{ck^2 N T_{\max}} . \]
Then we calculate the Jacobian matrix:
JacobianMatrix[f_List?VectorQ, x_List] :=
Outer[D, f, x] /; Equal @@ (Dimensions /@ {f, x})
a = {s + p*T*(1 - T/tmax) - dt*T - k*T*V, k*T*V - d*i, n*d*i - c*V}
b = {T, i, V}
JacobianMatrix[a, b] // MatrixForm
\[ {\bf J} = \begin{bmatrix} p \left( 1- \frac{T}{T_{\max}} \right) -d_T - \frac{p\,T}{T_{\max}} - k\,V & 0 & -k\,T \\ k\,V & -\delta & k\,T \\ 0 & \delta N & -c \end{bmatrix} . \]
At this critical point, the Jacobian becomes
\[ {\bf J} (\mbox{critical}) = \begin{bmatrix} -\frac{kNs}{c} -\frac{cp}{kN T_{\max}} & 0 & -\frac{c}{N} \\ p + \frac{kNs}{c} - d_T & -\delta & \frac{c}{N} \\ 0 & \delta N & -c \end{bmatrix} . \]

One class of drugs that HIV infected patients receive are reverse transcriptase (RT) inhibitors. RT inhibitors block the action of reverse transcription and prevent the virus from duplicating. If one could find the perfect RT inhibitor, then k=0 and our system becomes

\begin{align*} \dot{T} &= s + pT \left( 1- \frac{T}{T_{\max}} \right) - d_T T , \\ \dot{I} &= - \delta\,I , \\ \dot{V} &= N\delta \, I -c\, V . \end{align*}

Unfortunately, no one has discovered a perfect RT inhibitor, so we will need to modify the system to account for the effectiveness of the RT inhibitor. We can accomplish this by adding an effectiveness factor 1-η to the k VT term. Our system now becomes

\begin{align*} \dot{T} &= s + pT \left( 1- \frac{T}{T_{\max}} \right) - d_T T -k\left( 1-\eta \right) TV , \\ \dot{I} &= k\left( 1-\eta \right) TV - \delta\,I , \\ \dot{V} &= N\delta \, I -c\, V . \end{align*}

If η=1, then the RT inhibitor is completely effective. On the other hand, if η=0, then the RT inhibitor is completely ineffective. We now have a model for how the HIV-1 virus interacts with the immune system. Researchers can use data to estimate the parameters and see exactly what types of solutions are possible.

Example: In this model, the fox population is divided into three classes, all of which are measured in population density (foxes/km²), namely, susceptibles, denoted by X, are foxes that are currently healthy but are susceptible to catching the virus; infected, denoted by Y, are foxes that have caught the virus but are not yet capable of passing on the virus; and finally, infectious, denoted by Z, are foxes that are capable of infecting the susceptibles. The relevant equations for the fox rabies epidemic are
\[ \begin{split} \dot{X} &= a\,X - \left( b+ \gamma N \right) X - \beta\,X\,Z, \\ \dot{Y} &= \beta\,X\,Z - \left( \sigma + b + \gamma N \right) Y , \\ \dot{Z} &= \sigma\,Y - \left( \alpha + b + \gamma N \right) Z , \end{split} \]
with N = X + Y + Z being the total fox density. Note that the above model has no category of recovered immune foxes because very few, if any, survive after acquiring the rabies virus. The meaning of the coefficients and their estimated values are given in the following table.
Meaning of coefficients
Symbol Meaning Value
a average per capita birth rate of foxes 1 yr-1
b average per capita intrinsic death rate 0.5 yr-1
β rabies transmission coefficient 79.67 km² yr-1
σ 1/σ is the average latent period (∼ 28 to 30 days) 13 yr-1
α death rate of rabid foxes (average life expectancy ∼ 5 days) 73 yr-1
γ &gammalN represents increased death rate when N is large enough to deplete the food supply 0.1--5 km²yr-1

SIR and SIRS Models

This topic describes the differential equations that govern the classic deterministic SIR and SIRS compartmental models and describes how to configure EMOD, an agent-based stochastic model, to simulate an SIR/SIRS epidemic. In SIR models, individuals in the recovered state gain total immunity to the pathogen; in SIRS models, that immunity wanes over time and individuals can become reinfected. The EMOD generic simulation uses an SEIR-like disease model by default. You can modify the default SEIR model to an SIR model by turning off the incubation period.

As the first step in the modeling process, we identify the independent and dependent variables. The independent variable is time t, measured in days. We consider two related sets of dependent variables. The first set of dependent variables counts people in each of the groups, each as a function of time:

The second set of dependent variables represents the fraction of the total population in each of the three categories. So, if N is the total population (7,900,000 in our example), we have
Example: We consider transmission dynamics of a Childhood disease outbreak in a community with direct inflow of susceptible and vaccinated new-born. Childhood diseases are increasingly becoming the most common form of infectious diseases. These diseases include measles, mumps, Influenza, smallpox, chicken pox, Rubella, Polio etc., which take special interest to children under-five years who are born highly susceptible. The following SEIR model has four epidemiological compartments: the susceptible S, an exposed E, an infective I, and a recovered group R, i.e. the vaccinated and treated group who poses permanent immunity to the disease. We assume the vaccines are 100% efficient and death rates μ due to causes other than the disease in the compartments are not equal to births, leading to varying population size N. People who are recruited into the community with e the proportion of susceptible that are vaccinated as P (with 0 < P < 1) and take the rest to be susceptible. We assume the vaccination rate as π. A susceptible person will progress into the exposed group by being in contact with an infective individual, estimated by a contact rate β2 or through contact with an exposed individual, estimated by a contact rate β1. An exposed individual Progresses from exposed to the infective compartment at a rate δ. An infective child progresses from infected to the recovered group due to treatment at a rate γ. We also assume α to be death rate due to disease infection.

The resulting differential equations for the model are

\begin{align*} \frac{{\text d}S}{{\text d}t} &= \left( 1- P \right) \pi N - \frac{\beta_1 E + \beta_2 I}{N}\,S - \mu\, S, \\ \frac{{\text d}E}{{\text d}t} &= \frac{\beta_1 E + \beta_2 I}{N}\, S - \left( \delta + \mu \right) E, \\ \frac{{\text d}I}{{\text d}t} &= \delta\, E - \left( \alpha + \gamma + \mu \right) I, \\ \frac{{\text d}R}{{\text d}t} &= P\pi \,N + \gamma \,I - \mu\,R, \end{align*}
subject to the initial conditions
\[ S(0) = s_) , \quad E(0) = E_0 , \quad I(0) = I_0 , \quad R(0) = R_) . \]
We also assume that all coefficients of the system, μ, β1, β2, π, α, γ, and δ are constants, and N = S + E + I + R. Adding the above equations, we obtain
\[ \frac{{\text d}N}{{\text d}t} = \left( \pi - \mu \right) N - \alpha\,I, \]
which exhibits a varying population size with deaths due to fatal diseases.     ■


  1. Bjørnstad, O.N., Shea, K., Krzywinski, M., The SEIRS model for infectious disease dynamics, Nature Methods, 2020, volume 17, pages 557–558.
  2. SIR and SIRS Models, IDM
  3. Smith, D. and Moore, L., The SIR Model for Spread of Disease - The Differential Equation Model, The American Mathematical Monthly,
  4. Yano, T.K., Makinde, O.D., Malonza, D.M., Modelling Childhood Disease Outbreak in a Community with Inflow of Susceptible and Vaccinated New-born, Global Journal of Pure and Applied Mathematics, 2016, Volume 12, Number 5, pp. 3895-3916.


Return to Mathematica page
Return to the main page (APMA0340)
Return to the Part 1 Matrix Algebra
Return to the Part 2 Linear Systems of Ordinary Differential Equations
Return to the Part 3 Non-linear Systems of Ordinary Differential Equations
Return to the Part 4 Numerical Methods
Return to the Part 5 Fourier Series
Return to the Part 6 Partial Differential Equations
Return to the Part 7 Special Functions