---
title: Linear equations and integrating factors
heading: Solving any first-order linear equation
eyebrow: A8 · Lesson 4 · Integrating factors
xp: 40
---

::: hook
Feed a ramp into an RC low-pass filter, a voltage climbing steadily at 5 V per millisecond, and the output climbs at the same rate but stays a fixed distance behind, lagging by exactly one time constant. That lag is the tracking error of every first-order system following a steadily changing input: a thermostat chasing a rising setpoint, a sensor following a warming room. To find it, you need to solve $\tau\dot v + v = kt$, which isn't separable. Every first-order **linear** equation, whatever its input, yields to one trick: multiply by the right factor and the left side becomes a single derivative.
:::

::: play
- The straight line is the input ramp, rising at $k$ volts per millisecond. The curve is the RC filter's output, starting from zero.
- After a few time constants the output runs parallel to the input. How far behind is it, in time and in volts?
- Change $\tau$ and $k$ and watch the gap.
:::
:::

```sim plot
view: graph
x: t = 0..10 ms
y: v = 0..30 V
slider: tau = 0.2..3 step 0.1 = 1 ms
slider: k = 1..5 step 0.5 = 2.5
plot: k*t | label: input ramp
plot: k*(t - tau + tau*exp(-t/tau)) | label: output | color: ch2
readout: lag in time = tau ms | digits: 3
readout: gap in volts = k*tau V | digits: 3
```

::: predict
## An RC filter with $\tau$ = 1 ms follows a ramp rising at 5 V/ms. Once settled, how far below the input is the output?

- [ ] 0 V: it catches up eventually
- [x] 5 V: one time constant's worth of rise
- [ ] 2.5 V
- [ ] It falls further and further behind

::: reveal
5 V. The solution is $v = k(t - \tau) + k\tau e^{-t/\tau}$; once the exponential dies, the output is the input delayed by $\tau$, which on a ramp of 5 V/ms is a gap of $5 \times 1 = 5$ V. It never catches up, and never falls further behind.
:::
:::

::: nameit
## Standard form

A first-order **linear** equation can be written

$$\frac{dy}{dt} + p(t)\,y = q(t)$$

$y$ and $\dot y$ appear only to the first power, with no products. The RC circuit is one: $\dot v + \frac{1}{\tau}v = \frac{1}{\tau}v_\text{in}(t)$.

## The integrating factor

Multiply through by $\mu(t) = e^{\int p\,dt}$. Since $\dot\mu = p\mu$, the left side becomes $\mu\dot y + p\mu y = (\mu y)'$, by the product rule. So

$$(\mu y)' = \mu q \qquad y = \frac{1}{\mu}\left(\int\mu q\,dt + C\right)$$

For constant $p = a$, $\mu = e^{at}$.

## What the answer looks like

For constant $p = a > 0$ the solution is always

$$y = \underbrace{Ce^{-at}}_{\text{natural response}} + \underbrace{y_p(t)}_{\text{forced response}}$$

The natural response is the same decaying exponential whatever the input; the forced response follows the input. That split, which lesson 14 used for steps and sines, holds for every input.

## Tracking a ramp

For $\tau\dot v + v = kt$ with $v(0) = 0$:

$$v(t) = k(t - \tau) + k\tau e^{-t/\tau}$$

After the transient, the output equals the input delayed by $\tau$: a gap of $k\tau$.
:::

::: example
## Solve $\tau\dot v + v = kt$ with $v(0) = 0$.

::: solution
1. **Standard form.**
   $$\dot v + \frac{v}{\tau} = \frac{kt}{\tau}$$
   so the integrating factor is $\mu = e^{t/\tau}$.
2. **Multiply through.**
   $$(e^{t/\tau}v)' = \frac{k}{\tau}te^{t/\tau}$$
3. **Integrate by parts.**
   $$\begin{aligned} &\int\frac{k}{\tau}te^{t/\tau}dt \\ &= k(t - \tau)e^{t/\tau} + C \end{aligned}$$
4. **Divide by the factor.**
   $$v = k(t - \tau) + Ce^{-t/\tau}$$
5. **Fit the start.** $v(0) = 0$ gives $C = k\tau$.

**Answer:** $v = k(t - \tau) + k\tau e^{-t/\tau}$.
:::
:::

::: example
## Solve $\dot y + 2y = e^{-t}$ with $y(0) = 0$.

::: solution
1. **Integrating factor.** $\mu = e^{2t}$, so
   $$(e^{2t}y)' = e^{t}$$
2. **Integrate.**
   $$e^{2t}y = e^t + C$$
3. **Fit the start.** With $y(0) = 0$, $C = -1$:
   $$y = e^{-t} - e^{-2t}$$
4. **Its shape.** It rises from zero, peaks at $t = \ln 2$, and decays at the input's slower rate.

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

::: example
## Solve $\dot y + \frac{y}{t} = 1$ for $t > 0$ with $y(1) = 0$.

::: solution
1. **Integrating factor.** The coefficient $p(t) = \frac1t$ varies, so
   $$\begin{aligned} \mu &= e^{\int dt/t} \\ &= t \end{aligned}$$
2. **Multiply through and integrate.** The left side becomes $(ty)'$:
   $$\begin{aligned} (ty)' &= t \\ ty &= \frac{t^2}{2} + C \end{aligned}$$
3. **Fit the start.** $y(1) = 0$ gives $C = -\frac12$:
   $$y = \frac t2 - \frac{1}{2t}$$
4. **Evaluate at $t = 2$.**
   $$\begin{aligned} y(2) &= 1 - 0.25 \\ &= 0.75 \end{aligned}$$
5. **Large $t$.** For large $t$ the solution approaches $t/2$, the particular part, and the $\frac{1}{2t}$ term fades.

**Answer:** $y = \frac t2 - \frac{1}{2t}$, so $y(2) = 0.75$.
:::
:::

::: check
given: k = 2 | 5; tau = 0.5 | 2
answer: k*tau
unit: V
tolerance: 0.5%

## An RC filter with $\tau$ = {tau} ms follows a ramp of {k} V/ms. Once settled, how far below the input is the output?

::: right
Right. The output lags by $\tau$, a gap of $k\tau$ = {answer}.
:::

::: misses
- [k] The lag is one time constant, $\tau$ = {tau} ms, so multiply by it.
- [0] A first-order filter never catches a ramp.
- [any] Not yet. The output is the input delayed by $\tau$.
:::
:::

::: check
given: k = 2 | 4; tau = 1 | 2; t = 1 | 3
answer: k*(t - tau + tau*exp(-t/tau))
unit: V
tolerance: 0.5%

## A ramp of {k} V/ms drives an RC filter with $\tau$ = {tau} ms, starting from 0 V. What is the output at $t$ = {t} ms?

::: right
Right. $k(t - \tau + \tau e^{-t/\tau})$ = {answer}.
:::

::: misses
- [k*(t - tau)] Include the transient term, $k\tau e^{-t/\tau}$, which hasn't died yet.
- [k*t] That's the input.
- [any] Not yet. $v = k(t - \tau) + k\tau e^{-t/\tau}$.
:::
:::

::: check
given: a = 2 | 5; b = 4 | 10; t = 0.2 | 0.5
answer: b/a*(1 - exp(-a*t))
tolerance: 0.5%

## Solve $\dot y + \given{a}y = \given{b}$ with $y(0) = 0$. What is $y(\given{t})$?

::: right
Right. $y = \frac{b}{a}(1 - e^{-at})$ = {answer}.
:::

::: misses
- [b*(1 - exp(-a*t))] The final value is $b/a$, where $\dot y = 0$.
- [b/a] That's the final value; at $t$ = {t} it isn't there yet.
- [any] Not yet. $\mu = e^{at}$.
:::
:::

::: check
given: a = 4 | 5; c = 1 | 2; t = 0.5 | 1
answer: (exp(-c*t) - exp(-a*t))/(a - c)
tolerance: 0.5%

## Solve $\dot y + \given{a}y = e^{-\given{c}t}$ with $y(0) = 0$. What is $y(\given{t})$?

::: right
Right. $(e^{at}y)' = e^{(a - c)t}$ gives $y = \frac{e^{-ct} - e^{-at}}{a - c}$ = {answer}.
:::

::: misses
- [exp(-c*t) - exp(-a*t)] Divide by $a - c$ from the integral.
- [any] Not yet. Multiply by $e^{at}$ and integrate.
:::
:::

::: check
kind: choice

## What is the integrating factor for $\dot y + \dfrac{2}{t}y = t$ (for $t > 0$)?

- [x] $t^2$
- [ ] $e^{2t}$
- [ ] $2\ln t$
- [ ] $\frac{1}{t^2}$

::: right
Right. $e^{\int 2/t\,dt} = e^{2\ln t} = t^2$.
:::

::: misses
- [2] That would be for $p = 2$, a constant.
- [3] That's $\int p\,dt$; the factor is $e$ raised to it.
- [4] The sign: $e^{+2\ln t}$.
- [any] $\mu = e^{\int p\,dt}$.
:::
:::

::: check
given: t = 2 | 3 | 5
answer: (t^2 - 1)/(2*t)
tolerance: 0.5%

## Solve $\dot y + \dfrac{y}{t} = 1$ with $y(1) = 0$ ($t > 0$). What is $y(\given{t})$?

::: right
Right. $\mu = t$, so $(ty)' = t$ and $ty = \frac{t^2 - 1}{2}$: $y$ = {answer}.
:::

::: misses
- [t/2] Use $y(1) = 0$ to find the constant.
- [any] Not yet. $\mu = e^{\int dt/t} = t$.
:::
:::

::: check
kind: parts
given: k = 2 | 3 | 4; t = 1 | 2

## Solve $\dot y + \given{k}y = 1$ with $y(0) = 0$.

::: part
answer: (1 - exp(-k*t))/k
tolerance: 0.5%

### What is $y$ at $t$ = {t}?

::: misses
- [1 - exp(-k*t)] The final value is $1/k$.
- [any] $\mu = e^{kt}$: $(e^{kt}y)' = e^{kt}$.
:::
:::

::: part
answer: 1/k
tolerance: 0.5%

### What does $y$ approach?

::: misses
- [any] Set $\dot y = 0$.
:::
:::
:::

::: check
kind: derivation
vars: t = 0.5..4

## Solve $\dot y + \frac yt = 1$ with $y(1) = 0$, using $\mu = t$.

::: step
answer: t^2/2 - 1/2

### $(ty)' = t$. What is $ty$?
:::

::: step
answer: t/2 - 1/(2*t)

### What is $y$?
:::

::: right
Right. $y = \frac t2 - \frac{1}{2t}$.
:::
:::

::: explain
## Why does multiplying by $\mu = e^{\int p\,dt}$ make the equation solvable?

::: model
The product rule says $(\mu y)' = \mu\dot y + \dot\mu y$. Choosing $\mu$ with $\dot\mu = p\mu$, which is exactly what $e^{\int p\,dt}$ satisfies, makes $\mu\dot y + p\mu y$ equal to $(\mu y)'$. So after multiplying, the whole left side is the derivative of a single function, and integrating both sides gives $\mu y$ directly. All the difficulty moves into one ordinary integral, $\int\mu q\,dt$.
:::
:::

::: practice

::: check
given: a = 2 | 10; b = 6 | 30
answer: b/a
tolerance: 0.5%

## What does the solution of $\dot y + \given{a}y = \given{b}$ settle to?

::: misses
- [b] Set $\dot y = 0$: $ay = b$.
- [any] The equilibrium $b/a$.
:::
:::

::: check
given: tau = 2 | 5; k = 1 | 3; t = 20 | 50
answer: k*(t - tau)
unit: V
tolerance: 0.5%

## A ramp of {k} V/s drives a filter with $\tau$ = {tau} s. Long after the start, at $t$ = {t} s, what is the output?

::: misses
- [k*t] That's the input; the output lags by $\tau$.
- [any] $k(t - \tau)$ once the transient is gone.
:::
:::

::: check
given: a = 2..9 int
answer: ln(a)/(a - 1)
tolerance: 0.5%

## For $y = e^{-t} - e^{-\given{a}t}$, at what time is $y$ largest?

::: misses
- [any] Set $\dot y = -e^{-t} + ae^{-at} = 0$.
:::
:::
:::
