Ordinary differential equations Growth model in Python

Ordinary differential equations Growth model in Python

In this, first of all we discuss how it works in Ordinary differential equations then we move to the Second step. In the Second step we implement the Growth Model in Python Programming.

If you are new to Python Programming also check the list of topics given below. So that you can easily understand the Ordinary differential equations Growth model in Python.




In Ordinary differential equations

The General idea is that, instead of solving problems to find unknown numbers, we can solve problems to find unknown functions. There are many possibilities for this to mean, but one thing is that we have an unknown function y of x, gives that y and its derivative y'

y '= ky

where k is constant. Such a relationship between an unknown function and its derivative (or other derivative) is what is called a differential equation. 


Growth Model

An example of a differential equation: Bacterial growth

Experiment 1: At the start of an experiment there are 100 bacteria. If bacteria follows an experimental growth pattern with rate k =0.02, then to find the population after 5 hours and 10 hours

Python Code:
import numpy as np
from scipy.integrate import odeint
k = 0.02
def f(y,x):
return k*y
xs = np.arange(0,11,1)
y0 = 100
ys = odeint(f,y0,xs)
print(xs)
print(ys)
for i in xs:
if i==5 or i==10:
k = int(i)
print('The population after' + str(i)+ 'hours is:' + str (ys[k]))
Experiment 1 Output: [ 0  1  2  3  4  5  6  7  8  9 10]
[[100.        ]
 [102.02013388]
 [104.08107658]
 [106.183654  ]
 [108.32870616]
 [110.51709106]
 [112.74968424]
 [115.02737897]
 [117.3510862 ]
 [119.72173541]
 [122.14027497]]
The population after 5 hours is:[110.51709106]
The population after 10 hours is:[122.14027497]

Experiment 2: At the start of an experimental  there are 100 bacteria. If the bacteria follows an exponential growth pattern with rate k = 0.01, draw the graph for population v/s time for next 20 hours

Python Code:
import numpy as np
from scipy.integrate import odeint
from matplotlib import pyplot as plt
k = 0.02
def f(y, x):
return k * y
xs = np.arange(0, 21, 1)
y0 = 100
ys = odeint(f, y0, xs)
for i in xs:
if i==20:
k = int(i)
print('The population after' + str(i) + 'hours is:' + str(ys[k]))
plt.plot(xs,ys)
plt.plot(xs,ys,'ro')
plt.xlabel('time in hours')
plt.ylabel('population of bacteria')
plt.title('population of bacteria (k =0.02)')
plt.show()
Output:
The population after 20 hours is:[149.18246908]
Ordinary differential equations Growth model in Python









Ordinary differential equations Growth model in Python