Integrating Factor Method to Solve Differential Equations

A tutorial using the method of the integrating factor to solve first order differential equations is presented along with examples and their detailed solutions, and also exercises with answers.

The general form of the first order linear differential equation is as follows \[ \dfrac{dy}{dx} + P(x) y = Q(x) \] where \( P(x) \) and \( Q(x) \) are functions of \( x \).
If we multiply all terms in the differential equation given above by an unknown function \( u(x) \), the equation becomes
\[ u(x) \dfrac{dy}{dx} + u(x) P(x) y = u(x) Q(x) \]
The left-hand side in the above equation has a term \( u \dfrac{dy}{dx} \); we might think of writing the whole left-hand side \( u(x) \dfrac{dy}{dx} + u(x) P(x) y \) of the equation as \( \dfrac{d(uy)}{dx} \). Using the product rule of derivatives, we obtain \[ \dfrac{d(uy)}{dx} = y \dfrac{du}{dx} + u \dfrac{dy}{dx} \] For \( y \dfrac{du}{dx} + u \dfrac{dy}{dx} \) and \( u(x) \dfrac{dy}{dx} + u(x) P(x) y \) to be equal, we need to have \[ y \dfrac{du}{dx} + u \dfrac{dy}{dx} = u(x) \dfrac{dy}{dx} + u(x) P(x) y \] Compare the two sides of the above equation to obtain \[ y \dfrac{du}{dx} = u(x) P(x) y \] Divide both sides by \( y \) to obtain \[ \dfrac{du}{dx} = u(x) P(x) \] Which may be written as \[ \dfrac{1}{u} \dfrac{du}{dx} = P(x) \] Integrate both sides to obtain \[ \ln(u) = \int P(x) \,dx \] Solve the above for \( u \) to obtain \[ u(x) = e^{ \int P(x) \,dx} \] \( u(x) \) is called the integrating factor. A solution for the unknown function \( u \) has been found. This will help in solving the differential equations. \[ \dfrac{d(uy)}{dx} = u(x) Q(x) \] Integrate both sides to obtain \[ u(x) y = \int u(x) Q(x) \,dx \] Finally, solve for \( y \) to obtain \[ y = \dfrac{1}{u(x)} \int u(x) Q(x) \,dx \]


Examples with Solutions

Example 1: Solve the differential equation

\( \dfrac{dy}{dx} - 2xy = x \)

Solution to Example 1
Comparing the given differential equation with the general first-order differential equation, we have
\( P(x) = -2x \) and \( Q(x) = x \)
Let us now find the integrating factor \( u(x) \)
\( u(x) = e^{\int P(x) \,dx} \)
\( = e^{\int -2x \,dx} \)
\( = e^{-x^2} \)
We now substitute \( u(x) = e^{-x^2} \) and \( Q(x) = x \) in the equation \( u(x) y = \int u(x) Q(x) \,dx \) to obtain
\( e^{-x^2}y = \int xe^{-x^2} \,dx \)
Integrate the right-hand term to obtain
\( e^{-x^2}y = -\dfrac{1}{2}e^{-x^2} + C \), \( C \) is a constant of integration.
Solve the above for \( y \) to obtain
\( y = Ce^{x^2} - \dfrac{1}{2} \)
As a practice, find \( \dfrac{dy}{dx} \) and substitute \( y \) and \( \dfrac{dy}{dx} \) in the given equation to check that the solution found is correct.


Example 2: Solve the differential equation

\( \dfrac{dy}{dx} + \dfrac{y}{x} = -2 \) for \( x > 0 \)

Solution to Example 2
We first find \( P(x) \) and \( Q(x) \)
\( P(x) = \dfrac{1}{x} \) and \( Q(x) = -2 \)
The integrating factor \( u(x) \) is given by
\( u(x) = e^{\int P(x) \,dx} \)
\( = e^{\int \dfrac{1}{x} \,dx} \)
\( = e^{\ln |x|} = |x| = x \) since \( x > 0 \).
We now substitute \( u(x) = x \) and \( Q(x) = -2 \) in the equation \( u(x) y = \int u(x) Q(x) \,dx \) to obtain
\( xy = \int -2x \,dx \)
Integrate the right-hand term to obtain
\( xy = -x^2 + C \), \( C \) is a constant of integration.
Solve the above for \( y \) to obtain
\( y = \dfrac{C}{x} - x \)
As an exercise find \( \dfrac{dy}{dx} \) and substitute \( y \) and \( \dfrac{dy}{dx} \) in the given equation to check that the solution found is correct.


Example 3: Solve the differential equation
\[ x \dfrac{dy}{dx} + y = -x^3 \quad \text{for} \; x > 0 \]

Solution to Example 3
We first divide all terms of the equation by \( x \) to obtain
\( \dfrac{dy}{dx} + \dfrac{y}{x} = -x^2 \)
We now find \( P(x) \) and \( Q(x) \)
\( P(x) = \dfrac{1}{x} \) and \( Q(x) = -x^2 \)
The integrating factor \( u(x) \) is given by
\( u(x) = e^{\int P(x) \,dx} \)
\( = e^{\int \dfrac{1}{x} \,dx} \)
\( = e^{\ln |x|} = |x| = x \) since \( x > 0 \).
We now substitute \( u(x) = x \) and \( Q(x) = -x^2 \) in the equation \( u(x) y = \int u(x) Q(x) \,dx \) to obtain
\( xy = \int -x^3 \,dx \)
Integration of the right-hand term yields
\( xy = -\dfrac{x^4}{4} + C \), \( C \) is a constant of integration.
Solve the above for \( y \) to obtain
\( y = \dfrac{C}{x} - \dfrac{x^3}{4} \)
As an exercise, find \( \dfrac{dy}{dx} \) and substitute \( y \) and \( \dfrac{dy}{dx} \) in the given equation to check that the solution found is correct.
NOTE: If you can "see" that the right-hand side of the given equation
\( x \dfrac{dy}{dx} + y = -x^3 \)
can be written as \( \dfrac{d(xy)}{dx} \), the solution can be found easily as follows
\( \dfrac{d(xy)}{dx} = -x^3 \)
Integrate both sides to obtain
\( xy = -\dfrac{x^4}{4} + C \).
Then solve for \( y \) to obtain
\( y = -\dfrac{x^3}{4} + \dfrac{C}{x} \)


Exercises

Solve the following differential equations.
1. \( \dfrac{dy}{dx} + y = 2x + 5 \)
2. \( \dfrac{dy}{dx} + y = x^4 \)
Answers to Above Exercises
1. \( y = 2x + 3 + Ce^{-x} \), \( C \) constant of integration.
2. \( y = x^4 - 4x^3 + 12x^2 - 24x + Ce^{-x} + 24 \), \( C \) a constant of integration.

More references on Differential Equations
Differential Equations - Runge Kutta Method