Systems in the plane
linearSystem solves exactly: for a 2 by 2 matrix it names the kind of equilibrium, and for larger matrices it gives 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 and , the eigenvalues are , and the origin is
| condition | kind |
|---|---|
| saddle: real eigenvalues of opposite signs | |
| node: stable if , unstable if | |
| spiral: stable if , unstable if | |
| centre: closed orbits | |
| degenerate node, or a star when is a multiple of the identity | |
| a line of equilibria |
The entries are rational, so the signs of , and are decided exactly and the borderline cases are recognised for what they are.
The solution is . For a 2 by 2 matrix, with and ,
which follows from (Cayley-Hamilton).
Larger systems
For an by matrix, is the inverse Laplace transform of , because . The Faddeev–LeVerrier recursion gives this inverse with exact rational coefficients: with ,
where is the characteristic polynomial. Each entry is then inverted by partial fractions. This works when splits over the rationals into linear factors and quadratics. The result is checked: identically and , 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 grow like a power of . For other matrices, use the matrix exponential in the linear algebra package.
Nonlinear systems
An equilibrium of is a common zero of and . equilibria(box) bisects the box, discards pieces where interval arithmetic shows or 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, with the Jacobian matrix there. If no eigenvalue of 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 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 is identically zero: a conserved quantity with a strict extremum at the equilibrium makes it a centre. along(V) gives for a candidate Lyapunov function.
| call | returns |
|---|---|
| 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 |
@ratmath/analytic and Core's R, Rational, RationalInterval in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.