Near a steady state, a model with two variables behaves like a linear system . Look for solutions that keep their direction and only change their size: the direction must be an eigenvector, and along it the motion is a phase line, . Adding such solutions gives every solution. Two numbers, the trace and the determinant of , decide what the picture looks like: a saddle, a node, or a spiral.
import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import solve_ivp
from scipy.optimize import fsolve
from scipy.linalg import expm
plt.rcParams.update({"figure.dpi": 130, "font.size": 9, "axes.spines.top": False,
"axes.spines.right": False})
C_EXACT, C_OUTER, C_INNER, C_COMP = "#111111", "#0072B2", "#D55E00", "#009E73"
C_GREY = "#999999"
r, K, Nc = 1.0, 10.0, 1.0 # 1/day, 1e8 cells/mL, 1e8 cells/mL
dbar = lambda N: 1 / (1 + N / Nc) # drug nullcline (the QSS drug level)
NN = np.linspace(0, K, 400)
def interior_states(a):
z = np.roots([-r / (K * Nc), r * (1 / Nc - 1 / K), r - a])
return sorted(x.real for x in z if abs(x.imag) < 1e-12 and x.real > 0)
def jacobian(N, d, a, delta):
return np.array([[r * (1 - 2 * N / K) - a * d, -a * N],
[-delta * d / Nc, -delta * (1 + N / Nc)]])
def mark(ax, x, y, stable, ms=6):
style = dict(color=C_COMP) if stable else dict(mfc="white", mec=C_EXACT)
ax.plot([x], [y], "o", ms=ms, zorder=6, clip_on=False, **style)
def phase_plane(ax, F, G, xlim, ylim, trajs=(), t_max=20.0, n_grid=200,
density=1.2, flow_color="thistle", null_colors=(C_INNER, C_OUTER),
lw_null=2.0, lw_traj=1.0, null=True, fixed_points=True):
"""Phase portrait of x' = F(x, y), y' = G(x, y), after
A. Buttenschoen, NumericalPDEs/de (2019): streamlines whose width grows
with the speed, nullclines as zero contours (x-nullcline in the first
colour), trajectories from the points in trajs (squares), and steady
states found by fsolve from a grid of guesses and classified by the
eigenvalues of a finite-difference Jacobian (filled: stable, open:
unstable). F and G must accept numpy arrays. Returns the steady states."""
X, Y = np.meshgrid(np.linspace(*xlim, n_grid), np.linspace(*ylim, n_grid))
U, V = F(X, Y), G(X, Y)
speed = np.hypot(U, V)
ax.streamplot(X, Y, U, V, density=density, color=flow_color, arrowsize=1.0,
linewidth=0.4 + 1.6 * np.sqrt(speed / np.nanmax(speed)), zorder=1)
if null:
for Z, col in zip((U, V), null_colors):
ax.contour(X, Y, Z, [0], colors=[col], linewidths=lw_null, zorder=3)
rhs = lambda t, z: [F(*z), G(*z)]
for z0 in trajs:
s = solve_ivp(rhs, (0, t_max), z0, rtol=1e-9, atol=1e-11,
method="LSODA", dense_output=True)
t = np.concatenate([np.linspace(0, 0.02 * t_max, 400),
np.linspace(0.02 * t_max, t_max, 1600)])
ax.plot(*s.sol(t), color=C_EXACT, lw=lw_traj, zorder=4)
ax.plot(*z0, "s", color=C_EXACT, ms=3, zorder=4, clip_on=False)
fps = []
if fixed_points:
f2 = lambda z: [F(*z), G(*z)]
for gx in np.linspace(*xlim, 12):
for gy in np.linspace(*ylim, 12):
z, _, ier, _ = fsolve(f2, [gx, gy], full_output=True)
inside = (xlim[0] - 1e-9 <= z[0] <= xlim[1] + 1e-9
and ylim[0] - 1e-9 <= z[1] <= ylim[1] + 1e-9)
if ier == 1 and inside and not any(np.allclose(z, p, atol=1e-6) for p in fps):
fps.append(z)
e = 1e-6
for x0, y0 in fps:
J = np.array([[F(x0 + e, y0) - F(x0 - e, y0), F(x0, y0 + e) - F(x0, y0 - e)],
[G(x0 + e, y0) - G(x0 - e, y0), G(x0, y0 + e) - G(x0, y0 - e)]]) / (2 * e)
stable = np.all(np.linalg.eigvals(J).real < 0)
style = dict(color=C_COMP) if stable else dict(mfc="white", mec=C_EXACT)
ax.plot([x0], [y0], "o", ms=6, zorder=6, clip_on=False, **style)
ax.set_xlim(*xlim); ax.set_ylim(*ylim)
return fpsOn the phase line, near a steady state the deviation obeys (Proposition 1). In the plane, a model with two variables is linearized at a steady state in the same way: the deviation obeys, to first order,
where is the Jacobian matrix of at , the matrix of partial derivatives . This page solves (1) and sorts its solutions into types; Drug and Bacteria in the Plane applies the result to a model.
Separating time from direction¶
On the phase line, is solved by . The two equations of (1) are coupled, so they cannot be solved one at a time. Instead, separate time from direction, as in separation of variables: look for a solution that keeps a fixed direction and changes only its size,
Substituting into gives
The left side points along , so the right side must too. If is an eigenvector, , the vector equation becomes the scalar equation : along the motion is a phase line with slope , and .
Proposition 1 (Superposition principle)
If and solve , then so does for all constants , , real or complex.
Proof 1
Matrix multiplication is linear, so .
Proposition 2 (Eigenvector solutions)
If with , then solves . If has eigenvalues with eigenvectors , , every solution is
with , fixed by .
Proof 2
. By Proposition 1, (4) then solves the system for all , . The eigenvectors are not parallel: if , then and . So every initial value can be written as , and since a solution is determined by its initial value, every solution is of the form (4).
In coordinates along the eigenvectors the system splits into two phase lines, and : these are the variables that separate.
Remark 1 (Eigenvectors are the directions the flow does not turn)
At a point the velocity is . If is parallel to , the solution through moves along the line through the steady state and , and never leaves it. If not, it is pushed off that line, and its direction turns. So the eigenvectors are exactly the lines through the steady state that the flow carries into themselves: the dashed blue lines in the gallery below.
With two real eigenvalues there are two such lines, and every other solution turns, but only from one of them towards the other. By (4) its direction is a mix of and with weights and . As the first weight wins and the solution lines up with ; as it lines up with . The turning is finite: less than half a turn in all.
The eigenvalues are the roots of a quadratic (Proposition 5 below), so two cases are left: a complex pair, for which there is no such line, and a repeated root, for which there may be only one.
Complex eigenvalues¶
When , in the notation of Proposition 5, the eigenvalues are not real, and neither is any eigenvector: no line through the steady state is carried into itself (Remark 1). Every direction is turned, so no solution keeps its direction, and the ansatz (2) finds nothing. The simplest system that turns every direction shows what takes its place.
Example 1 (Turning and stretching)
This is what a complex eigenvalue means. Write the point as the complex number . Then
that is, with : a phase line whose slope is a complex number, solved by . By Euler’s formula, , and multiplying by it turns a point by the angle ; multiplying by stretches it. The real part of the eigenvalue is the rate of growth, and the imaginary part is the rate of turning.
Every real matrix with complex eigenvalues is this example, drawn on a tilted frame. Let , , be an eigenvalue of with eigenvector , where and are real vectors. The real and imaginary parts of are
The matrix of Example 1 acts on and in exactly this way. So in coordinates along and , that is, writing , the system becomes
the example again. For real eigenvalues, coordinates along the two eigenvectors split the system into two phase lines. For complex ones, coordinates along and turn it into the turning and stretching of (7). Circles in become ellipses in the plane, so the solutions are spirals around ellipses spanned by and , turning from towards .
Proposition 3 (Complex eigenvalues)
Proof 3
First, and are not parallel: otherwise would be a complex multiple of a real vector , and is impossible because is real and is not. So every can be written as , in one way.
By (9), solves exactly when solves the system of Example 1. In complex form that system is with , so , and
Collecting the terms with and with , . This is the claim with and , and at it reads .
Equivalently, : the two solutions are the real and imaginary parts of the complex solution that Proposition 2 gives.
The brackets in (11) are periodic with period : on their own they go around an ellipse. The factor shrinks the ellipse if and grows it if , so trajectories are spirals. If the ellipse neither shrinks nor grows, and the orbits are closed: a center. The imaginary part sets the rotation, and the real part alone decides stability. Since , that is the sign of the trace.
Example 2 (A tilted spiral)
alpha, omega = -0.2, 1.0
M = np.array([[alpha, -omega], [omega, alpha]]) # the example, eq-pp-polar
a, b = np.array([1.0, 1.0]), np.array([1.0, 0.0])
E = np.column_stack([a, -b]) # tilted frame: columns a, -b
s = np.linspace(0, 2 * np.pi, 300)
tt = np.linspace(0, 14, 1400)
fig, axs = plt.subplots(1, 2, figsize=(7.0, 3.3))
for ax, frame, lim, labels, title in (
(axs[0], np.eye(2), 1.35, ("$(1, 0)$", "$(0, 1)$"), "turning and stretching"),
(axs[1], E, 1.6, (r"$\mathbf{a}$", r"$-\mathbf{b}$"), "the same, on a tilted frame")):
for rr in (1.0, np.exp(2 * np.pi * alpha / omega)): # one turn apart
ax.plot(*(frame @ np.array([rr * np.cos(s), rr * np.sin(s)])),
color=C_GREY, lw=0.8, ls=":")
Z = frame @ np.array([expm(M * t) @ [1.0, 0.0] for t in tt]).T
ax.plot(*Z, color=C_EXACT, lw=1.1)
for i in (120, 440):
ax.annotate("", xy=Z[:, i + 12], xytext=Z[:, i],
arrowprops=dict(arrowstyle="-|>", color=C_EXACT, lw=0.9))
for vec, lab, off in zip(frame.T, labels, ((4, -10), (-6, 6))):
ax.annotate("", xy=vec, xytext=(0, 0),
arrowprops=dict(arrowstyle="-|>", color=C_OUTER, lw=1.4))
ax.annotate(lab, xy=vec, xytext=off, textcoords="offset points",
color=C_OUTER, fontsize=9)
mark(ax, 0, 0, True, ms=5)
ax.set_xlim(-lim, lim); ax.set_ylim(-lim, lim); ax.set_aspect("equal")
ax.set_xticks([]); ax.set_yticks([])
ax.spines["top"].set_visible(True); ax.spines["right"].set_visible(True)
ax.set_title(title, fontsize=9)
fig.tight_layout();
Left: Example 1 with , , started at . Dotted: circles one turn apart, the second times the first. Right: the matrix of Example 2, started at . It is the left picture with moved to and moved to : circles become ellipses, and the spiral follows them.
Repeated eigenvalues¶
The two roots coincide when , in the notation of Proposition 5. If , every vector is an eigenvector and every solution moves straight in or out along its own line, a star. Otherwise all eigenvectors are multiples of one vector , and Proposition 2 gives only one solution. A triangular example, solved with the integrating factor, shows what the second looks like.
Example 3 (A repeated eigenvalue)
Proposition 4 (Repeated eigenvalue)
Proof 4
Following Example 3, try . Then
which agree exactly when .
Such a exists. Let . A double root means and , so has trace and determinant . For every matrix, , as multiplying out shows, so here . Since , some has , and says is an eigenvector, with . Take .
Finally and are not parallel, since and . So every initial value is , and Proposition 1 and uniqueness finish the proof.
For large the term outgrows in (17), so every trajectory ends up parallel to the one eigenvector line, a degenerate node. The factor only delays the decay: if , then , and the steady state is still stable. A repeated root is the borderline between a node () and a spiral (): trajectories start to turn, but not all the way round.
Trace and determinant¶
Proposition 5 (Trace and determinant)
Let and . The eigenvalues of are the roots of ,
Consequently:
| condition | eigenvalues | the steady state is |
|---|---|---|
| real, opposite signs | a saddle: unstable | |
| , , | real, both negative | a stable node |
| , , | complex, negative real part | a stable spiral |
| , , | real, both positive | an unstable node |
| , , | complex, positive real part | an unstable spiral |
The borderlines are: , a repeated eigenvalue (star or degenerate node); , , purely imaginary eigenvalues (a center); and , a zero eigenvalue.
Proof 5
has determinant , and is an eigenvalue exactly when this vanishes. The quadratic formula gives the roots, and comparing coefficients gives their sum and product. If the product is negative, so the roots are real with opposite signs. If and the roots are real, they have the same sign, which is the sign of their sum ; if they are complex they are , with real part .
A saddle has one direction along which solutions approach and one along which they leave: it is an unstable point of a phase line with one extra, stable direction. The table is in Strogatz §5.2 and §6.3 Strogatz, 2015.
Here is every case, each drawn from the exact solution of the linear system.
from scipy.linalg import expm
LIN = [("saddle", [[1, 1], [4, -2]]),
("stable node", [[-1, 1], [0, -3]]),
("unstable node", [[1, -1], [0, 3]]),
("degenerate node", [[-1, 1], [0, -1]]),
("stable spiral", [[-0.5, -3], [1, -0.5]]),
("unstable spiral", [[0.3, -3], [1, 0.3]]),
("center", [[0, -3], [1, 0]]),
("star", [[-1, 0], [0, -1]])]
fig, axs = plt.subplots(2, 4, figsize=(7.4, 4.0))
tt = np.linspace(-8, 8, 1601)
for k, (ax, (name, A)) in enumerate(zip(axs.flat, LIN)):
A = np.array(A, float)
phase_plane(ax, lambda x, y: A[0, 0] * x + A[0, 1] * y,
lambda x, y: A[1, 0] * x + A[1, 1] * y, (-1, 1), (-1, 1),
null=False, fixed_points=False, density=0.7, n_grid=81)
lam, V = np.linalg.eig(A)
if np.all(np.isreal(lam)) and name != "star": # eigenvector lines
for j in range(2):
v = V[:, j].real
ax.plot([-2 * v[0], 2 * v[0]], [-2 * v[1], 2 * v[1]], color=C_OUTER,
lw=1.3, ls="--", zorder=3)
if name == "stable spiral":
starts = [(0.9, 0), (-0.9, 0)]
elif name == "unstable spiral":
starts = [(0.15, 0), (-0.15, 0)]
elif name == "center":
starts = [(0.3, 0), (0.6, 0), (0.9, 0)]
else:
starts = [0.75 * np.array([np.cos(th), np.sin(th)])
for th in np.linspace(0, 2 * np.pi, 6, endpoint=False) + 0.3]
for z0 in starts: # x(t) = e^{At} x(0)
Z = np.array([expm(A * s) @ np.array(z0, float) for s in tt]).T
Z[:, np.abs(Z).max(axis=0) > 3] = np.nan
ax.plot(*Z, color=C_EXACT, lw=0.8, zorder=4)
i = np.nanargmin(np.abs(np.hypot(*Z) - 0.6))
ax.annotate("", xy=Z[:, i + 15], xytext=Z[:, i],
arrowprops=dict(arrowstyle="-|>", color=C_EXACT, lw=0.8))
if name == "center":
ax.plot([0], [0], "o", color=C_GREY, ms=5, zorder=6)
else:
mark(ax, 0, 0, np.all(lam.real < 0), ms=5)
ax.set_title(f"({'abcdefgh'[k]}) {name}", fontsize=8.5)
ax.text(0.03, 0.03, rf"$T = {np.trace(A):g}$, $\Delta = {np.linalg.det(A):.3g}$",
transform=ax.transAxes, fontsize=7,
bbox=dict(fc="white", ec="none", alpha=0.8, pad=1))
ax.set_xticks([]); ax.set_yticks([]); ax.set_aspect("equal")
ax.spines["top"].set_visible(True); ax.spines["right"].set_visible(True)
fig.tight_layout();
Phase portraits of on the square , with trace and determinant in each corner. Black: exact solutions , forward and backward in time. Dashed blue: eigenvector lines, which are themselves trajectories. The matrices are
Things to notice:
(a) The eigenvalues are 2 and -3, with eigenvectors and . They need not be perpendicular. Trajectories come in along the steep line and leave along the line .
(b) The eigenvalues are -1, eigenvector , and -3, eigenvector . Trajectories first move roughly parallel to the fast direction , then turn and arrive tangent to the slow direction, the axis.
(c) is (b) with time reversed: is replaced by , the same curves with the arrows flipped.
(e), (f), (g) The three matrices differ only on the diagonal, that is, in the trace. All three turn counterclockwise: at the velocity is the first column of , which points up because . In (g), and give , so the orbits are ellipses times as wide as they are tall. The sign of decides whether the turning goes inward, outward, or neither.
(d) and (h) have the same trace and determinant, twice, but different pictures: one eigenvector line in (d), every line in (h), as in Proposition 4. Trace and determinant fix the eigenvalues, not the eigenvectors.
The trace–determinant plane. Proposition 5 sorts every matrix by the point . Plot that point, and the type of the steady state can be read off from the region it lands in.
fig, ax = plt.subplots(figsize=(5.6, 3.4))
TT = np.linspace(-4.5, 4.5, 400)
ax.fill_between(TT, -2, 0, color=C_INNER, alpha=0.07, lw=0)
ax.plot(TT, TT ** 2 / 4, color=C_OUTER, lw=1.5)
ax.axhline(0, color=C_EXACT, lw=0.8); ax.axvline(0, color=C_EXACT, lw=0.8)
ax.plot([0, 0], [0, 4.5], color=C_COMP, lw=2.5)
for x, y, s in ((-2.3, 4.3, "stable spirals"), (0.6, 4.3, "unstable spirals"),
(-4.4, 0.5, "stable nodes"), (3.0, 0.5, "unstable nodes"),
(-0.5, -1.3, "saddles")):
ax.text(x, y, s, fontsize=8, color="#555555", ha="left", va="center")
ax.text(0.1, 1.9, "centers", fontsize=8, color=C_COMP)
ax.text(3.15, 2.0, r"$T^2 = 4\Delta$", fontsize=8, color=C_OUTER)
pts = {}
for k, (name, A) in enumerate(LIN):
A = np.array(A, float)
pts.setdefault((round(np.trace(A), 3), round(np.linalg.det(A), 3)), []).append("abcdefgh"[k])
for (Tr, Dt), labels in pts.items():
ax.plot([Tr], [Dt], "o", color=C_EXACT, ms=4, zorder=5)
ax.annotate(", ".join(labels), (Tr, Dt), xytext=(4, 4), textcoords="offset points",
fontsize=8)
states = [((0.0, 1.0), "cleared", (-40, 2))] + [
((n, dbar(n)), lab, (6, -10)) for n, lab in zip(interior_states(2.0), (r"$N_-$", r"$N_+$"))]
for (N, d), lab, off in states:
Jd = jacobian(N, d, 2.0, 1 / 3)
ax.plot([np.trace(Jd)], [np.linalg.det(Jd)], "*", color=C_INNER, ms=9, zorder=6)
ax.annotate(lab, (np.trace(Jd), np.linalg.det(Jd)), xytext=off,
textcoords="offset points", fontsize=8, color=C_INNER)
ax.set_xlim(-4.5, 4.5); ax.set_ylim(-2, 5)
ax.set_xlabel(r"trace $T$"); ax.set_ylabel(r"determinant $\Delta$")
fig.tight_layout();
The trace–determinant plane. Below the axis (shaded): saddles. Above it, the parabola separates nodes (outside) from spirals (inside), and the axis separates stable (left) from unstable (right). Black dots: the gallery, except the saddle (a) at , below the frame; (d) and (h) sit at the same point on the parabola, and the center (g) on the green half-axis. Orange stars: the three steady states of the drug model (1) of Drug and Bacteria in the Plane, with /day and the slow drug, /day. None of them is inside the parabola.
For a nonlinear system, the Jacobian gives the right picture near a steady state whenever lies strictly inside one of the open regions: saddles, nodes and spirals keep their type, because a small nonlinear term cannot push the point across a boundary. On a boundary it can. A linear center may be a slow stable spiral, a slow unstable spiral, or a true center of the nonlinear system; a degenerate node may become a node or a spiral; and says nothing at all. That is where the saddle-node bifurcation happens. Strogatz §6.3 Strogatz, 2015.
- Strogatz, S. H. (2015). Nonlinear Dynamics and Chaos (2nd ed.). Westview Press.