Topic

Linear equations and Laplace transforms

linearODE solves any(n)+⋯+a1y′+a0y=g(x)a_n y^{(n)} + \dots + a_1 y' + a_0 y = g(x) 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 y=erxy = e^{rx} in the homogeneous equation gives anrn+⋯+a0=0a_n r^n + \dots + a_0 = 0. Each root contributes solutions:

rootsolutions
real rr, onceerxe^{rx}
real rr, mm timeserx, xerx, …, xm−1erxe^{rx},\ x e^{rx},\ \dots,\ x^{m-1} e^{rx}
α±βi\alpha \pm \beta ieαxcos⁡βx, eαxsin⁡βxe^{\alpha x}\cos\beta x,\ e^{\alpha x}\sin\beta x (times powers of xx 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 gg is a sum of terms xkeaxcos⁡wxx^k e^{ax}\cos wx or xkeaxsin⁡wxx^k e^{ax}\sin wx, a particular solution has the same shape with unknown coefficients. If a+wia + wi is a characteristic root ss times, the trial solution is multiplied by xsx^s: this is resonance, and it is why y′′+4y=cos⁡2xy'' + 4y = \cos 2x has the growing solution 14xsin⁡2x\tfrac14 x \sin 2x.

The coefficients are found without guessing. On the space spanned by xjeaxcos⁡wxx^j e^{ax}\cos wx and xjeaxsin⁡wxx^j e^{ax}\sin wx, 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 y1,y2y_1, y_2 and Wronskian W=y1y2′−y2y1′W = y_1 y_2' - y_2 y_1',

yp=−y1∫y2 ga2W dx+y2∫y1 ga2W dx. y_p = -y_1 \int \frac{y_2\,g}{a_2 W}\,dx + y_2 \int \frac{y_1\,g}{a_2 W}\,dx .

It is used when the integrals are found; method says which route was taken.

Laplace transforms

The transform F(s)=∫0∞e−stf(t) dtF(s) = \int_0^\infty e^{-st} f(t)\,dt turns differentiation into multiplication, L{y′}=sY−y(0)\mathcal{L}\{y'\} = sY - y(0), 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)" }
f(t)f(t)F(s)F(s)
tkeatt^k e^{at}k!/(s−a)k+1k!/(s - a)^{k+1}
eatcos⁡wte^{at}\cos wt(s−a)/((s−a)2+w2)(s - a)/((s - a)^2 + w^2)
eatsin⁡wte^{at}\sin wtw/((s−a)2+w2)w/((s - a)^2 + w^2)
u(t−c) f(t−c)u(t - c)\,f(t - c)e−csF(s)e^{-cs}F(s)

laplace transforms sums of terms tkeatcos⁡wtt^k e^{at}\cos wt and tkeatsin⁡wtt^k e^{at}\sin wt. 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.

callreturns
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
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