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 y and y′ appear only to the first power, with coefficients that may depend on :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′ so the equation reads .y′+P(x)y=Q(x).P is the coefficient of yafter this division, sign included.
Integrating factor.,μ(x)=e∫P(x)dx, with no constant needed. It is chosen so that ,μ′=Pμ, and then μy′+Pμy=(μy)′ by the product rule.
The solution. Multiply both sides by :μ:.(μy)′=μQ. Integrate, ,μy=∫μQdx+C, and only then divide by :μ:.y=μ1(∫μQdx+C). The constant ends up multiplied by .μ1.
Structure. The solution is one particular solution plus ,μC, the general solution of .y′+Py=0. When P is a positive constant, μC=Ce−Px is a transient that dies out.
Mixing problems. If Q(t) is the amount of salt and V(t) the volume, .Q′=(rate in)−V(t)Q⋅(outflow rate).V is constant only if inflow and outflow are equal.
Bernoulli equations.y′+Py=Qyn becomes linear in .v=y1−n.
Solve y′+(tanx)y=cosx on ,−2π<x<2π, with .y(0)=1.
··
Solve y′+2xy=x with ,y(0)=0, with an integrating factor and then by separating.
··
A tank holds 100 L of water with 10 kg of salt dissolved in it. Brine with 0.2 kg of salt per liter flows in at 5 L/min, and the well-mixed solution flows out at 5 L/min. Find the salt ,Q(t), its value at ,t=20, and when it reaches 19 kg.
···
A first-order filter, the continuous version of an exponential moving average, obeys ,y′+y=sinx, with .y(0)=0. Solve it, and describe the solution for large .x.
···
A tank starts with 20 L of pure water. Brine with 3 g of salt per liter flows in at 2 L/min, and the mixture flows out at 1 L/min. Find the salt ,Q(t), and the amount and concentration at t=20 min.
···
Solve the logistic equation y′=y−y2 with y(0)=21 by the substitution .v=y1.
Answers
y=3−2e−2x
y=e2x−ex
y=4x2+4x23
y=x−1+e−x
y=(x+1)cosx
y=21(1−e−x2)
;Q=20−10e−t/20;Q(20)≈16.32 kg; 19 kg at t=20ln10≈46.05 min
;y=21(sinx−cosx)+21e−x; for large ,x,y≈21sin(x−4π)
;Q=3(20+t)−20+t1200; at ,t=20,90 g in 40 L, or 2.25 g/L
,y=1+e−x1, the sigmoid
Worked solutions
Problem 1
Solve y′+2y=6 with .y(0)=1.
μ=e∫2dx=e2xAlready in standard form, with .P=2.
(e2xy)′=6e2xMultiply both sides by ;μ; the left side is now a product's derivative.
e2xy=3e2x+CIntegrate both sides.
,y=3+Ce−2x, and y(0)=3+C=1 gives C=−2Divide by ,μ, then use the initial condition.
y=3−2e−2xCheck: y′=4e−2x and .y′+2y=4e−2x+6−4e−2x=6. The solution rises toward the equilibrium .y=3.
Problem 2
Solve y′−y=e2x with .y(0)=0.
,P=−1, so μ=e−xThe sign of P goes into the exponent.
(e−xy)′=e−xe2x=exMultiply both sides by .e−x.
,e−xy=ex+C, so y=e2x+CexIntegrate, then divide by ,e−x, which multiplies by .ex.
y(0)=1+C=0 gives C=−1The initial condition.
y=e2x−exCheck: .y′−y=(2e2x−ex)−(e2x−ex)=e2x.
Problem 3
Solve xy′+2y=x2 for ,x>0, with .y(1)=1.
y′+x2y=xDivide by x to reach standard form; now .P=x2.
μ=e∫2/xdx=e2lnx=x2For ,x>0,.ln∣x∣=lnx.
(x2y)′=x2⋅x=x3Multiply the standard form by .x2. This is the original equation multiplied by .x.
,x2y=4x4+C, and 1=41+C gives C=43Integrate, then use .y(1)=1.
y=4x2+4x23Check: xy′=2x2−2x23 and ,2y=2x2+2x23, which add to .x2. For example .y(2)=1+163=1619.
Problem 4
Solve y′+y=x with .y(0)=0.
,μ=ex, so (exy)′=xex.P=1.
∫xexdx=xex−exBy parts with ,u=x,.dv=exdx.
,exy=(x−1)ex+C, so y=x−1+Ce−xAdd the constant before dividing by .ex.
y(0)=−1+C=0 gives C=1The initial condition.
y=x−1+e−xCheck: .y′+y=(1−e−x)+(x−1+e−x)=x. For large x the solution follows the line ,y=x−1, one unit behind the input.
Problem 5
Solve y′+(tanx)y=cosx on ,−2π<x<2π, with .y(0)=1.
,∫tanxdx=−ln∣cosx∣, so μ=e−lncosx=cosx1=secxcosx>0 on this interval.
(ysecx)′=cosxsecx=1Multiply both sides by .secx.
,ysecx=x+C, so y=(x+C)cosxIntegrate, then multiply by .cosx.
y=(x+1)cosx.y(0)=C=1. Check: y′=cosx−(x+1)sinx and ,ytanx=(x+1)sinx, which add to .cosx.
Problem 6
Solve y′+2xy=x with ,y(0)=0, with an integrating factor and then by separating.
,μ=e∫2xdx=ex2, so (ex2y)′=xex2.P=2x.
,ex2y=21ex2+C, so ,y=21+Ce−x2, and C=−21∫xex2dx=21ex2 by .u=x2.
Separating: ,y′=x(1−2y), so 1−2ydy=xdx and −21ln∣1−2y∣=2x2+cHere the right side factors, so this one is separable as well.
1−2y=Ae−x2 with A=1 from y(0)=0The same family.
y=21(1−e−x2)Both methods agree, as they must. With ,P=0, an equation y′+Py=Q is separable exactly when PQ is a constant; here it is ,21, the value y settles at.
Problem 7
A tank holds 100 L of water with 10 kg of salt dissolved in it. Brine with 0.2 kg of salt per liter flows in at 5 L/min, and the well-mixed solution flows out at 5 L/min. Find the salt ,Q(t), its value at ,t=20, and when it reaches 19 kg.
Q′=0.2⋅5−100Q⋅5=1−20QIn: 1 kg/min. Out: the concentration 100Q times 5 L/min. The volume stays at 100 L.
,Q′+20Q=1,,μ=et/20,(et/20Q)′=et/20Standard form with .P=201.
,et/20Q=20et/20+C, so ,Q=20+Ce−t/20, and Q(0)=10 gives C=−10Integrate, divide, apply .Q(0).
;Q(20)=20−10e−1;Q=19 when ,10e−t/20=1,t=20ln10The gap to 20 kg shrinks by a factor of e every 20 minutes.
;Q=20−10e−t/20;Q(20)≈16.32 kg; 19 kg at t=20ln10≈46.05 minIn the long run the tank holds 100×0.2=20 kg, the inflow concentration.
Problem 8
A first-order filter, the continuous version of an exponential moving average, obeys ,y′+y=sinx, with .y(0)=0. Solve it, and describe the solution for large .x.
,μ=ex,(exy)′=exsinx.P=1.
∫exsinxdx=2ex(sinx−cosx)By parts twice, solving for the integral when it reappears.
,y=2sinx−cosx+Ce−x, and y(0)=−21+C=0 gives C=21Divide by ex and apply .y(0)=0.
;y=21(sinx−cosx)+21e−x; for large ,x,y≈21sin(x−4π)The transient 21e−x dies out. What is left follows the input with its amplitude cut to 21≈0.707 and a lag of :4π: smoothing always costs delay, which is the tradeoff in choosing an EMA's decay rate.
Problem 9
A tank starts with 20 L of pure water. Brine with 3 g of salt per liter flows in at 2 L/min, and the mixture flows out at 1 L/min. Find the salt ,Q(t), and the amount and concentration at t=20 min.
V(t)=20+tThe volume grows by 2−1=1 L/min.
Q′=3⋅2−20+tQ⋅1=6−20+tQThe outflow concentration is ,V(t)Q, with the current volume.
,μ=e∫dt/(20+t)=20+t, so ((20+t)Q)′=6(20+t).P=20+t1.
,(20+t)Q=3(20+t)2+C, and Q(0)=0 gives C=−1200;∫6(20+t)dt=3(20+t)2; at ,t=0,.0=1200+C.
;Q=3(20+t)−20+t1200; at ,t=20,90 g in 40 L, or 2.25 g/L.Q(20)=120−30. The concentration approaches 3 g/L, the inflow's, as the tank grows.
Problem 10
Solve the logistic equation y′=y−y2 with y(0)=21 by the substitution .v=y1.
v′=−y2y′=−y2y−y2=1−vA Bernoulli equation with ,n=2, so .v=y1−2=y1.
,v′+v=1,,μ=ex, so exv=ex+C and v=1+Ce−xLinear in ,v, with .P=1.
v(0)=2 gives C=1.v(0)=y(0)1.
,y=1+e−x1, the sigmoidCheck: .y′=(1+e−x)2e−x=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.
xy′+2y=x2Right so far: Problem 3.
“The coefficient of y is ,2, so .μ=e∫2dx.”The habit that causes the mistake: P read off before dividing by the coefficient of .y′.
μ=e2xMultiplying by e2x gives ,xe2xy′+2e2xy, but ,(e2xy)′=e2xy′+2e2xy, so the left side is not a derivative and nothing can be integrated. Divide by x first: ,P=x2,,μ=x2, and ,y=4x2+4x23, with .y(2)=1619.
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.
μ=e2x and (e2xy)′=e2xy′+2e2xyRight so far: Problem 1.
“So .(e2xy)′=6.”The habit that causes the mistake: the right side left as it was.
,e2xy=6x+C, and y(0)=1 gives y=(6x+1)e−2xAt x=1 this gives ,7e−2≈0.947, while the solution is .3−2e−2≈2.729. It also decays to 0 rather than settling at .3. The right side must be multiplied as well: .(e2xy)′=6e2x.
3. Dropping the sign of P
μ=e∫P is remembered as an exponential of the coefficient, and its sign is lost.
y′−y=e2xRight so far: Problem 2, where .P=−1.
“.μ=ex.”The habit that causes the mistake: the coefficient taken as 1 instead of .−1.
,(exy)′=e3x, so y=31(e2x−e−x),(exy)′=ex(y′+y), not .ex(y′−y). Check the result: at ,x=1,,y′−y=31(e2+2e−1)≈2.708, but .e2≈7.389. With μ=e−x the answer is .y=e2x−ex.
4. Adding the constant after dividing by μ
The constant of integration is added on the last line, as for a plain antiderivative.
,(exy)′=xex, so exy=(x−1)exRight so far, apart from the constant: Problem 4, step 3.
“Divide by ,ex, then add .C.”The habit that causes the mistake: the constant belongs to the integration, before the division.
,y=x−1+C, and y(0)=0 gives y=xCheck: ,y′+y=1+x, not .x. The constant has to be divided by μ too: ,y=x−1+Ce−x, and the solution is .y=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.
Q′=6−(concentration)⋅1Right so far: Problem 9, where 2 L/min flows in and 1 L/min flows out.
“The concentration is .20Q.”The habit that causes the mistake: the starting volume used for all time.
,Q′=6−20Q, so Q=120(1−e−t/20) and Q(20)≈75.85 gThe tank gains 1 L every minute, so at t=20 it holds 40 L, not ,20, and less salt leaves than this assumes. With V=20+t the answer is 90 g.