Steps and impulses
Forces that switch on at a time, or strike at an instant, are where the Laplace transform is at its best. A factor heaviside(t - c) switches a term on at time . dirac(t - c) is a unit impulse at . laplaceSolve solves a linear equation with such forcing by transform, and then proves the answer piece by piece.
laplace("heaviside(t - 2)"); // "exp(-2*s)/s"
laplace("heaviside(t - 1)*t"); // "exp(-s)*(1/s + 1/s^2)"
laplace("heaviside(t - 1)*sin(t)"); // "exp(-s)*(sin(1)*(s/(s^2 + 1)) + cos(1)*(1/(s^2 + 1)))"
laplace("t*dirac(t - 2)"); // "exp(-2*s)*2"
inverseLaplace("exp(-2*s)/s^2").result; // "heaviside(t - 2)*(t - 2)"
inverseLaplace("exp(-3*s)").result; // "dirac(t - 3)"
const r = laplaceSolve([1, 0, 1], "heaviside(t - 1)", [0, 0]); // y'' + y = u(t − 1), at rest
r.solution; // "heaviside(t - 1)*(-cos(t - 1) + 1)"
r.pieces; // [{ from: "0", y: "0" }, { from: "1", y: "-cos(t - 1) + 1" }]
r.verified; // true
The shift theorems
Write for the unit step that is 0 before and 1 after, with . Then
For the first, substitute in . For a term , the shifted is expanded exactly: by the binomial theorem, and by the addition formula. That leaves constants such as , and , which stay as exact formulas. The second is the defining property of the impulse: .
Going back, inverseLaplace groups the terms of by their factor , inverts each group by partial fractions, and shifts: . A constant left over after the partial fractions is an impulse: . A polynomial of higher degree would need derivatives of the impulse, and is refused.
Solving with switched forcing
For with given, transforming gives
and is inverted group by group. steps records each stage.
const kick = laplaceSolve([1, 2, 5], "dirac(t - 2)", [1, 0]); // a damped spring, struck at t = 2
kick.solution;
// "cos(2*t)*exp(-t) + 1/2*sin(2*t)*exp(-t) + heaviside(t - 2)*(1/2*sin(2*t - 4)*exp(-t + 2))"
const pulse = laplaceSolve([1, 3, 2], "heaviside(t - 1) - heaviside(t - 3)", [0, 0]); // on from 1 to 3
pulse.pieces.map((p) => p.from); // ["0", "1", "3"]
Why the answer is proved, not just computed
Between switching times the forcing is an ordinary formula, and so is the solution. laplaceSolve checks, by exact symbolic differentiation:
- On each interval, the piece satisfies the equation identically.
- The first piece has the given initial values.
- At each switching time , the pieces join with continuous. At an impulse , jumps by exactly ; everywhere else it is continuous too.
That is exactly the meaning of a solution with step and impulse forcing. The uniqueness theorem for linear equations then says it is the solution, so verified: true is a proof.
| call | returns |
|---|---|
| laplace(f, { t, s, delay }) | a formula in s; f may contain heaviside(t - c) factors and dirac(t - c) |
| inverseLaplace(F, { s, t }) | { partialFractions, result } for sums of times rational functions |
| laplaceSolve(coefficients, forcing, initial, { t, s }) | { transform, partialFractions, solution, pieces, verified, steps, at(time) } |
heaviside and dirac are understood by these transform tools only. To evaluate or plot a switched solution, take its pieces.
@ratmath/analytic and Core's R, Rational, RationalInterval in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.