Jupyter Snippet CB2nd 07_lotka

Jupyter Snippet CB2nd 07_lotka

15.7. Analyzing a nonlinear differential system — Lotka-Volterra (predator-prey) equations

from sympy import *
init_printing(pretty_print=True)

var('x y')
var('a b c d', positive=True)

png

f = x * (a - b * y)
g = -y * (c - d * x)
solve([f, g], (x, y))

png

(x0, y0), (x1, y1) = _
M = Matrix((f, g))
M

png

J = M.jacobian((x, y))
J

png

M0 = J.subs(x, x0).subs(y, y0)
M0

png

M0.eigenvals()

png

M1 = J.subs(x, x1).subs(y, y1)
M1

png

M1.eigenvals()

png