from ODESolver import * import numpy as np import matplotlib.pyplot as plt class PredatorPrey: def __init__(self,r,m,a,b): self.r = r self.m = m self.a = a self.b = b def __call__(self, u, t): x, y = u[0],u[1] r = self.r; m = self.m a = self.a; b = self.b return r*x-a*x*y, -m*y+b*x*y problem = PredatorPrey(1,1,0.3,0.2) solver = RungeKutta4(problem) solver.set_initial_condition((1,1)) time = np.linspace(0,20,201) u,t = solver.solve(time) plt.plot(t,u[:,0],label='Prey pop.') plt.plot(t,u[:,1],label='Predator pop.') plt.legend() plt.show() """ Terminal> python predator_prey.py """