#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Dec 12 13:56:52 2022
File network_example.m
%igure 2.9 Numerical Simulation of network

@author: bingalls
"""
import numpy as np
import matplotlib.pyplot as plt

def dynamics(x, t):
    dx=[0,0,0,0] #generate a list to store derivatives
    dx[0]=3-2*x[0]-2.5*x[0]*x[1]
    dx[1]= 2*x[0]-2.5*x[0]*x[1]
    dx[2]= 2.5*x[0]*x[1] - 3*x[2]
    dx[3]= 2.5*x[0]*x[1] - 4*x[3]
    return dx

t_min=0; t_max=10; dt=0.1 #specify time-grid: from 0 0 to 10 with steps of 0.1
times=np.arange(t_min, t_max+dt, dt) #generate time-grid list
x0=[0,0,0,0] #specify initial condition


from scipy.integrate import odeint
x=odeint(dynamics, x0, times) #run simulation

plt.figure() #generate figure
plt.plot(times, x[:,0], label="[A]", linewidth=2)
plt.plot(times, x[:,1], label="[B]", linewidth=2)
plt.plot(times, x[:,2], label="[C]", linewidth=2)
plt.plot(times, x[:,3], label="[D]", linewidth=2)
plt.xlabel("Time")
plt.ylabel("concentration")
plt.legend()