# Variation of Parameters

When we know the solutions of a linear differential equation with constant coefficients and right hand side equal to zero, we can use variation of parameters to find a solution when the right hand side is not equal to zero.

This post is part of a series.

When we know the zero solutions $y_0$ of a differential equation $y’^\prime+a_1(x)y’+a_0(x)y=f(x)$, we can use a method called variation of parameters to find the particular solution. This method is especially useful in cases where we are unable to guess the particular solution through undetermined coefficients.

## Derivation

Variation of parameters is similar to undetermined coefficients in that we guess a solution form that is relevant to the differential equation, and adjust it as needed to solve the differential equation.

However, variation of parameters is more general: the guess is of the form $y_f(x)=u_1(x)y_1(x)+u_2(x)y_2(x)$, where $y_1$ and $y_2$ are the two zero solutions of the differential equation $y’^\prime+a_1(x)y’+a_0(x)y=0$, and $u_1(x)$ and $u_2(x)$ are some unknown multiplier functions for which we need to solve.

If we also force $y_f’(x)=u_1(x)y_1’(x)+u_2(x)y_2’(x)$, then we can set up a system of equations to solve for $u_1$ and $u_2$. (To be clear, the formula for $y_f’$ does not come from differentiating – rather, it is a condition that we force, so that we obtain a solvable system of equations.)

The first equation comes from differentiating $y_f$:

\begin{align*} y_f' &= u_1 y_1' + u_2 y_2' \\ (u_1y_1 + u_2y_2)' &= u_1 y_1' + u_2 y_2' \\ u_1'y_1 + u_1y_1' + u_2'y_2 + u_2y_2' &= u_1 y_1' + u_2 y_2' \\ u_1'y_1 + u_2'y_2 &= 0 \end{align*}

The second equation comes from substituting our guess for $y_f$ into the differential equation and simplifying, using the fact that $y_1$ and $y_2$ are the zero solutions.

\begin{align*} f &= y_f'' + a_1 y_f' + a_0 y_f \\ f &= (u_1 y_1' + u_2 y_2')' + a_1 (u_1 y_1' + u_2 y_2') + a_0 (u_1 y_1 + u_2 y_2) \\ f &= (u_1' y_1' + u_1 y_1'' + u_2' y_2' + u_2 y_2'') + a_1 (u_1 y_1' + u_2 y_2') + a_0 (u_1 y_1 + u_2 y_2) \\ f &= (u_1)(y_1''+a_1y_1'+a_0y_1) + (u_2)(y_2''+a_1y_2'+a_0y_2) + u_1'y_1' + u_2'y_2' \\ f &= (u_1)(0) + (u_2)(0) + u_1'y_1' + u_2'y_2' \\ f &= u_1'y_1' + u_2'y_2' \end{align*}

Our resulting system

\begin{align*} \begin{cases} u_1'y_1 + u_2'y_2 = 0 \\ u_1'y_1' + u_2'y_2' = f \end{cases} \end{align*}

is solved by

\begin{align*} u_1' &= -\frac{y_2f}{y_1y_2'-y_2y_1'} \\ u_2' &= \frac{y_1f}{y_1y_2'-y_2y_1'} \, . \end{align*}

Integrating, we have

\begin{align*} u_1 &= -\int \frac{y_2f}{y_1y_2'-y_2y_1'} \, dx \\ u_2 &= \int \frac{y_1f}{y_1y_2'-y_2y_1'} \, dx \, . \end{align*}

The particular solution is then

\begin{align*} y_f &= u_1y_1 + u_2y_y \\ &= - y_1 \int \frac{y_2f}{y_1y_2'-y_2y_1'} \, dx + y_2 \int \frac{y_1f}{y_1y_2'-y_2y_1'} \, dx . \end{align*}

## Demonstration

For example, to solve the differential equation $y’^\prime=2y’+y=\frac{e^x}{x}$, we start by solving $y’^\prime-2y’+y=0$ to find the zero solutions $y_1=e^x$ and $y_2 = xe^x$. After computing

\begin{align*} y_1y_2'-y_2y_1' &= e^x(e^x+xe^x)-xe^x(e^x) \\ &= e^{2x} \end{align*}

we are able to compute $u_1$ and $u_2$:

\begin{align*} u_1 &= -\int \frac{y_2 f}{y_1y_2'-y_2y_1'} \, dx \\ &= - \int \frac{xe^x \left( \frac{e^x}{x} \right) }{e^{2x} } \, dx \\ &= -\int 1 \, dx \\ &= -x \end{align*}

\begin{align*} u_2 &= \int \frac{y_1 f}{y_1y_2'-y_2y_1'} \, dx \\ &= \int \frac{e^x \left( \frac{e^x}{x} \right) }{e^{2x} } \, dx \\ &= \int \frac{1}{x} \, dx \\ &= \ln x \end{align*}

We can then compute the particular solution:

\begin{align*} y_f &= u_1 y_1 + u_2 y_2 \\ &= (-x)(e^x) + ( \ln x)(xe^x) \\ &= -xe^{x} + x e^{x} \ln x \\ &= xe^{x} ( \ln x - 1) \end{align*}

Finally, we can write the full solution, and lump any constant terms to eliminate redundancy.

\begin{align*} y &= y_0 + y_f \\ &= (C_1+C_2x)e^x + e^{x}(x \ln x - 1) \\ &= (C_1+C_2x + x \ln x)e^x \end{align*}

## Another Demonstration

As another example, we solve the differential equation $y’^\prime-y’=xe^x \sin x$ in the same way. The zero solutions to $y’^\prime-y’=0$ are $y_1=e^x$ and $y_2=1$, and we have

\begin{align*} y_1y_2' - y_2y_1' &= (e^x)(0)-(1)(e^x) \\ &= -e^x \, . \end{align*}

Computing $u_1$ and $u_2$, we have

\begin{align*} u_1 &= -\int \frac{y_2 f}{y_1y_2'-y_2y_1'} \, dx \\ &= - \int \frac{xe^x \sin x }{-e^{x} } \, dx \\ &= \int x \sin x \, dx \\ &= \sin x - x \cos x \end{align*}

\begin{align*} u_2 &= \int \frac{y_1 f}{y_1y_2'-y_2y_1'} \, dx \\ &= \int \frac{e^x \cdot x e^x \sin x }{-e^{x} } \, dx \\ &= -\int x e^x \sin x \, dx \\ &= \frac{1}{2}e^x \left( x \cos x - x \sin x - \cos x \right). \end{align*}

We can then compute the particular solution:

\begin{align*} y_f &= u_1 y_1 + u_2 y_2 \\ &= (\sin x - x \cos x)e^x + \frac{1}{2}e^x ( x \cos x - x \sin x - \cos x) \\ &= \frac{1}{2}e^x \left( 2 \sin x - x \cos x - x \sin x - \cos x \right) \end{align*}

Finally, we can write the full solution, and lump any constant terms to eliminate redundancy.

\begin{align*} y &= y_0 + y_f \\ &= C_1 e^x + C_2 + \frac{1}{2}e^x \left( 2 \sin x - x \cos x - x \sin x - \cos x \right) \\ &= C_2 + \frac{1}{2}e^x \left( C_1 + 2 \sin x - x \cos x - x \sin x - \cos x \right) \end{align*}

## Exercises

Use variation of parameters to solve the following differential equations. (You can view the solution by clicking on the problem.)

\begin{align*} 1) \hspace{.5cm} y'' - 2y' + y = \frac{e^x}{x^2} \end{align*}
Solution:
\begin{align*} y = e^x \left( C_1 + C_2x - \ln x \right) \end{align*}

\begin{align*} 2) \hspace{.5cm} y'' - 2y' + y = e^x \ln x \end{align*}
Solution:
\begin{align*} y = \frac{1}{4}e^x \left( C_1 + C_2 x - 3x^2 + 2x^2 \ln x \right) \end{align*}

\begin{align*} 3) \hspace{.5cm} y'' - 4y = \frac{1}{1+e^{2x}} \end{align*}
Solution:
\begin{align*} y = \frac{1}{8}e^{2x} \left[ C_1 + \ln \left( e^{-2x}+1 \right) \right] - \frac{1}{8}e^{-2x} \left[ C_1 + \ln \left( e^{2x}+1 \right) \right] - \frac{1}{8} \end{align*}

\begin{align*} 4) \hspace{.5cm} y'' + 2y' + y = \frac{1}{(1+x^2)e^x} \end{align*}
Solution:
\begin{align*} y = \frac{1}{2}e^{-x} \left[ C_1 + C_2 x - \ln (1+x^2) + 2x \arctan x \right] \end{align*}

\begin{align*} 5) \hspace{.5cm} y'' + y = xe^x \cos x \end{align*}
Solution:
\begin{align*} y = C_1 \cos x + C_2 \sin x + \frac{1}{25}e^x \left[ (10x-14) \sin x + (5x-2) \cos x \right] \end{align*}

\begin{align*} 6) \hspace{.5cm} y'' - y' = x^2 e^x \sin x \end{align*}
Solution:
\begin{align*} y = C_1 + \frac{1}{2}e^x \left[ C_2 + (-x^2+4x+1)\sin x + (-x^2-2x+5) \cos x \right] \end{align*}

This post is part of a series.

Tags: