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 x times a function of ,y, 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 split into ,x+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..dxdy=g(x)h(y). Divide by ,h(y), multiply by ,dx, and integrate both sides: .∫h(y)dy=∫g(x)dx+C. One constant is enough, and it goes in before you solve for .y.
Constant solutions. If ,h(y0)=0, then y≡y0 is a solution. Dividing by h(y) assumes ,h(y)=0, so check these separately.
Exponential growth and decay.y′=ky has solutions .y=y(0)ekx. From ln∣y∣=kx+c you get y=Aekx with ,A=±ec, and A=0 is the constant solution, so A can be any real number.
Initial condition. Use y(x0)=y0 to find .C. Then check that the answer satisfies the equation.
Interval of validity. A solution lives on the interval containing x0 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) for room temperature .Ta. The quantity that decays exponentially is ,T−Ta, not .T.
Solve dxdy=xy2 with ,y(0)=1, and find the interval on which the solution exists.
··
Solve dxdy=ex−y with .y(0)=ln2.
··
A radioactive sample decays at a rate proportional to its mass, ,dtdm=−km, with a half-life of 5 years. How long until 10% of it is left?
··
Coffee at 90°C is left in a 20°C room, and .T′=−k(T−20). After 10 minutes it is at 60°C. When does it reach 30°C?
···
Solve dxdy=y(1−y) with .y(0)=21.
··
Gradient flow is gradient descent with an infinitely small step: .dtdw=−ηL′(w). For ,L(w)=21(w−3)2,η=0.1 and ,w(0)=0, find w(t) and the time at which .w=2.9.
··
Solve ,dxdy=2x(y−1), first with ,y(0)=3, then with .y(0)=1.
···
Water drains from a tank through a hole at the bottom, and its depth h (in meters, with t in minutes) satisfies ,dtdh=−21h, with .h(0)=16. When is the tank empty, and when is it half full?
Answers
y=−2e3x
,y=x2+9, for all x
,y=2−x22, on −2<x<2
,y=ln(1+ex), the softplus function
ln25ln10≈16.61 years
About 34.77 minutes
,y=1+e−x1, the sigmoid
;w(t)=3−3e−0.1t;w=2.9 at t=10ln30≈34.01
y=1+2ex2 for ;y(0)=3;y≡1 for y(0)=1
Empty at t=16 minutes; half full at t=16−82≈4.69 minutes
Worked solutions
Problem 1
Solve dxdy=3y with .y(0)=−2.
ydy=3dxSeparate, for .y=0.
ln∣y∣=3x+cIntegrate both sides; one constant.
,∣y∣=ece3x, so y=Ae3x with A=±ecThe absolute value is why A can be negative.
y(0)=A=−2The initial condition.
y=−2e3xCheck: ,y′=−6e3x=3y, and .y(0)=−2. The solution stays negative and grows in size.
Problem 2
Solve dxdy=yx with .y(0)=3.
ydy=xdxMultiply both sides by .ydx.
2y2=2x2+CIntegrate both sides.
,C=29, so y2=x2+9At ,x=0,.y=3.
y=x2+9Take the positive root, because .y(0)=3>0.
,y=x2+9, for all xCheck: .y′=x2+9x=yx. The curve is the upper branch of the hyperbola .y2−x2=9.
Problem 3
Solve dxdy=xy2 with ,y(0)=1, and find the interval on which the solution exists.
y−2dy=xdxSeparate, for .y=0.
−y1=2x2+C.∫y−2dy=−y−1.
C=−1At :x=0:.−1=0+C.
,y1=1−2x2=22−x2, so y=2−x22Solve for y only after C is in.
,y=2−x22, on −2<x<2The formula blows up at ,x=±2≈±1.414, so the solution through y(0)=1 exists only between them. Growth at a rate y2 is faster than exponential and reaches infinity in finite time.
Problem 4
Solve dxdy=ex−y with .y(0)=ln2.
,dxdy=exe−y, so eydy=exdxSplit the exponential, then separate.
ey=ex+CIntegrate both sides.
C=1At :x=0:.eln2=2=1+C.
y=ln(1+ex)Take the log; ,1+ex>0, so this is defined for every .x.
,y=ln(1+ex), the softplus functionCheck: y′=1+exex and .ex−y=1+exex. The derivative of softplus is the sigmoid.
Problem 5
A radioactive sample decays at a rate proportional to its mass, ,dtdm=−km, with a half-life of 5 years. How long until 10% of it is left?
m=m0e−ktThe solution of ,m′=−km, as in Problem 1.
,e−5k=21, so k=5ln2After one half-life, half the mass is left.
,e−kt=101, so t=kln10=ln25ln10Solve for the time when .m=0.1m0.
ln25ln10≈16.61 yearsAbout 3.32 half-lives: .2−3.32≈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). After 10 minutes it is at 60°C. When does it reach 30°C?
,T−20dT=−kdt, so T−20=Ae−ktSeparate and integrate; T−20 decays exponentially.
A=90−20=70At .t=0.
,70e−10k=40, so k=10ln(7/4)≈0.0560 per minuteAt ,t=10,.T−20=40.
,70e−kt=10, so t=kln7=ln(7/4)10ln7At ,T=30,.T−20=10.
About 34.77 minutesT approaches 20°C but never reaches it.
Problem 7
Solve dxdy=y(1−y) with .y(0)=21.
,y(1−y)dy=dx, and y(1−y)1=y1+1−y1Separate, then partial fractions by the cover-up rule.
ln∣y∣−ln∣1−y∣=x+c.∫1−ydy=−ln∣1−y∣.
,1−yy=Aex, and A=1At ,x=0,.1/21/2=1.
,y=ex(1−y), so y(1+ex)=ex and y=1+exexSolve for .y.
,y=1+e−x1, the sigmoidDivide top and bottom by .ex. This is why ,σ′=σ(1−σ), and why logistic growth with rate 1 and capacity 1 is a sigmoid. The constant solutions y≡0 and y≡1 are its two horizontal asymptotes.
Problem 8
Gradient flow is gradient descent with an infinitely small step: .dtdw=−ηL′(w). For ,L(w)=21(w−3)2,η=0.1 and ,w(0)=0, find w(t) and the time at which .w=2.9.
dtdw=−0.1(w−3).L′(w)=w−3.
,w−3=Ae−0.1t, and A=−3The same structure as Problem 6: w−3 decays exponentially; .w(0)−3=−3.
w=3−3e−0.1tw climbs toward the minimizer .3.
,3e−0.1t=0.1, so t=10ln30w=2.9 means the gap is .0.1.
;w(t)=3−3e−0.1t;w=2.9 at t=10ln30≈34.01On a quadratic loss the distance to the minimum shrinks by the same factor in every unit of time. Gradient descent with step η shrinks it by 1−η per step, and .(1−η)n≈e−ηn.
Problem 9
Solve ,dxdy=2x(y−1), first with ,y(0)=3, then with .y(0)=1.
,y−1dy=2xdx, for y=1Separate.
,ln∣y−1∣=x2+c, so y=1+Aex2A=±ec is not 0 so far.
y(0)=3 gives A=2.1+A=3.
For :y(0)=1:y≡1 satisfies y′=0=2x(1−1)The constant solution, which step 1 excluded by dividing by .y−1. It is the case .A=0.
y=1+2ex2 for ;y(0)=3;y≡1 for y(0)=1Check: .y′=4xex2=2x⋅2ex2=2x(y−1).
Problem 10
Water drains from a tank through a hole at the bottom, and its depth h (in meters, with t in minutes) satisfies ,dtdh=−21h, with .h(0)=16. When is the tank empty, and when is it half full?
h−1/2dh=−21dtSeparate, for .h>0.
,2h=−2t+C, and C=8;∫h−1/2dh=2h1/2; at ,t=0,.2⋅4=8.
,h=4−4t, so h=(4−4t)2 for 0≤t≤16Valid while .h≥0.
h=0 at t=16After that :h≡0: the formula (4−4t)2 would start rising again, which an empty tank does not do.
,8=4−4t, so t=16−48=16−82Half full means ,h=8, if the tank has straight sides.
Empty at t=16 minutes; half full at t=16−82≈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 is often left until the end, as it would be for an ordinary antiderivative.
,ydy=3dx, so ln∣y∣=3xRight so far, apart from the constant: Problem 1, step 2.
“Solve for ,y, then add the constant.”The habit that causes the mistake: the constant belongs to the integration step, not to the final line.
,y=e3x+C, and y(0)=−2 gives y=e3x−3Check it: ,y′=3e3x, but ,3y=3e3x−9, so it does not satisfy the equation. Added at the integration step, ln∣y∣=3x+c becomes ,y=Ae3x, a multiplicative constant, and .y=−2e3x.
2. Splitting a square root
After solving for ,y2, taking the square root looks like taking it term by term.
y2=x2+9Right so far: Problem 2, step 3.
“The square root of x2 is x and of 9 is .3.”The habit that causes the mistake: a+b treated as .a+b.
y=x+3At x=4 this gives ,7, but .16+9=5. Check the equation too: ,y′=1, while ,yx=x+3x, so y=x+3 is not a solution. The answer is .y=x2+9.
3. Losing the constant solution
Separating means dividing by the function of ,y, and that function can be .0.
,y−1dy=2xdx, so y=1+Aex2 with A=±ecRight so far: Problem 9, step 2.
“ec is never ,0, so .A=0.”The habit that causes the mistake: only the solutions the division allowed are kept.
With ,y(0)=1,1+A=1 needs ,A=0, so there is no solutiony≡1 is a solution: both sides of y′=2x(y−1) are .0. Dividing by y−1 excluded it. Whenever you divide by ,h(y), check the values with h(y)=0 separately; here they make A=0 allowed.
4. Forgetting the room temperature in Newton's law
Exponential decay is usually ,y=y0e−kt, and that pattern gets applied to T itself.
,T′=−k(T−20),,T(0)=90,T(10)=60Right so far: Problem 6.
“T decays exponentially, so .T=90e−kt.”The habit that causes the mistake: the shift by the room temperature is dropped.
90e−10k=60 gives ,k=10ln1.5, and T=30 at t=ln1.510ln3≈27.10 minutesT=90e−kt decays to 0°C, not to the room's 20°C. It is T−20 that decays: ,70e−10k=40, and the coffee reaches 30°C at about 34.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.
y=2−x22 solves y′=xy2 with y(0)=1Right so far: Problem 3, step 4.
“Plug in .x=2.”The habit that causes the mistake: the formula treated as valid wherever it can be evaluated.
y(2)=2−42=−1The solution through y(0)=1 goes to +∞ at x=2≈1.414 and stops there; a solution must be differentiable on an interval, and it cannot jump from +∞ to negative values. The branch beyond 2 is a different solution, one that never passes through .(0,1).y(2) is not defined for this problem.