---
title: Exact and Bernoulli equations
heading: Two more first-order equations you can solve exactly
eyebrow: A8 · Lesson 5 · Exact and Bernoulli equations
xp: 40
---

::: hook
Separation and integrating factors cover most first-order equations an engineer meets, but two more families come up often enough to know by name. An **exact** equation is the derivative of something that stays constant, the way energy stays constant in a lossless system; its solutions are the level curves of that something. A **Bernoulli** equation has a power of $y$ on the right that makes it nonlinear, but a change of variable turns it linear. The logistic equation is one, and so is a capacitor discharging through a load whose current grows faster than its voltage.
:::

::: play
- The curves solve $\dot y = y - y^3$, a Bernoulli equation, from the starting value you set.
- Every start above zero settles at 1, from above or below. The formula behind the curve came from turning the equation into a linear one.
- Try a start near zero: the solution lingers, then rises. Try a start of 3: it drops quickly, because the $y^3$ term dominates.
:::

```sim plot
view: graph
x: t = 0..5
y: y = 0..3.2
slider: y0 = 0.05..3 step 0.05 = 0.5
plot: 1/sqrt(1 + (1/y0^2 - 1)*exp(-2*t)) | label: y(t)
plot: 1 | dashed | color: ch2 | label: equilibrium
readout: y at time 1 = 1/sqrt(1 + (1/y0^2 - 1)*exp(-2)) | digits: 4
```

::: predict
## Substituting $v = 1/y^2$ into $\dot y = y - y^3$ gives which equation for $v$?

- [x] $\dot v + 2v = 2$, which is linear
- [ ] $\dot v = v - v^3$, unchanged
- [ ] $\dot v = 2v^2$, still nonlinear
- [ ] $\dot v = 0$

::: reveal
$\dot v + 2v = 2$. With $v = y^{-2}$, $\dot v = -2y^{-3}\dot y = -2y^{-3}(y - y^3) = -2y^{-2} + 2 = -2v + 2$. A linear equation with a constant input: $v = 1 + (v_0 - 1)e^{-2t}$, and then $y = 1/\sqrt v$. That's the formula the sim plots.
:::
:::

::: nameit
## Exact equations

An equation written as $M(x, y)\,dx + N(x, y)\,dy = 0$ is **exact** if there's a function $F(x, y)$ with $F_x = M$ and $F_y = N$. Along a solution, $dF = M\,dx + N\,dy = 0$, so the solutions are the level curves $F(x, y) = C$.

**The test:** mixed partial derivatives agree, so an exact equation must have $M_y = N_x$, and in a simply connected region that's also enough.

**Finding $F$:** integrate $M$ with respect to $x$, adding an unknown function $g(y)$; then choose $g$ so that $F_y = N$.

## Bernoulli equations

An equation of the form

$$\dot y + p(t)y = q(t)y^n, \qquad n \ne 0, 1$$

becomes linear with $v = y^{1-n}$: dividing by $y^n$ and using $\dot v = (1 - n)y^{-n}\dot y$ gives

$$\dot v + (1 - n)p(t)v = (1 - n)q(t)$$

Solve that by an integrating factor, then return to $y = v^{1/(1-n)}$.

## Where they appear

- The logistic equation $\dot P = rP - \frac rKP^2$ is Bernoulli with $n = 2$: $v = 1/P$ makes it linear.
- Quadratic drag, $m\dot v = -bv^2 + F$, and a capacitor discharging through a load whose current goes as $v^2$ are Bernoulli or separable.
- Conservative systems give exact equations: for $\ddot x = -f(x)$, energy $\frac12\dot x^2 + \int f\,dx$ is the $F$ whose level curves are the trajectories in the phase plane.
:::

::: example
## Solve $(2xy + 3)\,dx + (x^2 + 4y)\,dy = 0$ through the point $(1, 1)$.

::: solution
1. **Test for exactness.** $M_y = 2x$ and $N_x = 2x$, so it's exact.
2. **Integrate $M$ in $x$.**
   $$F = x^2y + 3x + g(y)$$
3. **Match $F_y$ to $N$.** $F_y = x^2 + g'(y)$ must equal $N = x^2 + 4y$, so $g' = 4y$ and $g = 2y^2$:
   $$F = x^2y + 3x + 2y^2$$
4. **Pass through $(1, 1)$.**
   $$\begin{aligned} F(1, 1) &= 1 + 3 + 2 \\ &= 6 \end{aligned}$$

**Answer:** the solution is the curve $x^2y + 3x + 2y^2 = 6$.
:::
:::

::: example
## Solve $\dot y = y - y^3$ with $y(0) = 0.5$, and find $y(1)$.

::: solution
1. **Substitute.** With $n = 3$, use $v = y^{-2}$. The equation becomes
   $$\dot v + 2v = 2$$
2. **Solve the linear equation.** It starts at $v_0 = 0.5^{-2} = 4$:
   $$\begin{aligned} v &= 1 + (v_0 - 1)e^{-2t} \\ &= 1 + 3e^{-2t} \end{aligned}$$
3. **Go back to $y$.**
   $$y = \frac{1}{\sqrt{1 + 3e^{-2t}}}$$
4. **Evaluate at $t = 1$.**
   $$\begin{aligned} y(1) &= \frac{1}{\sqrt{1 + 3e^{-2}}} \\ &= 0.843 \end{aligned}$$
5. **Long run.** As $t \to \infty$, $v \to 1$ and $y \to 1$, the stable equilibrium.

**Answer:** $y = 1/\sqrt{1 + 3e^{-2t}}$, and $y(1) = 0.843$.
:::
:::

::: example
## Solve the logistic equation $\dot P = 0.5P\left(1 - \frac{P}{1000}\right)$ with $P(0) = 100$ as a Bernoulli equation.

::: solution
1. **Substitute $v = 1/P$.**
   $$\begin{aligned} \dot v &= -\dot P/P^2 \\ &= -0.5v + 0.0005 \end{aligned}$$
   which is linear, with equilibrium $v = 0.001$.
2. **Solve for $v$.**
   $$v = 0.001 + (0.01 - 0.001)e^{-0.5t}$$
3. **Go back to $P$.**
   $$P = \frac{1}{0.001 + 0.009e^{-0.5t}}$$
4. **Evaluate at $t = 4$.**
   $$\begin{aligned} P(4) &= \frac{1}{0.001 + 0.009e^{-2}} \\ &= 451 \end{aligned}$$
   This is the same answer separation gives in A6, found here without partial fractions.

**Answer:** $P = 1/(0.001 + 0.009e^{-0.5t})$, which gives $P(4) = 451$.
:::
:::

::: check
given: k = 1 | 2 | 3
answer: 2*k
tolerance: 0.5%

## For which $a$ is $(axy + 1)\,dx + (\given{k}x^2 + y)\,dy = 0$ exact?

::: right
Right. $M_y = ax$ must equal $N_x = 2kx$, so $a = 2k$ = {answer}.
:::

::: misses
- [k] Differentiate $kx^2$ with respect to $x$: $2kx$.
- [any] Not yet. Exact means $M_y = N_x$.
:::
:::

::: check
given: x = 1 | 2; y = 1 | 3
answer: x^2*y + 3*x + 2*y^2
tolerance: 0.5%

## The solutions of $(2xy + 3)\,dx + (x^2 + 4y)\,dy = 0$ are the curves $F = C$. What is $C$ for the curve through $(\given{x}, \given{y})$?

::: right
Right. $F = x^2y + 3x + 2y^2$ = {answer} there.
:::

::: misses
- [x^2*y + 3*x] Include $g(y) = 2y^2$, which comes from the $4y$ in $N$.
- [any] Not yet. $F = x^2y + 3x + 2y^2$.
:::
:::

::: check
given: n = 2 | 3 | 4
answer: 1 - n
tolerance: 0.5%

## A Bernoulli equation has $y^{\given{n}}$ on the right. What power $m$ in $v = y^m$ makes it linear?

::: right
Right. $v = y^{1-n}$, so $m$ = {answer}.
:::

::: misses
- [n - 1] Check the sign: the exponent is $1 - n$.
- [any] Not yet. Divide by $y^n$ and look for a derivative.
:::
:::

::: check
given: y0 = 0.5 | 2; t = 0.5 | 1
answer: 1/sqrt(1 + (1/y0^2 - 1)*exp(-2*t))
tolerance: 0.5%

## Solve $\dot y = y - y^3$ with $y(0)$ = {y0}. What is $y$ at $t$ = {t}?

::: right
Right. $y = \frac{1}{\sqrt{1 + (y_0^{-2} - 1)e^{-2t}}}$ = {answer}.
:::

::: misses
- [any] Not yet. With $v = y^{-2}$, $v = 1 + (v_0 - 1)e^{-2t}$.
:::
:::

::: check
kind: parts
given: r = 0.5 | 1; K = 100 | 1000; P0 = 10 | 50

## Solve $\dot P = \given{r}P\left(1 - \frac{P}{\given{K}}\right)$ with $P(0)$ = {P0}, using $v = 1/P$.

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

### What value does $v$ settle to?

::: misses
- [K] That's $P$'s final value; $v = 1/P$.
- [any] Set $\dot v = 0$ in $\dot v = -rv + r/K$.
:::
:::

::: part
answer: 1/(1/K + (1/P0 - 1/K)*exp(-2*r))
tolerance: 0.5%

### What is $P$ at $t = 2$?

::: misses
- [any] $v = \frac1K + \left(\frac{1}{P_0} - \frac1K\right)e^{-rt}$.
:::
:::
:::

::: check
kind: derivation
vars: p = 0.5..3, q = 0.5..3, t = 0..3, v0 = 0.5..3

## Turn $\dot y + py = qy^2$ into a linear equation with $v = 1/y$.

::: step
answer: p

### $\dot v = -\dot y/y^2 = p/y - q$. The equation is $\dot v = av - q$. What is $a$?
:::

::: step
answer: q/p + (v0 - q/p)*exp(p*t)

### Solve it from $v(0) = v_0$. What is $v(t)$?
:::

::: right
Right. The linear equation in $v$ has the solution $\frac qp + \left(v_0 - \frac qp\right)e^{pt}$; then $y = 1/v$.
:::
:::

::: explain
## Why does the substitution $v = y^{1-n}$ turn a Bernoulli equation into a linear one?

::: model
Dividing $\dot y + py = qy^n$ by $y^n$ gives $y^{-n}\dot y + py^{1-n} = q$. The second term is already $p$ times $y^{1-n}$, and the first term is almost the derivative of $y^{1-n}$: the chain rule gives $\frac{d}{dt}y^{1-n} = (1 - n)y^{-n}\dot y$. So with $v = y^{1-n}$, the equation reads $\frac{\dot v}{1 - n} + pv = q$, which has no powers of $v$ at all. The nonlinearity was a single power of $y$, and the right power of $y$ as the new unknown absorbs it. That only works for this one form; a sum of two different powers of $y$ can't be removed this way.
:::
:::

::: practice

::: check
given: k = 0.5..5
answer: 2*k
tolerance: 0.5%

## Exactness of $(axy + 1)dx + (\given{k}x^2 + y)dy = 0$: which $a$?

::: misses
- [any] $a = 2k$.
:::
:::

::: check
given: y0 = 0.1..3; t = 0..3
answer: 1/sqrt(1 + (1/y0^2 - 1)*exp(-2*t))
tolerance: 0.5%

## $y(t)$ for $\dot y = y - y^3$ from {y0}, at $t$ = {t}?

::: misses
- [any] $\left(1 + (y_0^{-2} - 1)e^{-2t}\right)^{-1/2}$.
:::
:::
:::
