3. First-order linear equations and the integrating factor

📖 Reading · 9 min
💡 Every code box below is live — edit it and hit Run.

§13.1's separation technique failed on y'=x+y — a sum, not a product, of an x-piece and a y-piece. This lesson handles exactly that equation (and every equation shaped like it) with a different trick entirely: multiply both sides by a cleverly chosen function that turns the left side into something a single reverse-product-rule step can undo.

Standard form

A first-order linear equation can be written as

\frac{dy}{dx}+P(x)y=Q(x)

— "linear" because y and y' appear only to the first power, with no products like y\cdot y' or nonlinear terms like y^2. This form includes y'=x+y directly: rearranged, y'-y=x, matching the standard form with P(x)=-1, Q(x)=x.

The integrating factor

Multiply both sides by a function \mu(x), chosen so the left side collapses into the derivative of a single product \mu(x)y. By the product rule (§2.3):

\frac{d}{dx}\big[\mu(x)y\big]=\mu(x)y'+\mu'(x)y

Comparing this to \mu(x)y'+\mu(x)P(x)y (the left side of the equation after multiplying by \mu), the two match exactly when \mu'(x)=\mu(x)P(x) — a separable equation (§13.1) in \mu itself! Separating and integrating:

\frac{d\mu}\mu=P(x)\,dx\ \Longrightarrow\ \ln|\mu|=\int P(x)\,dx\ \Longrightarrow\ \boxed{\mu(x)=e^{\int P(x)\,dx}}

This \mu(x) is the integrating factor. Multiplying the original equation by it turns the left side into an exact derivative:

\frac{d}{dx}\big[\mu(x)y\big]=\mu(x)Q(x)

Integrating both sides and solving for y:

\mu(x)y=\int\mu(x)Q(x)\,dx+C\ \Longrightarrow\ y=\frac1{\mu(x)}\left(\int\mu(x)Q(x)\,dx+C\right)

The entire method is: compute \mu, multiply through, integrate, divide back out — a fixed four-step recipe that works for any first-order linear equation, regardless of whether it happens to be separable too.

Doing it in Python

Solving y'-y=x — exactly §13.0's equation, y'=x+y, rearranged into standard form — with the integrating factor method, and applying the initial condition y(0)=1:

import sympy as sp

x, C = sp.symbols('x C')
P, Q = -1, x   # standard form: y' + P(x)y = Q(x), so y' - y = x means P = -1

mu = sp.exp(sp.integrate(P, x))
print(f"integrating factor mu(x) = {mu}")

rhs_integral = sp.integrate(mu * Q, x)
print(f"integral of mu*Q dx = {rhs_integral}")

y_general = sp.simplify((rhs_integral + C) / mu)
print(f"general solution: y = {y_general}")

C_value = sp.solve(sp.Eq(y_general.subs(x, 0), 1), C)[0]
y_particular = sp.simplify(y_general.subs(C, C_value))
print(f"particular solution: y = {y_particular}")

Confirming this matches §13.0's Euler's-method approximation from the same initial value problem:

import sympy as sp

x = sp.Symbol('x')
y_exact = 2*sp.exp(x) - x - 1

exact_at_half = float(y_exact.subs(x, sp.Rational(1,2)))
euler_approx = 1.72102   # section 13.0's Euler's-method result at x=0.5, h=0.1

print(f"exact solution at x=0.5:  {exact_at_half:.5f}")
print(f"Euler's method (h=0.1):   {euler_approx}")
print(f"reasonably close, as expected for a coarse step size")

Solving a second linear equation, confirming the recipe generalizes:

import sympy as sp

x, C = sp.symbols('x C')
P, Q = 2, sp.exp(-x)   # y' + 2y = e^(-x)

mu = sp.exp(sp.integrate(P, x))
rhs_integral = sp.integrate(mu * Q, x)
y_general = sp.simplify((rhs_integral + C) / mu)
print(f"mu = {mu}")
print(f"general solution: y = {y_general}")

Worked example

Solve y'-y=x, y(0)=1, using the integrating factor.

Standard form: P(x)=-1, Q(x)=x.

\mu(x)=e^{\int-1\,dx}=e^{-x}

Multiply the equation by \mu:

e^{-x}y'-e^{-x}y=xe^{-x}\ \Longrightarrow\ \frac d{dx}\big[e^{-x}y\big]=xe^{-x}

Integrate both sides, using integration by parts (§4.6) on the right:

e^{-x}y=\int xe^{-x}\,dx=-xe^{-x}-e^{-x}+C

Divide by e^{-x} (multiply by e^x):

y=-x-1+Ce^x

Apply y(0)=1: 1=-0-1+C\Rightarrow C=2.

\boxed{y=2e^x-x-1}

Sanity check. This is exactly §13.0's exact solution, quoted there without derivation to check Euler's method against — now derived properly from first principles. Differentiate to double-check: y'=2e^x-1, and y'-y=(2e^x-1)-(2e^x-x-1)=x ✓, matching the original equation. And y(0)=2-0-1=1 ✓. Both loose ends from §13.0 are now tied off. ✓

Your turn

1. Find the integrating factor for y'+3y=e^{2x}.

2. Solve y'+3y=e^{2x}, y(0)=1, completely.

3. True or false: the integrating factor method only works when the equation is also separable.

Solutions

1. P(x)=3, so \mu(x)=e^{\int3\,dx}=\boxed{e^{3x}}.

2. Multiply by \mu=e^{3x}:

\frac d{dx}\big[e^{3x}y\big]=e^{3x}\cdot e^{2x}=e^{5x}

e^{3x}y=\int e^{5x}\,dx=\frac15e^{5x}+C

y=\frac15e^{2x}+Ce^{-3x}

Apply y(0)=1: 1=\frac15+C\Rightarrow C=\frac45.

\boxed{y=\frac15e^{2x}+\frac45e^{-3x}}

3. False. y'-y=x (this lesson's worked example) is not separable — its right side, x+y, doesn't factor into a product of an x-only and a y-only piece, exactly as §13.1 confirmed. The integrating factor method works for every first-order linear equation regardless of separability; it's a genuinely different technique, not a special case of separation. (Some equations, like y'=xy from §13.1, happen to be solvable by either method — but the integrating factor's real value is handling equations, like this lesson's, that separation can't touch at all.)

Check yourself in code

Solve y'-y=x, y(0)=1 using the integrating factor method.

Print exactly this:

mu(x) = exp(-x)
general solution: y = C*exp(x) - x - 1
particular solution: y = -x + 2*exp(x) - 1
import sympy as sp

x, C = sp.symbols('x C')
P, Q = -1, x

mu = sp.exp(sp.integrate(P, x))
print("mu(x) = ...")

rhs_integral = sp.integrate(mu * Q, x)
y_general = sp.simplify((rhs_integral + C) / mu)
print("general solution: y = ...")

C_value = sp.solve(sp.Eq(y_general.subs(x, 0), 1), C)[0]
y_particular = sp.simplify(y_general.subs(C, C_value))
print("particular solution: y = ...")
import sympy as sp

x, C = sp.symbols('x C')
P, Q = -1, x

mu = sp.exp(sp.integrate(P, x))
print(f"mu(x) = {mu}")

rhs_integral = sp.integrate(mu * Q, x)
y_general = sp.simplify((rhs_integral + C) / mu)
print(f"general solution: y = {y_general}")

C_value = sp.solve(sp.Eq(y_general.subs(x, 0), 1), C)[0]
y_particular = sp.simplify(y_general.subs(C, C_value))
print(f"particular solution: y = {y_particular}")

Every first-order linear equation, y'+P(x)y=Q(x), yields to the integrating factor \mu(x)=e^{\int P(x)\,dx}, chosen precisely so multiplying through collapses the left side into the single derivative \frac{d}{dx}[\mu y] via the product rule — after which integrating and dividing back out recovers y exactly, no approximation needed. This method reaches equations, like y'-y=x, that §13.1's separation technique cannot touch at all, and it finally supplies the exact solution §13.0 used to check Euler's method against.

Next: exact equations — a third first-order technique, built once more on §10.2's Clairaut's theorem, for equations that fit neither the separable nor the linear mold.