""" A classical system of difference equations; the Lotka-Volterra model. The model describes the dynamics of two interacting species; one predator and one prey. """ import numpy as np import matplotlib.pyplot as plt x0 = 100 # startpopulasjon byttedyr y0 = 8 # startpopulasjon rovdyr a = 0.0015 b = 0.0003 c = 0.006 d = 0.5 N = 10000 # antall tidsenheter (dager) time = range(N+1) x = np.zeros(len(time)) y = np.zeros_like(x) x[0] = x0 y[0] = y0 for n in time[1:]: x[n] = x[n-1] + a * x[n-1] - b * x[n-1] * y[n-1] y[n] = y[n-1] + d * b * x[n-1] * y[n-1] - c * y[n-1] plt.plot(time, x,label = 'Byttedyr') plt.plot(time, y, label = 'Rovdyr') plt.xlabel('Tid') plt.ylabel('Populasjon') plt.legend() plt.show()