Topic

Systems in the plane

linearSystem solves x′=Axx' = Ax exactly: for a 2 by 2 matrix it names the kind of equilibrium, and for larger matrices it gives eAte^{At} and the stability. planarSystem takes a nonlinear system, finds every equilibrium in a box with proof, and classifies each from its linearisation.

const s = linearSystem([[1, 2], [3, 2]]);
s.eigenvalues;      // ["-1", "4"]
s.kind;             // "saddle"
s.exponential;      // e^{At} as four formulas in t
s.solution([1, 0]); // ["2/5*exp(4*t) + 3/5*exp(-t)", "3/5*exp(4*t) - 3/5*exp(-t)"]

const pendulum = planarSystem(["y", "-sin(x) - y/2"], ["x", "y"]);
pendulum.equilibria({ x: [-4, 4], y: [-2, 2] });
// three records: saddle at (-π, 0), stable spiral at (0, 0), saddle at (π, 0)

Linear systems

With τ=tr⁡A\tau = \operatorname{tr} A and Δ=det⁡A\Delta = \det A, the eigenvalues are λ=12(τ±τ2−4Δ)\lambda = \tfrac12\bigl(\tau \pm \sqrt{\tau^2 - 4\Delta}\bigr), and the origin is

conditionkind
Δ<0\Delta < 0saddle: real eigenvalues of opposite signs
Δ>0, τ2>4Δ\Delta > 0,\ \tau^2 > 4\Deltanode: stable if τ<0\tau < 0, unstable if τ>0\tau > 0
Δ>0, τ2<4Δ, τ≠0\Delta > 0,\ \tau^2 < 4\Delta,\ \tau \ne 0spiral: stable if τ<0\tau < 0, unstable if τ>0\tau > 0
Δ>0, τ=0\Delta > 0,\ \tau = 0centre: closed orbits
Δ>0, τ2=4Δ\Delta > 0,\ \tau^2 = 4\Deltadegenerate node, or a star when AA is a multiple of the identity
Δ=0\Delta = 0a line of equilibria

The entries are rational, so the signs of τ\tau, Δ\Delta and τ2−4Δ\tau^2 - 4\Delta are decided exactly and the borderline cases are recognised for what they are.

The solution is x(t)=eAtx(0)x(t) = e^{At}x(0). For a 2 by 2 matrix, with μ=τ/2\mu = \tau/2 and δ=μ2−Δ\delta = \mu^2 - \Delta,

eAt=eμt(c(t) I+s(t) (A−μI)),(c,s)={(cosh⁡ωt, sinh⁡(ωt)/ω)δ=ω2>0(1, t)δ=0(cos⁡ωt, sin⁡(ωt)/ω)δ=−ω2<0, e^{At} = e^{\mu t}\Bigl(c(t)\,I + s(t)\,(A - \mu I)\Bigr), \qquad (c, s) = \begin{cases} (\cosh\omega t,\ \sinh(\omega t)/\omega) & \delta = \omega^2 > 0 \\ (1,\ t) & \delta = 0 \\ (\cos\omega t,\ \sin(\omega t)/\omega) & \delta = -\omega^2 < 0, \end{cases}

which follows from (A−μI)2=δI(A - \mu I)^2 = \delta I (Cayley-Hamilton).

Larger systems

For an nn by nn matrix, eAte^{At} is the inverse Laplace transform of (sI−A)−1(sI - A)^{-1}, because L{eAt}=(sI−A)−1\mathcal{L}\{e^{At}\} = (sI - A)^{-1}. The Faddeev–LeVerrier recursion gives this inverse with exact rational coefficients: with M1=IM_1 = I,

Mk=AMk−1+cn−k+1I,cn−k=−1ktr⁡(AMk),(sI−A)−1=∑k=1nMk s n−kp(s), M_{k} = A M_{k-1} + c_{n-k+1} I, \qquad c_{n-k} = -\tfrac1k \operatorname{tr}(A M_k), \qquad (sI - A)^{-1} = \frac{\sum_{k=1}^{n} M_k\, s^{\,n-k}}{p(s)},

where p(s)=sn+cn−1sn−1+⋯+c0p(s) = s^n + c_{n-1}s^{n-1} + \dots + c_0 is the characteristic polynomial. Each entry is then inverted by partial fractions. This works when pp splits over the rationals into linear factors and quadratics. The result is checked: ddteAt=A eAt\tfrac{d}{dt}e^{At} = A\,e^{At} identically and eA⋅0=Ie^{A\cdot 0} = I, and verified reports it.

const s3 = linearSystem([[0, 1, 0], [0, 0, 1], [-6, -11, -6]]);
s3.characteristic;   // "s^3 + 6*s^2 + 11*s + 6 = 0"
s3.eigenvalues;      // ["-1", "-2", "-3"]
s3.stability;        // "asymptotically stable"
s3.solution([1, 0, 0])[0];   // "3*exp(-t) - 3*exp(-2*t) + exp(-3*t)"
linearSystem([[0, 1, 0], [0, 0, 1], [0, 0, 0]]).exponential[0];   // ["1", "t", "1/2*t^2"]

Stability is read from the real parts of the eigenvalues, whose signs are decided exactly. If every real part is negative, the system is asymptotically stable; if any is positive, it is unstable. Eigenvalues on the imaginary axis give stability that is not asymptotic, if each is semisimple, which is checked exactly by a rank. Otherwise the system is unstable: a repeated zero eigenvalue with a Jordan block makes eAte^{At} grow like a power of tt. For other matrices, use the matrix exponential in the linear algebra package.

Nonlinear systems

An equilibrium of x′=f(x,y), y′=g(x,y)x' = f(x, y),\ y' = g(x, y) is a common zero of ff and gg. equilibria(box) bisects the box, discards pieces where interval arithmetic shows ff or gg has no zero, and applies a Krawczyk test to the rest: when the test succeeds there is exactly one equilibrium in that piece. The returned list has complete: true when every part of the box was either proven empty or proven to hold exactly one equilibrium.

Near an equilibrium the system looks like its linearisation, x′=Jxx' = Jx with JJ the Jacobian matrix there. If no eigenvalue of JJ has zero real part (the equilibrium is hyperbolic), the nonlinear system has the same kind of equilibrium with the same stability (Hartman-Grobman). The trace and determinant of JJ are enclosed over the small box that holds the equilibrium, so a reported saddle, node or spiral is proven. When the linear part is a centre, the nonlinear terms decide, and the record says so.

Two tools settle such cases. conserves(H) checks that Hxf+HygH_x f + H_y g is identically zero: a conserved quantity with a strict extremum at the equilibrium makes it a centre. along(V) gives V˙=Vxf+Vyg\dot V = V_x f + V_y g for a candidate Lyapunov function.

callreturns
linearSystem([[a, b], [c, d]]){ trace, determinant, discriminant, eigenvalues, eigenvectors, kind, stability, exponential, solution(x0) }
linearSystem(A), A n by n{ characteristic, eigenvalues, stability, exponential, verified, solution(x0) }
planarSystem([f, g], [x, y], { params })PlanarSystem
s.jacobian(), s.nullclines()formulas
s.equilibria({ x: [a, b], y: [c, d] })records { point, unique, jacobian, trace, determinant, kind, stability, hyperbolic }, with complete on the list
s.conserves(H), s.along(V)boolean, formula
s.orbit({ from, until })a Refinement like ode.solve
Try itEdit the code and run it with @ratmath/analytic and Core's R, Rational, RationalInterval in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.
Ctrl/⌘ + Enter runs