In [ ]:

```
from sympy import *
init_printing()
```

In [ ]:

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

The variables x and y represent the populations of the preys and predators, respectively. The parameters a, b, c and d are positive parameters (described more precisely in "How it works..."). The equations are:

$$\begin{align} \frac{dx}{dt} &= f(x) = x(a-by)\\ \frac{dy}{dt} &= g(x) = -y(c-dx) \end{align}$$In [ ]:

```
f = x * (a - b*y)
g = -y * (c - d*x)
```

Let's find the fixed points of the system (solving f(x,y) = g(x,y) = 0).

In [ ]:

```
solve([f, g], (x, y))
```

In [ ]:

```
(x0, y0), (x1, y1) = _
```

Let's write the 2D vector with the two equations.

In [ ]:

```
M = Matrix((f, g)); M
```

Now we can compute the Jacobian of the system, as a function of (x, y).

In [ ]:

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

In [ ]:

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

In [ ]:

```
M0.eigenvals()
```

In [ ]:

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

In [ ]:

```
M1.eigenvals()
```

You'll find all the explanations, figures, references, and much more in the book (to be released later this summer).

IPython Cookbook, by Cyrille Rossant, Packt Publishing, 2014 (500 pages).