Integrating Factor Method

lean4-proofdifferential-equationsvisualization
μ(x)=ep(x)dx,(μy)=μq\mu(x)=e^{\int p(x)\,dx},\quad (\mu y)'=\mu q

Statement

The first-order linear ODE

y+p(x)y=q(x)y' + p(x)\,y = q(x)

is solved by choosing the integrating factor μ(x)=ep(x)dx\mu(x) = e^{\int p(x)\,dx}. Multiplying both sides gives

(μy)=μq(\mu y)' = \mu q

which integrates to

y(x)=1μ(x) ⁣(μ(x)q(x)dx+C)y(x) = \frac{1}{\mu(x)}\!\left(\int \mu(x)\,q(x)\,dx + C\right)

Worked example: y+y=exy' + y = e^x. Here p1p \equiv 1, so μ=ex\mu = e^x.

exy+exy=e2x    (exy)=e2xe^x y' + e^x y = e^{2x} \implies (e^x y)' = e^{2x}

Integrating: exy=12e2x+Ce^x y = \tfrac{1}{2}e^{2x} + C, giving y=12ex+Cexy = \tfrac{1}{2}e^x + Ce^{-x}.

Visualization

Solution to y+2xy=xy' + 2xy = x with y(0)=0y(0) = 0:

Integrating factor: μ=ex2\mu = e^{x^2}. Then (ex2y)=xex2(e^{x^2} y)' = x e^{x^2}, integrating:

y(x)=12+Cex2,y(0)=0    C=12y(x) = \frac{1}{2} + Ce^{-x^2}, \qquad y(0) = 0 \implies C = -\tfrac{1}{2}
y(x)=12(1ex2)y(x) = \frac{1}{2}(1 - e^{-x^2})
xxex2e^{-x^2}y(x)=12(1ex2)y(x) = \tfrac{1}{2}(1-e^{-x^2})
0.01.0000.000
0.50.7790.111
1.00.3680.316
1.50.1050.448
2.00.0180.491
3.00.0000.500

The solution rises from 00 and saturates at y=1/2y = 1/2 as xx \to \infty — controlled by the Gaussian decay in ex2e^{-x^2}.

Proof Sketch

  1. Define μ(x)=ex0xp(s)ds\mu(x) = e^{\int_{x_0}^x p(s)\,ds}. Then μ=pμ\mu' = p\mu.
  2. Product rule. (μy)=μy+μy=pμy+μ(qpy)=μq(\mu y)' = \mu' y + \mu y' = p\mu y + \mu(q - py) = \mu q.
  3. Integrate. μ(x)y(x)=x0xμ(s)q(s)ds+C\mu(x) y(x) = \int_{x_0}^x \mu(s) q(s)\,ds + C.
  4. Divide by μ(x)0\mu(x) \neq 0. (Exponential is always positive.) This gives the explicit formula.

The key identity is the product rule from the Fundamental Theorem of CalculusFundamental Theorem of Calculusabf(x)dx=f(b)f(a)\int_a^b f'(x)\,dx = f(b) - f(a)Integration and differentiation are inverse operationsRead more → and the chain rule μ=pμ\mu' = p\mu.

Connections

The integrating factor epe^{\int p} is the scalar instance of the matrix exponential in Linear ODE General SolutionLinear ODE General Solutiony(t)=eAty0 solves y=Ay,  y(0)=y0y(t) = e^{At}y_0 \text{ solves } y' = Ay,\; y(0)=y_0The matrix exponential e^{At} gives the unique solution to y' = Ay with initial condition y(0) = y_0.Read more →; the product rule step mirrors the computation in Chain RuleChain Ruleddx[f(g(x))]=f(g(x))g(x)\frac{d}{dx}[f(g(x))] = f'(g(x)) \cdot g'(x)Differentiate composite functions by peeling layersRead more →.

Lean4 Proof

import Mathlib.Analysis.SpecialFunctions.ExpDeriv

/-!
  We verify the integrating factor identity for y' + y = eˣ.
  The claim: y(x) = (1/2)*exp(x) + C*exp(-x) satisfies y' + y = exp(x).
  We verify this by direct differentiation using `ring` after collecting
  derivative facts.
-/

/-- For any constant C, y(x) = (1/2)*exp(x) + C*exp(-x)
    satisfies y'(x) + y(x) = exp(x). -/
theorem integrating_factor_example (C : ) :
    let y  :    := fun x => (1/2) * Real.exp x + C * Real.exp (-x)
    let y' :    := fun x => (1/2) * Real.exp x - C * Real.exp (-x)
     x : , y' x + y x = Real.exp x := by
  intro y y' x
  simp only [y, y']
  ring

/-- The derivative of y(x) = (1/2)*exp(x) + C*exp(-x) equals y'(x). -/
theorem integrating_factor_deriv (C : ) (x : ) :
    HasDerivAt (fun x => (1/2 : ) * Real.exp x + C * Real.exp (-x))
               ((1/2) * Real.exp x - C * Real.exp (-x)) x := by
  have h1 := (Real.hasDerivAt_exp x).const_mul (1/2 : )
  have h2 := ((Real.hasDerivAt_exp (-x)).comp x
               (hasDerivAt_neg x)).const_mul C
  simp only [neg_neg] at h2
  convert h1.add h2 using 1
  ring