Linear equations and Laplace transforms
linearODE solves with rational coefficients: the characteristic roots, the solutions of the homogeneous equation, a particular solution by undetermined coefficients or variation of parameters, and the constants from initial values. laplace and inverseLaplace are the transform route to the same answers.
const s = linearODE([1, -3, 2], "exp(x)"); // y'' - 3y' + 2y = e^x
s.characteristic; // "r^2 - 3*r + 2 = 0"
s.roots; // [{ root: "1", … }, { root: "2", … }]
s.basis; // ["exp(x)", "exp(2*x)"]
s.particular; // "-(x*exp(x))" resonance: e^x already solves the homogeneous equation
s.general; // "y = C1*exp(x) + C2*exp(2*x) - x*exp(x)"
const i = s.initial([1, 0]); // y(0) = 1, y'(0) = 0
i.solution; // "y = -(x*exp(x)) + exp(x)"
i.check(1); // against the validated numerical solution
The characteristic equation
Trying in the homogeneous equation gives . Each root contributes solutions:
| root | solutions |
|---|---|
| real , once | |
| real , times | |
| (times powers of if repeated) |
Roots are found exactly: rational roots with their multiplicities, then quadratic factors, whose roots are written with square roots. A polynomial with an irreducible factor of degree three or more has roots that square roots do not reach, and linearODE refuses and points to the numerical solver.
Undetermined coefficients
When is a sum of terms or , a particular solution has the same shape with unknown coefficients. If is a characteristic root times, the trial solution is multiplied by : this is resonance, and it is why has the growing solution .
The coefficients are found without guessing. On the space spanned by and , differentiation is a matrix, so the whole operator is a matrix, and the coefficients solve a linear system with exact rational arithmetic. verified reports that substituting the result back leaves exactly zero.
Variation of parameters
For other right-hand sides of a second-order equation, with homogeneous solutions and Wronskian ,
It is used when the integrals are found; method says which route was taken.
Laplace transforms
The transform turns differentiation into multiplication, , so a linear equation with initial values becomes algebra. The inverse is found by partial fractions.
laplace("t^2*exp(-t)"); // "2/(s + 1)^3"
laplace("t*sin(3*t)"); // "6*s/(s^2 + 9)^2"
laplace("t", { delay: 2 }); // "exp(-2*s)/s^2" for u(t - 2)·(t - 2)
inverseLaplace("1/(s^2*(s + 1))");
// { partialFractions: "-(1/s) + 1/s^2 + 1/(s + 1)", result: "-1 + t + exp(-t)" }
laplace transforms sums of terms and . inverseLaplace inverts rational functions whose denominators split over the rationals into linear factors (to any power) and single quadratic factors. Forcing that switches on at a time, written heaviside(t - c), and impulses, written dirac(t - c), are on the page Steps and impulses, together with laplaceSolve.
| call | returns |
|---|---|
| linearODE(coefficients, forcing = 0, { x, y }) | { characteristic, roots, basis, homogeneous, particular, method, verified, steps, general, initial } |
| s.initial(values, x0 = 0) | { constants, solution, at(x), check(x1) } |
| laplace(f, { t, s, delay }) | a formula in s |
| inverseLaplace(F, { s, t }) | { partialFractions, result } |
| partialFractions(N, D) | { poly, linear, quadratic } for polynomials given as coefficient arrays |
@ratmath/analytic and Core's R, Rational, RationalInterval in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.