Simulate Coupled Differential Equations in Python

This simulation predicts the spread of HIV infection in a body with an initial infection. The human immunodeficiency virus (HIV) infection spreads and can develop into acquired immunodeficiency syndrome (AIDS). AIDS can lead to immune system failure and eventual inability to defend the body against infection or cancer. Without treatment with antiretroviral drugs, survival time after infection with HIV is about 9 to 11 years, depending on a number of factors. Antiretroviral drugs such as TDF…


  1. #——————————————————————————-
    # Name: HIV simulation
    # Purpose: with administration of antivirus drugs A,kr7
    # ——————————————————————————-
    import numpy as np
    from scipy.integrate import odeint
    import matplotlib.pyplot as plt

    def hiv(x,t):
    kr1 = 1e5 #new healthy cells
    kr2 = 0.1 #death rate of healthy cells
    kr3 = 2e-7 #healthy cells converting to infected cells
    kr4 = 0.5 #death rate of infected cells
    kr5 = 5 #death rate of virus
    kr6 = 100 #production of virus by infected cells
    kr7 = 1.0

    if t>3.0: # drugs begin at year 3
    A = 100.0 #A = 0 means no drugs administration
    A = 0.0

    h = x[0]
    i = x[1]
    v = x[2]
    p = kr3*h*v
    dhdt = kr1 – kr2*h – p
    didt = p – kr4*i
    dvdt = -p – kr5*v + kr6*i – kr7*A*v # drugs will eliminate proportionally with A*v
    return [dhdt, didt, dvdt]

    def main():
    #Initial Conditions
    x0 = [1e6,0,100]
    t = np.linspace(0,15,1000) #graph over 15 years, 1000 points
    x = odeint(hiv,x0,t)
    h = x[:,0]
    i = x[:,1]
    v = x[:,2]

    plt.xlabel('time in years')

    if _name_ == '__main__':

Leave a Reply

Your email address will not be published.