Practice / Calculus

Separable differential equations: growth, decay, cooling and the logistic curve

Ten separable differential equations: exponential growth with a negative start, y′ = x/y, a solution that blows up in finite time, the equation whose solution is softplus, half-life, Newton's law of cooling, the sigmoid as the solution of y′ = y(1 − y), gradient flow on a quadratic loss, a constant solution lost by dividing, and a draining tank, with worked solutions and the mistakes of adding the constant too late, splitting a square root and forgetting where a solution stops.

Before you start

A differential equation describes how a quantity changes, and solving it recovers the quantity itself. When the rate factors into a function of xx times a function of yy, the variables can be separated and each side integrated on its own. The sigmoid, softplus and the exponential decay of gradient flow on a quadratic loss all come out of equations like this. The work goes wrong in a few places: the constant of integration added after exponentiating instead of before, x2+9\sqrt{x^2 + 9} split into x+3x + 3, a constant solution thrown away by dividing by zero, the shift in Newton's law of cooling forgotten, and a formula used past the point where the solution stops. These ten problems cover each of them.

  • Separable. dydx=g(x) h(y)\dfrac{dy}{dx} = g(x)\,h(y). Divide by h(y)h(y), multiply by dxdx, and integrate both sides: ∫dyh(y)=∫g(x) dx+C\displaystyle\int \frac{dy}{h(y)} = \int g(x)\,dx + C. One constant is enough, and it goes in before you solve for yy.
  • Constant solutions. If h(y0)=0h(y_0) = 0, then y≡y0y \equiv y_0 is a solution. Dividing by h(y)h(y) assumes h(y)≠0h(y) \ne 0, so check these separately.
  • Exponential growth and decay. y′=kyy' = ky has solutions y=y(0)ekxy = y(0)e^{kx}. From ln⁡∣y∣=kx+c\ln\lvert y\rvert = kx + c you get y=Aekxy = Ae^{kx} with A=±ecA = \pm e^c, and A=0A = 0 is the constant solution, so AA can be any real number.
  • Initial condition. Use y(x0)=y0y(x_0) = y_0 to find CC. Then check that the answer satisfies the equation.
  • Interval of validity. A solution lives on the interval containing x0x_0 where the formula is defined and differentiable. If the formula blows up, the solution ends there; the formula's values on the far side belong to a different solution.
  • Newton's law of cooling. T′=−k(T−Ta)T' = -k(T - T_a) for room temperature TaT_a. The quantity that decays exponentially is T−TaT - T_a, not TT.

Builds on: Integration: substitution and parts, Partial fractions and integrating rational functions

Problems

  1. ·

    Solve dydx=3y\dfrac{dy}{dx} = 3y with y(0)=−2y(0) = -2.

  2. ·

    Solve dydx=xy\dfrac{dy}{dx} = \dfrac{x}{y} with y(0)=3y(0) = 3.

  3. ··

    Solve dydx=xy2\dfrac{dy}{dx} = xy^2 with y(0)=1y(0) = 1, and find the interval on which the solution exists.

  4. ··

    Solve dydx=ex−y\dfrac{dy}{dx} = e^{x - y} with y(0)=ln⁡2y(0) = \ln2.

  5. ··

    A radioactive sample decays at a rate proportional to its mass, dmdt=−km\dfrac{dm}{dt} = -km, with a half-life of 55 years. How long until 10%10\% of it is left?

  6. ··

    Coffee at 90°C is left in a 20°C room, and T′=−k(T−20)T' = -k(T - 20). After 1010 minutes it is at 60°C. When does it reach 30°C?

  7. ···

    Solve dydx=y(1−y)\dfrac{dy}{dx} = y(1 - y) with y(0)=12y(0) = \tfrac12.

  8. ··

    Gradient flow is gradient descent with an infinitely small step: dwdt=−ηL′(w)\dfrac{dw}{dt} = -\eta L'(w). For L(w)=12(w−3)2L(w) = \tfrac12(w - 3)^2, η=0.1\eta = 0.1 and w(0)=0w(0) = 0, find w(t)w(t) and the time at which w=2.9w = 2.9.

  9. ··

    Solve dydx=2x(y−1)\dfrac{dy}{dx} = 2x(y - 1), first with y(0)=3y(0) = 3, then with y(0)=1y(0) = 1.

  10. ···

    Water drains from a tank through a hole at the bottom, and its depth hh (in meters, with tt in minutes) satisfies dhdt=−12h\dfrac{dh}{dt} = -\tfrac12\sqrt h, with h(0)=16h(0) = 16. When is the tank empty, and when is it half full?

Worked solutions

Problem 1

Solve dydx=3y\dfrac{dy}{dx} = 3y with y(0)=−2y(0) = -2.

  1. dyy=3 dx\dfrac{dy}{y} = 3\,dxSeparate, for y≠0y \ne 0.
  2. ln⁡∣y∣=3x+c\ln\lvert y\rvert = 3x + cIntegrate both sides; one constant.
  3. ∣y∣=ece3x\lvert y\rvert = e^ce^{3x}, so y=Ae3xy = Ae^{3x} with A=±ecA = \pm e^cThe absolute value is why AA can be negative.
  4. y(0)=A=−2y(0) = A = -2The initial condition.
  5. y=−2e3xy = -2e^{3x}Check: y′=−6e3x=3yy' = -6e^{3x} = 3y, and y(0)=−2y(0) = -2. The solution stays negative and grows in size.

Problem 2

Solve dydx=xy\dfrac{dy}{dx} = \dfrac{x}{y} with y(0)=3y(0) = 3.

  1. y dy=x dxy\,dy = x\,dxMultiply both sides by y dxy\,dx.
  2. y22=x22+C\tfrac{y^2}2 = \tfrac{x^2}2 + CIntegrate both sides.
  3. C=92C = \tfrac92, so y2=x2+9y^2 = x^2 + 9At x=0x = 0, y=3y = 3.
  4. y=x2+9y = \sqrt{x^2 + 9}Take the positive root, because y(0)=3>0y(0) = 3 > 0.
  5. y=x2+9y = \sqrt{x^2 + 9}, for all xxCheck: y′=xx2+9=xyy' = \tfrac{x}{\sqrt{x^2 + 9}} = \tfrac xy. The curve is the upper branch of the hyperbola y2−x2=9y^2 - x^2 = 9.

Problem 3

Solve dydx=xy2\dfrac{dy}{dx} = xy^2 with y(0)=1y(0) = 1, and find the interval on which the solution exists.

  1. y−2 dy=x dxy^{-2}\,dy = x\,dxSeparate, for y≠0y \ne 0.
  2. −1y=x22+C-\dfrac1y = \dfrac{x^2}2 + C∫y−2 dy=−y−1\int y^{-2}\,dy = -y^{-1}.
  3. C=−1C = -1At x=0x = 0: −1=0+C-1 = 0 + C.
  4. 1y=1−x22=2−x22\dfrac1y = 1 - \dfrac{x^2}2 = \dfrac{2 - x^2}{2}, so y=22−x2y = \dfrac{2}{2 - x^2}Solve for yy only after CC is in.
  5. y=22−x2y = \dfrac{2}{2 - x^2}, on −2<x<2-\sqrt2 < x < \sqrt2The formula blows up at x=±2≈±1.414x = \pm\sqrt2 \approx \pm1.414, so the solution through y(0)=1y(0) = 1 exists only between them. Growth at a rate y2y^2 is faster than exponential and reaches infinity in finite time.

Problem 4

Solve dydx=ex−y\dfrac{dy}{dx} = e^{x - y} with y(0)=ln⁡2y(0) = \ln2.

  1. dydx=exe−y\dfrac{dy}{dx} = e^xe^{-y}, so ey dy=ex dxe^y\,dy = e^x\,dxSplit the exponential, then separate.
  2. ey=ex+Ce^y = e^x + CIntegrate both sides.
  3. C=1C = 1At x=0x = 0: eln⁡2=2=1+Ce^{\ln2} = 2 = 1 + C.
  4. y=ln⁡(1+ex)y = \ln(1 + e^x)Take the log; 1+ex>01 + e^x > 0, so this is defined for every xx.
  5. y=ln⁡(1+ex)y = \ln(1 + e^x), the softplus functionCheck: y′=ex1+exy' = \tfrac{e^x}{1 + e^x} and ex−y=ex1+exe^{x - y} = \tfrac{e^x}{1 + e^x}. The derivative of softplus is the sigmoid.

Problem 5

A radioactive sample decays at a rate proportional to its mass, dmdt=−km\dfrac{dm}{dt} = -km, with a half-life of 55 years. How long until 10%10\% of it is left?

  1. m=m0e−ktm = m_0e^{-kt}The solution of m′=−kmm' = -km, as in Problem 1.
  2. e−5k=12e^{-5k} = \tfrac12, so k=ln⁡25k = \dfrac{\ln2}{5}After one half-life, half the mass is left.
  3. e−kt=110e^{-kt} = \tfrac1{10}, so t=ln⁡10k=5ln⁡10ln⁡2t = \dfrac{\ln10}{k} = \dfrac{5\ln10}{\ln2}Solve for the time when m=0.1m0m = 0.1m_0.
  4. 5ln⁡10ln⁡2≈16.61\dfrac{5\ln10}{\ln2} \approx 16.61 yearsAbout 3.323.32 half-lives: 2−3.32≈0.12^{-3.32} \approx 0.1. The initial mass cancels, so it was never needed.

Problem 6

Coffee at 90°C is left in a 20°C room, and T′=−k(T−20)T' = -k(T - 20). After 1010 minutes it is at 60°C. When does it reach 30°C?

  1. dTT−20=−k dt\dfrac{dT}{T - 20} = -k\,dt, so T−20=Ae−ktT - 20 = Ae^{-kt}Separate and integrate; T−20T - 20 decays exponentially.
  2. A=90−20=70A = 90 - 20 = 70At t=0t = 0.
  3. 70e−10k=4070e^{-10k} = 40, so k=ln⁡(7/4)10≈0.0560k = \dfrac{\ln(7/4)}{10} \approx 0.0560 per minuteAt t=10t = 10, T−20=40T - 20 = 40.
  4. 70e−kt=1070e^{-kt} = 10, so t=ln⁡7k=10ln⁡7ln⁡(7/4)t = \dfrac{\ln7}{k} = \dfrac{10\ln7}{\ln(7/4)}At T=30T = 30, T−20=10T - 20 = 10.
  5. About 34.7734.77 minutesTT approaches 20°C but never reaches it.

Problem 7

Solve dydx=y(1−y)\dfrac{dy}{dx} = y(1 - y) with y(0)=12y(0) = \tfrac12.

  1. dyy(1−y)=dx\dfrac{dy}{y(1 - y)} = dx, and 1y(1−y)=1y+11−y\dfrac{1}{y(1 - y)} = \dfrac1y + \dfrac{1}{1 - y}Separate, then partial fractions by the cover-up rule.
  2. ln⁡∣y∣−ln⁡∣1−y∣=x+c\ln\lvert y\rvert - \ln\lvert1 - y\rvert = x + c∫dy1−y=−ln⁡∣1−y∣\int\tfrac{dy}{1 - y} = -\ln\lvert1 - y\rvert.
  3. y1−y=Aex\dfrac{y}{1 - y} = Ae^x, and A=1A = 1At x=0x = 0, 1/21/2=1\tfrac{1/2}{1/2} = 1.
  4. y=ex(1−y)y = e^x(1 - y), so y(1+ex)=exy(1 + e^x) = e^x and y=ex1+exy = \dfrac{e^x}{1 + e^x}Solve for yy.
  5. y=11+e−xy = \dfrac{1}{1 + e^{-x}}, the sigmoidDivide top and bottom by exe^x. This is why σ′=σ(1−σ)\sigma' = \sigma(1 - \sigma), and why logistic growth with rate 11 and capacity 11 is a sigmoid. The constant solutions y≡0y \equiv 0 and y≡1y \equiv 1 are its two horizontal asymptotes.

Problem 8

Gradient flow is gradient descent with an infinitely small step: dwdt=−ηL′(w)\dfrac{dw}{dt} = -\eta L'(w). For L(w)=12(w−3)2L(w) = \tfrac12(w - 3)^2, η=0.1\eta = 0.1 and w(0)=0w(0) = 0, find w(t)w(t) and the time at which w=2.9w = 2.9.

  1. dwdt=−0.1(w−3)\dfrac{dw}{dt} = -0.1(w - 3)L′(w)=w−3L'(w) = w - 3.
  2. w−3=Ae−0.1tw - 3 = Ae^{-0.1t}, and A=−3A = -3The same structure as Problem 6: w−3w - 3 decays exponentially; w(0)−3=−3w(0) - 3 = -3.
  3. w=3−3e−0.1tw = 3 - 3e^{-0.1t}ww climbs toward the minimizer 33.
  4. 3e−0.1t=0.13e^{-0.1t} = 0.1, so t=10ln⁡30t = 10\ln30w=2.9w = 2.9 means the gap is 0.10.1.
  5. w(t)=3−3e−0.1tw(t) = 3 - 3e^{-0.1t}; w=2.9w = 2.9 at t=10ln⁡30≈34.01t = 10\ln30 \approx 34.01On a quadratic loss the distance to the minimum shrinks by the same factor in every unit of time. Gradient descent with step η\eta shrinks it by 1−η1 - \eta per step, and (1−η)n≈e−ηn(1 - \eta)^n \approx e^{-\eta n}.

Problem 9

Solve dydx=2x(y−1)\dfrac{dy}{dx} = 2x(y - 1), first with y(0)=3y(0) = 3, then with y(0)=1y(0) = 1.

  1. dyy−1=2x dx\dfrac{dy}{y - 1} = 2x\,dx, for y≠1y \ne 1Separate.
  2. ln⁡∣y−1∣=x2+c\ln\lvert y - 1\rvert = x^2 + c, so y=1+Aex2y = 1 + Ae^{x^2}A=±ecA = \pm e^c is not 00 so far.
  3. y(0)=3y(0) = 3 gives A=2A = 21+A=31 + A = 3.
  4. For y(0)=1y(0) = 1: y≡1y \equiv 1 satisfies y′=0=2x(1−1)y' = 0 = 2x(1 - 1)The constant solution, which step 1 excluded by dividing by y−1y - 1. It is the case A=0A = 0.
  5. y=1+2ex2y = 1 + 2e^{x^2} for y(0)=3y(0) = 3; y≡1y \equiv 1 for y(0)=1y(0) = 1Check: y′=4xex2=2x⋅2ex2=2x(y−1)y' = 4xe^{x^2} = 2x\cdot2e^{x^2} = 2x(y - 1).

Problem 10

Water drains from a tank through a hole at the bottom, and its depth hh (in meters, with tt in minutes) satisfies dhdt=−12h\dfrac{dh}{dt} = -\tfrac12\sqrt h, with h(0)=16h(0) = 16. When is the tank empty, and when is it half full?

  1. h−1/2 dh=−12 dth^{-1/2}\,dh = -\tfrac12\,dtSeparate, for h>0h > 0.
  2. 2h=−t2+C2\sqrt h = -\tfrac t2 + C, and C=8C = 8∫h−1/2 dh=2h1/2\int h^{-1/2}\,dh = 2h^{1/2}; at t=0t = 0, 2⋅4=82\cdot4 = 8.
  3. h=4−t4\sqrt h = 4 - \tfrac t4, so h=(4−t4)2h = \big(4 - \tfrac t4\big)^2 for 0≤t≤160 \le t \le 16Valid while h≥0\sqrt h \ge 0.
  4. h=0h = 0 at t=16t = 16After that h≡0h \equiv 0: the formula (4−t4)2\big(4 - \tfrac t4\big)^2 would start rising again, which an empty tank does not do.
  5. 8=4−t4\sqrt8 = 4 - \tfrac t4, so t=16−48=16−82t = 16 - 4\sqrt8 = 16 - 8\sqrt2Half full means h=8h = 8, if the tank has straight sides.
  6. Empty at t=16t = 16 minutes; half full at t=16−82≈4.69t = 16 - 8\sqrt2 \approx 4.69 minutesThe first half drains in under a third of the time, because the flow is fastest when the water is deepest.

Where this goes wrong

1. Adding the constant after exponentiating

The +C+C is often left until the end, as it would be for an ordinary antiderivative.

  1. dyy=3 dx\dfrac{dy}{y} = 3\,dx, so ln⁡∣y∣=3x\ln\lvert y\rvert = 3xRight so far, apart from the constant: Problem 1, step 2.
  2. “Solve for yy, then add the constant.”The habit that causes the mistake: the constant belongs to the integration step, not to the final line.
  3. y=e3x+Cy = e^{3x} + C, and y(0)=−2y(0) = -2 gives y=e3x−3y = e^{3x} - 3Check it: y′=3e3xy' = 3e^{3x}, but 3y=3e3x−93y = 3e^{3x} - 9, so it does not satisfy the equation. Added at the integration step, ln⁡∣y∣=3x+c\ln\lvert y\rvert = 3x + c becomes y=Ae3xy = Ae^{3x}, a multiplicative constant, and y=−2e3xy = -2e^{3x}.

2. Splitting a square root

After solving for y2y^2, taking the square root looks like taking it term by term.

  1. y2=x2+9y^2 = x^2 + 9Right so far: Problem 2, step 3.
  2. “The square root of x2x^2 is xx and of 99 is 33.”The habit that causes the mistake: a+b\sqrt{a + b} treated as a+b\sqrt a + \sqrt b.
  3. y=x+3y = x + 3At x=4x = 4 this gives 77, but 16+9=5\sqrt{16 + 9} = 5. Check the equation too: y′=1y' = 1, while xy=xx+3\tfrac xy = \tfrac{x}{x + 3}, so y=x+3y = x + 3 is not a solution. The answer is y=x2+9y = \sqrt{x^2 + 9}.

3. Losing the constant solution

Separating means dividing by the function of yy, and that function can be 00.

  1. dyy−1=2x dx\dfrac{dy}{y - 1} = 2x\,dx, so y=1+Aex2y = 1 + Ae^{x^2} with A=±ecA = \pm e^cRight so far: Problem 9, step 2.
  2. “ece^c is never 00, so A≠0A \ne 0.”The habit that causes the mistake: only the solutions the division allowed are kept.
  3. With y(0)=1y(0) = 1, 1+A=11 + A = 1 needs A=0A = 0, so there is no solutiony≡1y \equiv 1 is a solution: both sides of y′=2x(y−1)y' = 2x(y - 1) are 00. Dividing by y−1y - 1 excluded it. Whenever you divide by h(y)h(y), check the values with h(y)=0h(y) = 0 separately; here they make A=0A = 0 allowed.

4. Forgetting the room temperature in Newton's law

Exponential decay is usually y=y0e−kty = y_0e^{-kt}, and that pattern gets applied to TT itself.

  1. T′=−k(T−20)T' = -k(T - 20), T(0)=90T(0) = 90, T(10)=60T(10) = 60Right so far: Problem 6.
  2. “TT decays exponentially, so T=90e−ktT = 90e^{-kt}.”The habit that causes the mistake: the shift by the room temperature is dropped.
  3. 90e−10k=6090e^{-10k} = 60 gives k=ln⁡1.510k = \tfrac{\ln1.5}{10}, and T=30T = 30 at t=10ln⁡3ln⁡1.5≈27.10t = \tfrac{10\ln3}{\ln1.5} \approx 27.10 minutesT=90e−ktT = 90e^{-kt} decays to 0°C, not to the room's 20°C. It is T−20T - 20 that decays: 70e−10k=4070e^{-10k} = 40, and the coffee reaches 30°C at about 34.7734.77 minutes.

5. Using the formula past the blow-up

The formula for the solution is defined on both sides of the point where it blows up.

  1. y=22−x2y = \dfrac{2}{2 - x^2} solves y′=xy2y' = xy^2 with y(0)=1y(0) = 1Right so far: Problem 3, step 4.
  2. “Plug in x=2x = 2.”The habit that causes the mistake: the formula treated as valid wherever it can be evaluated.
  3. y(2)=22−4=−1y(2) = \dfrac{2}{2 - 4} = -1The solution through y(0)=1y(0) = 1 goes to +∞+\infty at x=2≈1.414x = \sqrt2 \approx 1.414 and stops there; a solution must be differentiable on an interval, and it cannot jump from +∞+\infty to negative values. The branch beyond 2\sqrt2 is a different solution, one that never passes through (0,1)(0, 1). y(2)y(2) is not defined for this problem.

Print this set: separable-differential-equations.pdf (problems, answers, and worked solutions on separate pages).

Read the guide: Separable differential equations: separate, integrate, add C, then solve for y