Friday, March 6, 2015

py32. Logistic Growth in Python

Logistic growth of fisheries, or other populations, will go towards a Carrying Capacity. The growth will start exponentially and is S-shaped.


For a specific rate of growth, and Carrying Capacity, the Population is shown.


The vertical line shows the maximum derivative, that is where the maximum growth occurs.

# ex32.py
from __future__ import print_function, division
import numpy as np
import matplotlib.pyplot as plt

r = .25 # growth rate / yr
K = 100 # carrying capacity
t = 40 # number of years
num = np.zeros(t+1)
num[0] = 1
for i in range(t):
    num[i+1] = num[i]+r*num[i]*(1-num[i]/K)
plt.plot(range(t+1),num, 'b')
plt.xlabel('Year')
plt.ylabel('Number')
plt.title('Growth rate: 0.25, Carrying Capacity = 100')
plt.axvline(np.argmax(np.diff(num)),  color = 'k'  )
plt.show()

Output:

No comments:

Post a Comment