---
title: Laplace transforms for initial-value problems
heading: Turning a differential equation and its starting values into algebra
eyebrow: A8 · Lesson 32 · Laplace transforms
xp: 40
---

::: hook
Phasors turned a driven equation into algebra, but only for the steady state, and only for sinusoids. The **Laplace transform** does the same for the whole response, transient included, for steps, ramps, exponentials and switched inputs alike. Derivatives become multiplication by $s$, and the initial conditions enter the algebra by themselves, so there's no separate step of fitting constants. It's how circuit textbooks solve switching problems and how control engineers think about every system.
:::

::: play
- The curve solves $\ddot y + 3\dot y + 2y = 0$ for the initial position and velocity you set.
- In the Laplace domain this is $Y(s) = \frac{(s + 3)y_0 + v_0}{(s + 1)(s + 2)}$, and partial fractions give the two exponentials.
- Set $v_0 = -2y_0$: the slow mode's coefficient $2y_0 + v_0$ vanishes and only $e^{-2t}$ is left, so the curve falls faster.
:::

```sim plot
view: graph
x: t = 0..6
y: y = -1.5..2
slider: y0 = -1..1.5 step 0.1 = 1
slider: v0 = -3..3 step 0.1 = 0
plot: (2*y0 + v0)*exp(-t) - (y0 + v0)*exp(-2*t) | label: y(t)
readout: coefficient of e^(−t) = 2*y0 + v0 | digits: 3
readout: coefficient of e^(−2t) = -(y0 + v0) | digits: 3
```

::: predict
## The transform of $\dot y$ is $sY(s) - y(0)$. What happens to the initial condition when you transform $\dot y + 2y = 0$ with $y(0) = 3$?

- [x] It appears on the right side: $(s + 2)Y = 3$, so $Y = \frac{3}{s + 2}$
- [ ] It's lost, and must be fitted at the end
- [ ] It multiplies $s$
- [ ] It makes the transform undefined

::: reveal
It appears on the right: $sY - 3 + 2Y = 0$, so $Y = \frac{3}{s + 2}$ and $y = 3e^{-2t}$. The initial condition behaves like an input, a charge already on the capacitor acting like a source, which is how the Laplace method handles it automatically.
:::
:::

::: nameit
## The transform

$$\mathcal{L}\{f\} = F(s) = \int_0^\infty f(t)e^{-st}\,dt$$

The integral converges for $s$ large enough, which is all the method needs. A short table covers most engineering problems:

| $f(t)$ | $F(s)$ |
|---|---|
| 1 (a step) | $\frac1s$ |
| $t^n$ | $\frac{n!}{s^{n+1}}$ |
| $e^{at}$ | $\frac{1}{s - a}$ |
| $\cos\omega t$ | $\frac{s}{s^2 + \omega^2}$ |
| $\sin\omega t$ | $\frac{\omega}{s^2 + \omega^2}$ |
| $e^{at}f(t)$ | $F(s - a)$ |

## Derivatives

Integrating by parts gives the rule that makes the method work:

$$\mathcal{L}\{\dot y\} = sY - y(0), \qquad \mathcal{L}\{\ddot y\} = s^2Y - sy(0) - \dot y(0)$$

## The method

1. Transform the equation, initial conditions included.
2. Solve the algebra for $Y(s)$.
3. Break $Y(s)$ into partial fractions, each one in the table.
4. Read off $y(t)$ term by term.

The denominator's roots are the system's characteristic roots: they set the natural response, and the input's own poles set the forced one.

## Final value theorem

If $y(t)$ settles, its final value is $\lim_{s\to0}sY(s)$: you can find where a system ends up without inverting anything. It doesn't apply if $sY(s)$ has a pole on or to the right of the imaginary axis, since then $y$ doesn't settle.
:::

::: example
## Solve $\dot y + 2y = 4$ with $y(0) = 1$.

::: solution
1. **Transform.**
   $$sY - 1 + 2Y = \frac4s$$
2. **Solve for $Y$ and split it.** Use partial fractions (multiply by $s$ and set $s = 0$ for the first coefficient; multiply by $s + 2$ and set $s = -2$ for the second):
   $$\begin{aligned} Y &= \frac{s + 4}{s(s + 2)} \\ &= \frac2s - \frac{1}{s + 2} \end{aligned}$$
3. **Invert.**
   $$y = 2 - e^{-2t}$$
   It starts at 1 and rises to 2.

**Answer:** $y = 2 - e^{-2t}$, rising from 1 to 2.
:::
:::

::: example
## Solve $\ddot y + 3\dot y + 2y = 0$ with $y(0) = 1$, $\dot y(0) = 0$.

::: solution
1. **Transform.**
   $$s^2Y - s + 3(sY - 1) + 2Y = 0$$
   so $(s^2 + 3s + 2)Y = s + 3$.
2. **Partial fractions.**
   $$\begin{aligned} Y &= \frac{s + 3}{(s + 1)(s + 2)} \\ &= \frac{2}{s + 1} - \frac{1}{s + 2} \end{aligned}$$
3. **Invert.**
   $$y = 2e^{-t} - e^{-2t}$$
4. **Check.** $y(0) = 1$ and $\dot y(0) = -2 + 2 = 0$. The initial conditions were never fitted; they came in with the transform.

**Answer:** $y = 2e^{-t} - e^{-2t}$.
:::
:::

::: example
## Solve $\ddot y + 3\dot y + 2y = 4$ from rest, and find $y(1)$ and the final value.

::: solution
1. **Transform.** From rest,
   $$(s^2 + 3s + 2)Y = \frac4s$$
2. **Partial fractions.**
   $$\begin{aligned} Y &= \frac{4}{s(s + 1)(s + 2)} \\ &= \frac2s - \frac{4}{s + 1} + \frac{2}{s + 2} \end{aligned}$$
3. **Invert.**
   $$y = 2 - 4e^{-t} + 2e^{-2t}$$
4. **Evaluate at $t = 1$.**
   $$\begin{aligned} y(1) &= 2 - 1.472 + 0.271 \\ &= 0.799 \end{aligned}$$
5. **Final value.** The final value theorem gives it directly, matching the constant term:
   $$\begin{aligned} \lim_{s\to0}sY &= \frac{4}{2} \\ &= 2 \end{aligned}$$

**Answer:** $y = 2 - 4e^{-t} + 2e^{-2t}$, with $y(1) = 0.799$ and a final value of 2.
:::
:::

::: check
given: a = 1 | 2 | 5; s = 3 | 6
answer: 1/(s + a)
tolerance: 0.5%

## What is $\mathcal{L}\{e^{-\given{a}t}\}$ at $s$ = {s}?

::: right
Right. $\frac{1}{s + a}$ = {answer}.
:::

::: misses
- [1/(s - a)] The exponent is $-a$, so the pole is at $s = -a$.
- [any] Not yet. $\mathcal{L}\{e^{at}\} = \frac{1}{s - a}$.
:::
:::

::: check
given: w = 2 | 5; s = 1 | 3
answer: w/(s^2 + w^2)
tolerance: 0.5%

## What is $\mathcal{L}\{\sin \given{w}t\}$ at $s$ = {s}?

::: right
Right. $\frac{\omega}{s^2 + \omega^2}$ = {answer}.
:::

::: misses
- [s/(s^2 + w^2)] That's the cosine.
- [any] Not yet. Check the table.
:::
:::

::: check
given: k = 2 | 3 | 5; y0 = 1 | 4; c = 6 | 10
answer: c/k
tolerance: 0.5%

## $\dot y + \given{k}y = \given{c}$ with $y(0)$ = {y0}. What does the final value theorem give?

::: right
Right. $sY = \frac{sy_0 + c}{s + k} \to \frac ck$ = {answer} as $s \to 0$.
:::

::: misses
- [y0] The initial value doesn't affect where it settles.
- [c] Divide by $k$.
- [any] Not yet. Solve for $Y$, multiply by $s$ and let $s \to 0$.
:::
:::

::: check
given: a = 1 | 2; b = 3 | 4
answer: 1/(b - a)
tolerance: 0.5%

## Write $\frac{1}{(s + \given{a})(s + \given{b})} = \frac{A}{s + \given{a}} + \frac{B}{s + \given{b}}$. What is $A$?

::: right
Right. Multiply by $s + a$ and set $s = -a$: $A = \frac{1}{b - a}$ = {answer}.
:::

::: misses
- [1/(a - b)] That's $B$.
- [any] Not yet. Cover up $s + a$ and evaluate the rest at $s = -a$.
:::
:::

::: check
kind: parts
given: y0 = 1 | 2; v0 = 0 | 3

## Transform $\ddot y + 3\dot y + 2y = 0$ with $y(0)$ = {y0} and $\dot y(0)$ = {v0}.

::: part
answer: 2*y0 + v0
tolerance: 0.5%

### What is the coefficient of $e^{-t}$ in $y$?

::: misses
- [any] $Y = \frac{(s + 3)y_0 + v_0}{(s + 1)(s + 2)}$; cover up $s + 1$ and set $s = -1$.
:::
:::

::: part
answer: -(y0 + v0)
tolerance: 0.5%

### And of $e^{-2t}$?

::: misses
- [y0 + v0] Check the sign at $s = -2$: $\frac{(1)y_0 + v_0}{-1}$.
- [any] Cover up $s + 2$ and set $s = -2$.
:::
:::
:::

::: check
kind: derivation
vars: a = 0.5..4, t = 0..3

## Solve $\dot y + ay = 1$ from $y(0) = 0$ with the Laplace transform.

::: step
answer: 1/a

### $Y = \frac{1}{s(s + a)} = \frac{A}{s} + \frac{B}{s + a}$. What is $A$?
:::

::: step
answer: (1 - exp(-a*t))/a

### What is $y(t)$?
:::

::: right
Right. $\frac1a - \frac1ae^{-at}$: the step response of a first-order system, without an integrating factor.
:::
:::

::: check
kind: python

## Invert $Y(s) = \frac{s + 3}{(s + 1)(s + 2)(s + 4)}$ by residues: find the roots of the denominator with `np.roots`, compute each residue $\frac{N(p)}{D'(p)}$, and set `res` to the residues (in the order of the roots $-1, -2, -4$) and `y1` to $y(1)$.

```python starter
import numpy as np

res = [0, 0, 0]
y1 = 0.0
print(res, y1)
```

```python solution
import numpy as np

N = [1, 3]
D = np.polymul(np.polymul([1, 1], [1, 2]), [1, 4])
dD = np.polyder(D)
roots = sorted(np.roots(D).real, reverse=True)
res = [np.polyval(N, p) / np.polyval(dD, p) for p in roots]
y1 = sum(r * np.exp(p) for r, p in zip(res, roots))
print(res, y1)
```

```python tests
import math
import numpy as np
assert np.allclose(res, [2 / 3, -1 / 2, -1 / 6]), f"The residues are 2/3, -1/2 and -1/6; got {res}."
assert abs(y1 - (2 / 3 * math.exp(-1) - 0.5 * math.exp(-2) - math.exp(-4) / 6)) < 1e-12, f"y(1) = 0.17453; got {y1}."
assert abs(sum(res)) < 1e-12, "The residues sum to y(0) = 0, as the initial value theorem says."
```

::: right
Right. Three residues give the whole time response; their sum is $y(0)$, a quick check on the arithmetic.
:::
:::

::: explain
## Why does the Laplace transform turn differentiation into multiplication by $s$?

::: model
The transform weights $f(t)$ by $e^{-st}$, and $e^{-st}$ is itself an eigenfunction of differentiation: $\frac{d}{dt}e^{-st} = -se^{-st}$. Integrating $\dot y\,e^{-st}$ by parts moves the derivative onto the exponential, which brings out a factor $s$, leaving $s$ times the transform of $y$, plus a boundary term at $t = 0$, which is $-y(0)$. So differentiating in time becomes multiplying by $s$ in the transform, and the initial value comes along as that boundary term. A linear equation with constant coefficients becomes a polynomial in $s$ multiplying $Y$, and solving it is algebra.
:::
:::

::: practice

::: check
given: a = 0.1..10; s = 0.5..10
answer: 1/(s + a)
tolerance: 0.5%

## $\mathcal{L}\{e^{-\given{a}t}\}$ at $s$ = {s}?

::: misses
- [any] $\frac{1}{s + a}$.
:::
:::

::: check
given: k = 0.5..10; c = 1..20
answer: c/k
tolerance: 0.5%

## Final value of $\dot y + \given{k}y = \given{c}$?

::: misses
- [any] $c/k$.
:::
:::
:::
