Practice / Calculus

Linear first-order differential equations: the integrating factor

Ten linear first-order differential equations solved with an integrating factor: a constant forcing term, e^(2x) on the right, xy′ + 2y = x² after rewriting in standard form, a forcing term that needs integration by parts, sec x as the factor, one that is also separable, a salt tank with constant volume, a sinusoidal input and its lagging steady state, a tank that fills while it drains, and the Bernoulli substitution that turns the logistic equation into a linear one, with worked solutions and the mistakes of multiplying only one side, adding the constant after dividing and holding a changing volume constant.

Before you start

A first-order equation is linear when yy and y′y' appear only to the first power, with coefficients that may depend on xx: y′+P(x) y=Q(x)y' + P(x)\,y = Q(x). Most of these are not separable, because the right side is a sum rather than a product, but all of them can be solved the same way. Multiply by an integrating factor that turns the left side into the derivative of a product, then integrate. Mixing tanks, circuits, cooling with a changing room temperature and the continuous-time version of an exponential moving average are all equations of this kind. The work goes wrong in a few places: the factor computed before the equation is in standard form or with the wrong sign, only the left side multiplied, the constant added after dividing by the factor, and a changing volume treated as fixed. These ten problems cover each of them.

  • Standard form. Divide by the coefficient of y′y' so the equation reads y′+P(x) y=Q(x)y' + P(x)\,y = Q(x). PP is the coefficient of yy after this division, sign included.
  • Integrating factor. μ(x)=e∫P(x) dx\mu(x) = e^{\int P(x)\,dx}, with no constant needed. It is chosen so that μ′=Pμ\mu' = P\mu, and then μy′+Pμy=(μy)′\mu y' + P\mu y = (\mu y)' by the product rule.
  • The solution. Multiply both sides by μ\mu: (μy)′=μQ(\mu y)' = \mu Q. Integrate, μy=∫μQ dx+C\mu y = \displaystyle\int\mu Q\,dx + C, and only then divide by μ\mu: y=1μ(∫μQ dx+C)y = \dfrac{1}{\mu}\Big(\displaystyle\int\mu Q\,dx + C\Big). The constant ends up multiplied by 1μ\tfrac1\mu.
  • Structure. The solution is one particular solution plus Cμ\tfrac{C}{\mu}, the general solution of y′+Py=0y' + Py = 0. When PP is a positive constant, Cμ=Ce−Px\tfrac{C}{\mu} = Ce^{-Px} is a transient that dies out.
  • Mixing problems. If Q(t)Q(t) is the amount of salt and V(t)V(t) the volume, Q′=(rate in)−QV(t)⋅(outflow rate)Q' = (\text{rate in}) - \dfrac{Q}{V(t)}\cdot(\text{outflow rate}). VV is constant only if inflow and outflow are equal.
  • Bernoulli equations. y′+Py=Qyny' + Py = Qy^n becomes linear in v=y1−nv = y^{1-n}.

Builds on: Separable differential equations: growth, decay, cooling and the logistic curve, Integration: substitution and parts

Problems

  1. ·

    Solve y′+2y=6y' + 2y = 6 with y(0)=1y(0) = 1.

  2. ·

    Solve y′−y=e2xy' - y = e^{2x} with y(0)=0y(0) = 0.

  3. ··

    Solve xy′+2y=x2xy' + 2y = x^2 for x>0x > 0, with y(1)=1y(1) = 1.

  4. ··

    Solve y′+y=xy' + y = x with y(0)=0y(0) = 0.

  5. ··

    Solve y′+(tan⁡x) y=cos⁡xy' + (\tan x)\,y = \cos x on −π2<x<π2-\tfrac\pi2 < x < \tfrac\pi2, with y(0)=1y(0) = 1.

  6. ··

    Solve y′+2xy=xy' + 2xy = x with y(0)=0y(0) = 0, with an integrating factor and then by separating.

  7. ··

    A tank holds 100100 L of water with 1010 kg of salt dissolved in it. Brine with 0.20.2 kg of salt per liter flows in at 55 L/min, and the well-mixed solution flows out at 55 L/min. Find the salt Q(t)Q(t), its value at t=20t = 20, and when it reaches 1919 kg.

  8. ···

    A first-order filter, the continuous version of an exponential moving average, obeys y′+y=sin⁡xy' + y = \sin x, with y(0)=0y(0) = 0. Solve it, and describe the solution for large xx.

  9. ···

    A tank starts with 2020 L of pure water. Brine with 33 g of salt per liter flows in at 22 L/min, and the mixture flows out at 11 L/min. Find the salt Q(t)Q(t), and the amount and concentration at t=20t = 20 min.

  10. ···

    Solve the logistic equation y′=y−y2y' = y - y^2 with y(0)=12y(0) = \tfrac12 by the substitution v=1yv = \tfrac1y.

Worked solutions

Problem 1

Solve y′+2y=6y' + 2y = 6 with y(0)=1y(0) = 1.

  1. μ=e∫2 dx=e2x\mu = e^{\int2\,dx} = e^{2x}Already in standard form, with P=2P = 2.
  2. (e2xy)′=6e2x(e^{2x}y)' = 6e^{2x}Multiply both sides by μ\mu; the left side is now a product's derivative.
  3. e2xy=3e2x+Ce^{2x}y = 3e^{2x} + CIntegrate both sides.
  4. y=3+Ce−2xy = 3 + Ce^{-2x}, and y(0)=3+C=1y(0) = 3 + C = 1 gives C=−2C = -2Divide by μ\mu, then use the initial condition.
  5. y=3−2e−2xy = 3 - 2e^{-2x}Check: y′=4e−2xy' = 4e^{-2x} and y′+2y=4e−2x+6−4e−2x=6y' + 2y = 4e^{-2x} + 6 - 4e^{-2x} = 6. The solution rises toward the equilibrium y=3y = 3.

Problem 2

Solve y′−y=e2xy' - y = e^{2x} with y(0)=0y(0) = 0.

  1. P=−1P = -1, so μ=e−x\mu = e^{-x}The sign of PP goes into the exponent.
  2. (e−xy)′=e−xe2x=ex(e^{-x}y)' = e^{-x}e^{2x} = e^xMultiply both sides by e−xe^{-x}.
  3. e−xy=ex+Ce^{-x}y = e^x + C, so y=e2x+Cexy = e^{2x} + Ce^xIntegrate, then divide by e−xe^{-x}, which multiplies by exe^x.
  4. y(0)=1+C=0y(0) = 1 + C = 0 gives C=−1C = -1The initial condition.
  5. y=e2x−exy = e^{2x} - e^xCheck: y′−y=(2e2x−ex)−(e2x−ex)=e2xy' - y = (2e^{2x} - e^x) - (e^{2x} - e^x) = e^{2x}.

Problem 3

Solve xy′+2y=x2xy' + 2y = x^2 for x>0x > 0, with y(1)=1y(1) = 1.

  1. y′+2x y=xy' + \dfrac2x\,y = xDivide by xx to reach standard form; now P=2xP = \tfrac2x.
  2. μ=e∫2/x dx=e2ln⁡x=x2\mu = e^{\int 2/x\,dx} = e^{2\ln x} = x^2For x>0x > 0, ln⁡∣x∣=ln⁡x\ln\lvert x\rvert = \ln x.
  3. (x2y)′=x2⋅x=x3(x^2y)' = x^2\cdot x = x^3Multiply the standard form by x2x^2. This is the original equation multiplied by xx.
  4. x2y=x44+Cx^2y = \dfrac{x^4}4 + C, and 1=14+C1 = \tfrac14 + C gives C=34C = \tfrac34Integrate, then use y(1)=1y(1) = 1.
  5. y=x24+34x2y = \dfrac{x^2}4 + \dfrac{3}{4x^2}Check: xy′=x22−32x2xy' = \tfrac{x^2}2 - \tfrac{3}{2x^2} and 2y=x22+32x22y = \tfrac{x^2}2 + \tfrac{3}{2x^2}, which add to x2x^2. For example y(2)=1+316=1916y(2) = 1 + \tfrac3{16} = \tfrac{19}{16}.

Problem 4

Solve y′+y=xy' + y = x with y(0)=0y(0) = 0.

  1. μ=ex\mu = e^x, so (exy)′=xex(e^xy)' = xe^xP=1P = 1.
  2. ∫xex dx=xex−ex\displaystyle\int xe^x\,dx = xe^x - e^xBy parts with u=xu = x, dv=ex dxdv = e^x\,dx.
  3. exy=(x−1)ex+Ce^xy = (x - 1)e^x + C, so y=x−1+Ce−xy = x - 1 + Ce^{-x}Add the constant before dividing by exe^x.
  4. y(0)=−1+C=0y(0) = -1 + C = 0 gives C=1C = 1The initial condition.
  5. y=x−1+e−xy = x - 1 + e^{-x}Check: y′+y=(1−e−x)+(x−1+e−x)=xy' + y = (1 - e^{-x}) + (x - 1 + e^{-x}) = x. For large xx the solution follows the line y=x−1y = x - 1, one unit behind the input.

Problem 5

Solve y′+(tan⁡x) y=cos⁡xy' + (\tan x)\,y = \cos x on −π2<x<π2-\tfrac\pi2 < x < \tfrac\pi2, with y(0)=1y(0) = 1.

  1. ∫tan⁡x dx=−ln⁡∣cos⁡x∣\displaystyle\int\tan x\,dx = -\ln\lvert\cos x\rvert, so μ=e−ln⁡cos⁡x=1cos⁡x=sec⁡x\mu = e^{-\ln\cos x} = \dfrac{1}{\cos x} = \sec xcos⁡x>0\cos x > 0 on this interval.
  2. (ysec⁡x)′=cos⁡xsec⁡x=1(y\sec x)' = \cos x\sec x = 1Multiply both sides by sec⁡x\sec x.
  3. ysec⁡x=x+Cy\sec x = x + C, so y=(x+C)cos⁡xy = (x + C)\cos xIntegrate, then multiply by cos⁡x\cos x.
  4. y=(x+1)cos⁡xy = (x + 1)\cos xy(0)=C=1y(0) = C = 1. Check: y′=cos⁡x−(x+1)sin⁡xy' = \cos x - (x + 1)\sin x and ytan⁡x=(x+1)sin⁡xy\tan x = (x + 1)\sin x, which add to cos⁡x\cos x.

Problem 6

Solve y′+2xy=xy' + 2xy = x with y(0)=0y(0) = 0, with an integrating factor and then by separating.

  1. μ=e∫2x dx=ex2\mu = e^{\int2x\,dx} = e^{x^2}, so (ex2y)′=xex2(e^{x^2}y)' = xe^{x^2}P=2xP = 2x.
  2. ex2y=12ex2+Ce^{x^2}y = \tfrac12e^{x^2} + C, so y=12+Ce−x2y = \tfrac12 + Ce^{-x^2}, and C=−12C = -\tfrac12∫xex2 dx=12ex2\int xe^{x^2}\,dx = \tfrac12e^{x^2} by u=x2u = x^2.
  3. Separating: y′=x(1−2y)y' = x(1 - 2y), so dy1−2y=x dx\dfrac{dy}{1 - 2y} = x\,dx and −12ln⁡∣1−2y∣=x22+c-\tfrac12\ln\lvert1 - 2y\rvert = \tfrac{x^2}2 + cHere the right side factors, so this one is separable as well.
  4. 1−2y=Ae−x21 - 2y = Ae^{-x^2} with A=1A = 1 from y(0)=0y(0) = 0The same family.
  5. y=12(1−e−x2)y = \tfrac12\big(1 - e^{-x^2}\big)Both methods agree, as they must. With P≠0P \ne 0, an equation y′+Py=Qy' + Py = Q is separable exactly when QP\tfrac QP is a constant; here it is 12\tfrac12, the value yy settles at.

Problem 7

A tank holds 100100 L of water with 1010 kg of salt dissolved in it. Brine with 0.20.2 kg of salt per liter flows in at 55 L/min, and the well-mixed solution flows out at 55 L/min. Find the salt Q(t)Q(t), its value at t=20t = 20, and when it reaches 1919 kg.

  1. Q′=0.2⋅5−Q100⋅5=1−Q20Q' = 0.2\cdot5 - \dfrac{Q}{100}\cdot5 = 1 - \dfrac{Q}{20}In: 11 kg/min. Out: the concentration Q100\tfrac{Q}{100} times 55 L/min. The volume stays at 100100 L.
  2. Q′+Q20=1Q' + \dfrac{Q}{20} = 1, μ=et/20\mu = e^{t/20}, (et/20Q)′=et/20(e^{t/20}Q)' = e^{t/20}Standard form with P=120P = \tfrac1{20}.
  3. et/20Q=20et/20+Ce^{t/20}Q = 20e^{t/20} + C, so Q=20+Ce−t/20Q = 20 + Ce^{-t/20}, and Q(0)=10Q(0) = 10 gives C=−10C = -10Integrate, divide, apply Q(0)Q(0).
  4. Q(20)=20−10e−1Q(20) = 20 - 10e^{-1}; Q=19Q = 19 when 10e−t/20=110e^{-t/20} = 1, t=20ln⁡10t = 20\ln10The gap to 2020 kg shrinks by a factor of ee every 2020 minutes.
  5. Q=20−10e−t/20Q = 20 - 10e^{-t/20}; Q(20)≈16.32Q(20) \approx 16.32 kg; 1919 kg at t=20ln⁡10≈46.05t = 20\ln10 \approx 46.05 minIn the long run the tank holds 100×0.2=20100 \times 0.2 = 20 kg, the inflow concentration.

Problem 8

A first-order filter, the continuous version of an exponential moving average, obeys y′+y=sin⁡xy' + y = \sin x, with y(0)=0y(0) = 0. Solve it, and describe the solution for large xx.

  1. μ=ex\mu = e^x, (exy)′=exsin⁡x(e^xy)' = e^x\sin xP=1P = 1.
  2. ∫exsin⁡x dx=ex(sin⁡x−cos⁡x)2\displaystyle\int e^x\sin x\,dx = \frac{e^x(\sin x - \cos x)}{2}By parts twice, solving for the integral when it reappears.
  3. y=sin⁡x−cos⁡x2+Ce−xy = \dfrac{\sin x - \cos x}2 + Ce^{-x}, and y(0)=−12+C=0y(0) = -\tfrac12 + C = 0 gives C=12C = \tfrac12Divide by exe^x and apply y(0)=0y(0) = 0.
  4. sin⁡x−cos⁡x2=12sin⁡(x−π4)\dfrac{\sin x - \cos x}2 = \dfrac{1}{\sqrt2}\sin\Big(x - \dfrac\pi4\Big)sin⁡(x−π4)=sin⁡x−cos⁡x2\sin(x - \tfrac\pi4) = \tfrac{\sin x - \cos x}{\sqrt2}.
  5. y=12(sin⁡x−cos⁡x)+12e−xy = \tfrac12(\sin x - \cos x) + \tfrac12e^{-x}; for large xx, y≈12sin⁡(x−π4)y \approx \tfrac{1}{\sqrt2}\sin\big(x - \tfrac\pi4\big)The transient 12e−x\tfrac12e^{-x} dies out. What is left follows the input with its amplitude cut to 12≈0.707\tfrac1{\sqrt2} \approx 0.707 and a lag of π4\tfrac\pi4: smoothing always costs delay, which is the tradeoff in choosing an EMA's decay rate.

Problem 9

A tank starts with 2020 L of pure water. Brine with 33 g of salt per liter flows in at 22 L/min, and the mixture flows out at 11 L/min. Find the salt Q(t)Q(t), and the amount and concentration at t=20t = 20 min.

  1. V(t)=20+tV(t) = 20 + tThe volume grows by 2−1=12 - 1 = 1 L/min.
  2. Q′=3⋅2−Q20+t⋅1=6−Q20+tQ' = 3\cdot2 - \dfrac{Q}{20 + t}\cdot1 = 6 - \dfrac{Q}{20 + t}The outflow concentration is QV(t)\tfrac{Q}{V(t)}, with the current volume.
  3. μ=e∫dt/(20+t)=20+t\mu = e^{\int dt/(20 + t)} = 20 + t, so ((20+t)Q)′=6(20+t)\big((20 + t)Q\big)' = 6(20 + t)P=120+tP = \tfrac{1}{20 + t}.
  4. (20+t)Q=3(20+t)2+C(20 + t)Q = 3(20 + t)^2 + C, and Q(0)=0Q(0) = 0 gives C=−1200C = -1200∫6(20+t) dt=3(20+t)2\int6(20 + t)\,dt = 3(20 + t)^2; at t=0t = 0, 0=1200+C0 = 1200 + C.
  5. Q=3(20+t)−120020+tQ = 3(20 + t) - \dfrac{1200}{20 + t}; at t=20t = 20, 9090 g in 4040 L, or 2.252.25 g/LQ(20)=120−30Q(20) = 120 - 30. The concentration approaches 33 g/L, the inflow's, as the tank grows.

Problem 10

Solve the logistic equation y′=y−y2y' = y - y^2 with y(0)=12y(0) = \tfrac12 by the substitution v=1yv = \tfrac1y.

  1. v′=−y′y2=−y−y2y2=1−vv' = -\dfrac{y'}{y^2} = -\dfrac{y - y^2}{y^2} = 1 - vA Bernoulli equation with n=2n = 2, so v=y1−2=1yv = y^{1-2} = \tfrac1y.
  2. v′+v=1v' + v = 1, μ=ex\mu = e^x, so exv=ex+Ce^xv = e^x + C and v=1+Ce−xv = 1 + Ce^{-x}Linear in vv, with P=1P = 1.
  3. v(0)=2v(0) = 2 gives C=1C = 1v(0)=1y(0)v(0) = \tfrac{1}{y(0)}.
  4. y=11+e−xy = \dfrac{1}{1 + e^{-x}}, the sigmoidCheck: y′=e−x(1+e−x)2=y(1−y)y' = \tfrac{e^{-x}}{(1 + e^{-x})^2} = y(1 - y). Separating with partial fractions gives the same answer; the substitution avoids the partial fractions.

Where this goes wrong

1. Finding μ before the standard form

The integrating factor is computed from the equation exactly as it is written.

  1. xy′+2y=x2xy' + 2y = x^2Right so far: Problem 3.
  2. “The coefficient of yy is 22, so μ=e∫2 dx\mu = e^{\int2\,dx}.”The habit that causes the mistake: PP read off before dividing by the coefficient of y′y'.
  3. μ=e2x\mu = e^{2x}Multiplying by e2xe^{2x} gives xe2xy′+2e2xyxe^{2x}y' + 2e^{2x}y, but (e2xy)′=e2xy′+2e2xy(e^{2x}y)' = e^{2x}y' + 2e^{2x}y, so the left side is not a derivative and nothing can be integrated. Divide by xx first: P=2xP = \tfrac2x, μ=x2\mu = x^2, and y=x24+34x2y = \tfrac{x^2}4 + \tfrac{3}{4x^2}, with y(2)=1916y(2) = \tfrac{19}{16}.

2. Multiplying only the left side by μ

The factor is there to make the left side a derivative, so it is easy to apply it there and nowhere else.

  1. μ=e2x\mu = e^{2x} and (e2xy)′=e2xy′+2e2xy(e^{2x}y)' = e^{2x}y' + 2e^{2x}yRight so far: Problem 1.
  2. “So (e2xy)′=6(e^{2x}y)' = 6.”The habit that causes the mistake: the right side left as it was.
  3. e2xy=6x+Ce^{2x}y = 6x + C, and y(0)=1y(0) = 1 gives y=(6x+1)e−2xy = (6x + 1)e^{-2x}At x=1x = 1 this gives 7e−2≈0.9477e^{-2} \approx 0.947, while the solution is 3−2e−2≈2.7293 - 2e^{-2} \approx 2.729. It also decays to 00 rather than settling at 33. The right side must be multiplied as well: (e2xy)′=6e2x(e^{2x}y)' = 6e^{2x}.

3. Dropping the sign of P

μ=e∫P\mu = e^{\int P} is remembered as an exponential of the coefficient, and its sign is lost.

  1. y′−y=e2xy' - y = e^{2x}Right so far: Problem 2, where P=−1P = -1.
  2. “μ=ex\mu = e^{x}.”The habit that causes the mistake: the coefficient taken as 11 instead of −1-1.
  3. (exy)′=e3x(e^xy)' = e^{3x}, so y=13(e2x−e−x)y = \tfrac13\big(e^{2x} - e^{-x}\big)(exy)′=ex(y′+y)(e^xy)' = e^x(y' + y), not ex(y′−y)e^x(y' - y). Check the result: at x=1x = 1, y′−y=13(e2+2e−1)≈2.708y' - y = \tfrac13\big(e^2 + 2e^{-1}\big) \approx 2.708, but e2≈7.389e^2 \approx 7.389. With μ=e−x\mu = e^{-x} the answer is y=e2x−exy = e^{2x} - e^x.

4. Adding the constant after dividing by μ

The constant of integration is added on the last line, as for a plain antiderivative.

  1. (exy)′=xex(e^xy)' = xe^x, so exy=(x−1)exe^xy = (x - 1)e^xRight so far, apart from the constant: Problem 4, step 3.
  2. “Divide by exe^x, then add CC.”The habit that causes the mistake: the constant belongs to the integration, before the division.
  3. y=x−1+Cy = x - 1 + C, and y(0)=0y(0) = 0 gives y=xy = xCheck: y′+y=1+xy' + y = 1 + x, not xx. The constant has to be divided by μ\mu too: y=x−1+Ce−xy = x - 1 + Ce^{-x}, and the solution is y=x−1+e−xy = x - 1 + e^{-x}.

5. Holding a changing volume constant

Mixing problems usually have equal inflow and outflow, so the volume is taken as fixed.

  1. Q′=6−(concentration)⋅1Q' = 6 - (\text{concentration})\cdot1Right so far: Problem 9, where 22 L/min flows in and 11 L/min flows out.
  2. “The concentration is Q20\tfrac{Q}{20}.”The habit that causes the mistake: the starting volume used for all time.
  3. Q′=6−Q20Q' = 6 - \tfrac{Q}{20}, so Q=120(1−e−t/20)Q = 120\big(1 - e^{-t/20}\big) and Q(20)≈75.85Q(20) \approx 75.85 gThe tank gains 11 L every minute, so at t=20t = 20 it holds 4040 L, not 2020, and less salt leaves than this assumes. With V=20+tV = 20 + t the answer is 9090 g.

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

Read the guide: Linear differential equations: standard form, the integrating factor, then integrate both sides