""" Example from lecture on Sept 23, logistic growth formulated and solved as a difference equation. """ import numpy as np import matplotlib.pyplot as plt x0 = 100 # initial population rho = 0.05 # growth rate R = 500 # max population (carrying capacity) N = 200 # number of years time = range(N + 1) x = np.zeros(N + 1) x[0] = x0 for n in time[1:]: x[n] = x[n - 1] + rho * x[n - 1] * (1 - x[n - 1] / R) plt.plot(time, x) plt.xlabel('Time') plt.ylabel('Population') plt.show()