### Structure of the General Solution

The nonhomogeneous differential equation of this type has the form

\[{y^{\prime\prime} + py’ + qy }={ f\left( x \right),}\]

where \(p, q\) are constant numbers (that can be both as real as complex numbers). For each equation we can write the related homogeneous or complementary equation:

\[{y^{\prime\prime} + py’ + qy }={ 0.}\]

#### Theorem.

The general solution of a nonhomogeneous equation is the sum of the general solution \({y_0}\left( x \right)\) of the related homogeneous equation and a particular solution \({y_1}\left( x \right)\) of the nonhomogeneous equation:

\[{y\left( x \right) }={ {y_0}\left( x \right) + {y_1}\left( x \right).}\]

Below we consider two methods of constructing the general solution of a nonhomogeneous differential equation.

### Method of Variation of Constants

If the general solution \({y_0}\) of the associated homogeneous equation is known, then the general solution for the nonhomogeneous equation can be found by using the method of variation of constants.

Let the general solution of a second order homogeneous differential equation be

\[{{y_0}\left( x \right) }={ {C_1}{Y_1}\left( x \right) }+{ {C_2}{Y_2}\left( x \right).}\]

Instead of the constants \({C_1}\) and \({C_2}\) we will consider arbitrary functions \({C_1}\left( x \right)\) and \({C_2}\left( x \right).\) We will find these functions such that the solution

\[{y = {C_1}\left( x \right){Y_1}\left( x \right) }+{ {C_2}\left( x \right){Y_2}\left( x \right)}\]

satisfies the nonhomogeneous equation with the right side \(f\left( x \right).\)

The unknown functions \({C_1}\left( x \right)\) and \({C_2}\left( x \right)\) can be determined from the system of two equations:

\[\left\{ \begin{array}{l} {C’_1}\left( x \right){Y_1}\left( x \right) + {C’_2} \left( x \right){Y_2}\left( x \right) = 0\\ {C’_1} \left( x \right){Y’_1} \left( x \right) + {C’_2} \left( x \right){Y’_2} \left( x \right) = f\left( x \right) \end{array} \right.\]

### Method of Undetermined Coefficients

The right side \(f\left( x \right)\) of a nonhomogeneous differential equation is often an exponential, polynomial or trigonometric function or a combination of these functions. In this case, it’s more convenient to look for a solution of such an equation using the method of undetermined coefficients.

The given method works only for a restricted class of functions in the right side, such as

- \(f\left( x \right) \) \(= {P_n}\left( x \right){e^{\alpha x}};\)
- \(f\left( x \right) \) \(= \left[ {{P_n}\left( x \right)\cos\left( {\beta x} \right) }\right.\) \(\left.{+ {Q_m}\left( x \right)\sin\left( {\beta x} \right)} \right]{e^{\alpha x}},\) where \({{P_n}\left( x \right)}\) and \({{Q_m}\left( x \right)}\) are polynomials of degree \(n\) and \(m,\) respectively.

In both cases, a choice for the particular solution should match the structure of the right side of the nonhomogeneous equation.

In case \(1,\) if the power \(\alpha\) of the exponential function coincides with a root of the auxiliary characteristic equation, the particular solution will contain the additional factor \({x^s},\) where \(s\) is the order of the root \(\alpha\) in the characteristic equation.

In case \(2,\) if the number \(\alpha + \beta i\) coincides with a root of the characteristic equation, the expected expression for the particular solution should be multiplied by the additional factor \(x.\)

The unknown coefficients can be determined by substitution of the expected type of the particular solution into the original nonhomogeneous differential equation.

### Superposition Principle

If the right side of a nonhomogeneous equation is the sum of several functions of kind

\[

{{P_n}\left( x \right){e^{\alpha x}}\;\;\text{and/or}\;\;}\kern-0.3pt

{\left[ {{P_n}\left( x \right)\cos\left( {\beta x} \right) }\right.}+{\left.{ {Q_m}\left( x \right)\sin\left( {\beta x} \right)} \right]{e^{\alpha x}},}

\]

then a particular solution of the differential equation is also the sum of particular solutions constructed separately for each term in the right side.

## Solved Problems

Click or tap a problem to see the solution.

### Example 1

Solve the differential equation \(y^{\prime\prime} + y = \sin \left( {2x} \right).\)### Example 2

Find the general solution of the equation \(y^{\prime\prime} + y’ – 6y\) \( = 36x.\)### Example 3

Solve the differential equation \(y^{\prime\prime} – 5y’ + 4y \) \(= {e^{4x}}.\)### Example 4

Find the general solution of the equation \(y^{\prime\prime} + 9y \) \(= 2{x^2} – 5.\)### Example 5

Solve the differential equation \(y^{\prime\prime} + 16y \) \(= 2{\cos ^2}x.\)### Example 6

Solve the equation \(y^{\prime\prime} + y = {\sec ^2}x\) using the method of variation of constants.### Example 7

Find the solution of the differential equation \(y^{\prime\prime} – 7y’ + 12y \) \(= 8\sin x + {e^{3x}}.\)### Example 1.

Solve the differential equation \(y^{\prime\prime} + y = \sin \left( {2x} \right).\)Solution.

First we solve the related homogeneous equation \(y^{\prime\prime} + y = 0.\) The roots of the corresponding characteristic equation are purely imaginary:

\[

{{k^2} + 1 = 0,\;\;}\Rightarrow

{{k^2} = – 1,\;\;}\Rightarrow

{{k_{1,2}} = \pm i.}

\]

Hence, the general solution of the homogeneous equation is given by

\[{{y_0}\left( x \right) }={ {C_1}\cos x }+{ {C_2}\sin x.}\]

Let’s go back to the nonhomogeneous equation. We will seek for its solution in the form

\[{y\left( x \right) }={ {C_1}\left( x \right)\cos x }+{ {C_2}\left( x \right)\sin x,}\]

using the method of variation of constants.

The functions \({C_1}\left( x \right)\) and \({C_2}\left( x \right)\) can be determined from the following system of equations:

\[\left\{ \begin{array}{l} {{C’_1}\left( x \right)\cos x} + {{C’_2}\left( x \right)\sin x} = 0\\ {C’_1}\left( x \right){\left( {\cos x} \right)^\prime } + {C’_2}\left( x \right){\left( {\sin x} \right)^\prime } = {\sin 2x} \end{array} \right.\]

Then

\[\left\{ \begin{array}{l} {{C’_1}\left( x \right)\cos x} + {{C’_2}\left( x \right)\sin x} = 0\\ {{C’_1}\left( x \right)\left( { – \sin x} \right)} + {{C’_2}\left( x \right)\cos x }= {\sin 2x} \end{array} \right.\]

We can express the derivative \({C’_1}\left( x \right)\) from the first equation:

\[{C’_1}\left( x \right) = – {C’_2}\left( x \right)\frac{{\sin x}}{{\cos x}}.\]

Substituting this in the second equation, we find the derivative \({C’_2}\left( x \right):\)

\[

{{\left( { – {C’_2}\left( x \right)\frac{{\sin x}}{{\cos x}}} \right)\left( { – \sin x} \right) }+{ {C’_2}\left( x \right)\cos x = \sin 2x,\;\;}}\Rightarrow

{{ {C’_2}\left( x \right)\left( {\frac{{{{\sin }^2}x}}{{\cos x}} + \cos x} \right) }={ \sin 2x,\;\;}}\Rightarrow

{{ {C’_2}\left( x \right)\frac{{{{\sin }^2}x + {{\cos }^2}x}}{{\cos x}} }={ \sin 2x,\;\;}}\Rightarrow

{ {C’_2}\left( x \right)\frac{1}{{\cos x}} = \sin 2x,\;\;}\Rightarrow

{ {C’_2}\left( x \right) = \sin 2x\cos x.}

\]

It follows from here that

\[

{{C’_1}\left( x \right) }={ – \sin 2x\cos x \cdot \frac{{\sin x}}{{\cos x}} }

= { – \sin 2x\sin x.}

\]

Integrating the expressions for the derivatives \({C’_1}\left( x \right)\) and \({C’_2}\left( x \right),\) gives

\[

{{C_1}\left( x \right) }={ \int {\left( { – \sin 2x\sin x} \right)dx} }

= { – 2\int {{{\sin }^2}x\cos xdx} }

= { – 2\int {{{\sin }^2}xd\left( {\sin x} \right)} }

= { – 2 \cdot \frac{{{{\sin }^3}x}}{3} + {A_1} }

= { – \frac{2}{3}{\sin ^3}x + {A_1},}

\]

\[

{{C_2}\left( x \right) }={ \int {\left( {\sin 2x\cos x} \right)dx} }

= {2\int {\sin x\,{{\cos }^2}xdx} }

= { – 2\int {{\cos^2}xd\left( {\cos x} \right)} }

= { – 2 \cdot \frac{{{\cos^3}x}}{3} + {A_2} }

= { – \frac{2}{3}{\cos^3}x + {A_2}.}

\]

where \({A_1},\) \({A_2}\) are constants of integration.

Now we substitute the found functions \({C_1}\left( x \right)\) and \({C_2}\left( x \right)\) into the formula for \({y_1}\left( x \right)\) and write the general solution of the nonhomogeneous equation:

\[

{y\left( x \right) }={ {C_1}\left( x \right)\cos x + {C_2}\left( x \right)\sin x }

= {{\left( { – \frac{2}{3}{\sin^3}x + {A_1}} \right)\cos x }}+{{ \left( { – \frac{2}{3}{\cos^3}x + {A_2}} \right)\sin x }}

= {{{A_1}\cos x + {A_2}\sin x }-{ \frac{2}{3}{\sin ^3}x\cos x }}-{{ \frac{2}{3}{\cos^3}x\sin x }}

= {{{A_1}\cos x + {A_2}\sin x }}-{{ \frac{2}{3}\sin x\cos x\left( {\underbrace {{{\sin }^2}x + {{\cos }^2}x}_1} \right) }}

= {{{A_1}\cos x + {A_2}\sin x }-{ \frac{1}{3} \cdot 2\sin x\cos x }}

= {{{A_1}\cos x + {A_2}\sin x }-{ \frac{1}{3}\sin 2x.}}

\]