Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save lefuturiste/cd0d8ea99f9f2de201817a3e3587b138 to your computer and use it in GitHub Desktop.
Save lefuturiste/cd0d8ea99f9f2de201817a3e3587b138 to your computer and use it in GitHub Desktop.
import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt
t = np.arange(0, 15, 0.1)
a = 0.5
b = 0.5
def tick(y, t):
rabbits, foxes = y
return [
rabbits-a*rabbits*foxes,
-foxes+b*rabbits*foxes
]
sol = odeint(tick, [1, 1], t)
plt.plot(t, sol[:, 0], 'b', label='rabbits(t)')
plt.plot(t, sol[:, 1], 'g', label='foxes(t)')
plt.legend(loc='best')
plt.xlabel('t')
plt.grid()
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment