Skip to main content
Logo image

Section 2.5 Nonhomogeneous equations

Note: 2 lectures, §3.5 in [EP], §3.5 and §3.6 in [BD]

Subsection 2.5.1 Solving nonhomogeneous equations

We have solved linear constant coefficient homogeneous equations. What about nonhomogeneous linear ODEs? For example, the equations for forced mechanical vibrations. That is, suppose we have an equation such as
\begin{equation} y'' + 5y'+ 6y = 2x+1 .\tag{2.6} \end{equation}
We will write \(Ly = 2x+1\) when the exact form of the operator is not important. We solve (2.6) in the following manner. First, we find the general solution \(y_c\) to the associated homogeneous equation
\begin{equation} y'' + 5y'+ 6y = 0 .\tag{2.7} \end{equation}
We call \(y_c\) the complementary solution. Next, we find a single particular solution \(y_p\) to (2.6) in some way. Then
\begin{equation*} y = y_c + y_p \end{equation*}
is the general solution to (2.6). We have \(L y_c = 0\) and \(L y_p = 2x+1\text{.}\) As \(L\) is a linear operator we verify that \(y\) is a solution, \(L y = L ( y_c + y_p) = L y_c + L y_p = 0 + (2x+1)\text{.}\) Let us see why we obtain the general solution.
Let \(y_p\) and \(\tilde{y}_p\) be two different particular solutions to (2.6). Write the difference as \(w = y_p - \tilde{y}_p\text{.}\) Then plug \(w\) into the left-hand side of the equation to get
\begin{equation*} w'' + 5w'+ 6w = (y_p'' + 5y_p'+ 6y_p) - (\tilde{y}_p'' + 5\tilde{y}_p'+ 6\tilde{y}_p) = (2x+1) - (2x+1) = 0 . \end{equation*}
Using the operator notation the calculation becomes simpler. As \(L\) is a linear operator we write
\begin{equation*} Lw = L(y_p - \tilde{y}_p) = Ly_p - L\tilde{y}_p = (2x+1)-(2x+1) = 0 . \end{equation*}
So \(w = y_p - \tilde{y}_p\) is a solution to (2.7), that is \(Lw = 0\text{.}\) Any two solutions of (2.6) differ by a solution to the homogeneous equation (2.7). The solution \(y = y_c + y_p\) includes all solutions to (2.6), since \(y_c\) is the general solution to the associated homogeneous equation.
The moral of the story is that we can find the particular solution in any old way. If we find a different particular solution (by a different method, or simply by guessing), then we still get the same general solution. The formula may look different, and the constants we have to choose to satisfy the initial conditions may be different, but it is the same solution.

Subsection 2.5.2 Undetermined coefficients

The trick is to somehow, in a smart way, guess one particular solution to (2.6). Note that \(2x+1\) is a polynomial, and the left-hand side of the equation will be a polynomial if we let \(y\) be a polynomial of the same degree. Let us try
\begin{equation*} y_p = Ax + B . \end{equation*}
We plug \(y_p\) into the left hand side to obtain
\begin{equation*} \begin{split} y_p'' + 5y_p'+ 6y_p & = (Ax+B)'' + 5(Ax+B)' + 6(Ax+B) \\ & = 0 + 5A + 6Ax + 6B = 6Ax+ (5A+6B) . \end{split} \end{equation*}
So \(6Ax+(5A+6B) = 2x+1\text{.}\) Therefore, \(A = \nicefrac{1}{3}\) and \(B = \nicefrac{-1}{9}\text{.}\) That means \(y_p = \frac{1}{3}\, x - \frac{1}{9} = \frac{3x-1}{9}\text{.}\) Solving the complementary problem (exercise!) we get
\begin{equation*} y_c = C_1 e^{-2x} + C_2 e^{-3x}. \end{equation*}
Hence the general solution to (2.6) is
\begin{equation*} y = C_1 e^{-2x} + C_2 e^{-3x} + \frac{3x-1}{9} . \end{equation*}
Now suppose we are further given some initial conditions. For example, \(y(0) = 0\) and \(y'(0) = \nicefrac{1}{3}\text{.}\) First find \(y' = - 2C_1 e^{-2x} - 3C_2 e^{-3x} + \nicefrac{1}{3}\text{.}\) Then
\begin{equation*} 0 = y(0) = C_1 + C_2 -\frac{1}{9} , \qquad \frac{1}{3} = y'(0) = - 2C_1 - 3C_2 + \frac{1}{3} . \end{equation*}
We solve to get \(C_1 = \nicefrac{1}{3}\) and \(C_2 = \nicefrac{-2}{9}\text{.}\) The particular solution we want is
\begin{equation*} y = \frac{1}{3} e^{-2x} - \frac{2}{9} e^{-3x} + \frac{3x-1}{9} = \frac{3 e^{-2x} - 2 e^{-3x} + 3x-1}{9} . \end{equation*}

Exercise 2.5.1.

Check that \(y\) really solves the equation (2.6) and the given initial conditions.
Note: A common mistake is to solve for constants using the initial conditions with \(y_c\) and only add the particular solution \(y_p\) after that. That will not work. You need to first compute \(y = y_c + y_p\) and only then solve for the constants using the initial conditions.
Another important remark is that you should not forget the lower degree terms, even if they do not appear on the right hand side. If the equation is \(Ly=x^3+1\text{,}\) you must try \(y_p = Ax^3+Bx^2+Cx+D\text{,}\) even though there is no \(x^2\) nor \(x\) on the right hand side of the equation. It is a general polynomial of degree 3 that must be tried.
A right-hand side consisting of exponentials, sines, and cosines can be handled similarly. For example,
\begin{equation*} y''+2y'+2y = \cos (2x) . \end{equation*}
Let us find some \(y_p\text{.}\) We start by guessing the solution includes some multiple of \(\cos(2x)\text{.}\) We may have to also add a multiple of \(\sin (2x)\) to our guess since derivatives of cosine are sines. We try
\begin{equation*} y_p = A \cos (2x) + B \sin (2x) . \end{equation*}
We plug \(y_p\) into the equation and we get
\begin{multline*} \underbrace{-4 A \cos (2x) - 4 B \sin (2x)}_{y_p''} +2 \underbrace{\bigl(-2A \sin (2x) + 2B \cos (2x)\bigr)}_{y_p'} \\ + 2 \underbrace{\bigl(A \cos (2x) + 2B \sin (2x)\bigr)}_{y_p} = \cos (2x) , \end{multline*}
\begin{equation*} (-4A+4B+2A) \cos(2x) + (-4B-4A+2B) \sin(2x) = \cos(2x) . \end{equation*}
The left-hand side must equal to right-hand side. Namely, \(-4A + 4B + 2A = 1\) and \(-4B - 4A + 2B = 0\text{.}\) So \(-2A+4B =1\) and \(2A+B=0\) and hence \(A=\nicefrac{-1}{10}\) and \(B=\nicefrac{1}{5}\text{.}\) So
\begin{equation*} y_p = A \cos (2x) + B \sin (2x) = \frac{-\cos (2x) + 2 \sin (2x)}{10} . \end{equation*}
Similarly, if the right-hand side contains exponentials we try exponentials. If
\begin{equation*} Ly = e^{3x}, \end{equation*}
we try \(y_p = A e^{3x}\) as our guess and try to solve for \(A\text{.}\)
When the right-hand side is a multiple of sines, cosines, exponentials, and polynomials, we can use the product rule for differentiation to come up with a guess. We need to guess a form for \(y_p\) such that \(Ly_p\) is of the same form, and has all the terms needed to for the right-hand side. For example,
\begin{equation*} Ly = (1+3x^2)\,e^{-x}\cos (\pi x) . \end{equation*}
For this equation, we guess
\begin{equation*} y_p = (A + Bx + Cx^2)\,e^{-x} \cos (\pi x) + (D + Ex + Fx^2)\,e^{-x} \sin (\pi x) . \end{equation*}
We plug in and then hopefully get equations that we can solve for \(A\text{,}\) \(B\text{,}\) \(C\text{,}\) \(D\text{,}\) \(E\text{,}\) and \(F\text{.}\) As you can see this can make for a very long and tedious calculation very quickly. C’est la vie!
There is one hiccup in all this. It could be that our guess actually solves the associated homogeneous equation. That is, consider
\begin{equation*} y'' - 9y = e^{3x} . \end{equation*}
We would love to guess \(y_p = Ae^{3x}\text{,}\) but if we plug this into the left-hand side of the equation we get
\begin{equation*} y_p''-9y_p = 9Ae^{3x} - 9Ae^{3x} = 0 \not= e^{3x} . \end{equation*}
There is no way to choose \(A\) to make the left-hand side be \(e^{3x}\text{.}\) The trick in this case is to multiply our guess by \(x\) to get rid of duplication with the complementary solution. That is, first we find \(y_c\) (solution to \(Ly = 0\))
\begin{equation*} y_c = C_1 e^{-3x} + C_2 e^{3x} , \end{equation*}
and we note that the \(e^{3x}\) term is a duplicate with our desired guess. We modify our guess to \(y_p = Axe^{3x}\) so that there is no duplication anymore. Let us try: \(y_p' = Ae^{3x} + 3Axe^{3x}\) and \(y_p'' = 6Ae^{3x} + 9Axe^{3x}\text{,}\) so
\begin{equation*} y_p'' -9y_p = 6Ae^{3x} + 9Axe^{3x} - 9Axe^{3x} = 6Ae^{3x} . \end{equation*}
Thus \(6Ae^{3x}\) is supposed to equal \(e^{3x}\text{.}\) Hence, \(6A = 1\) and so \(A=\nicefrac{1}{6}\text{.}\) We can now write the general solution as
\begin{equation*} y = y_c + y_p = C_1 e^{-3x} + C_2 e^{3x} + \frac{1}{6}\,xe^{3x} . \end{equation*}
It is possible that multiplying by \(x\) does not get rid of all duplication. For example,
\begin{equation*} y''-6y'+9y = e^{3x} . \end{equation*}
The complementary solution is \(y_c = C_1 e^{3x} + C_2 x e^{3x}\text{.}\) Guessing \(y_p=A xe^{3x}\) does not get us anywhere. We want to guess \(y_p = Ax^2e^{3x}\text{.}\) Basically, we multiply our guess by \(x\) until all duplication is gone. But no more! Multiplying too many times will not work.
Finally, what if the right-hand side has several terms, such as
\begin{equation*} Ly = e^{2x} + \cos x . \end{equation*}
In this case we find \(u\) that solves \(Lu = e^{2x}\) and \(v\) that solves \(Lv = \cos x\) (that is, do each term separately). If we set \(y = u+ v\text{,}\) then we find our desired solution \(Ly = e^{2x} + \cos x\text{.}\) This is because \(L\) is linear; we have \(Ly = L(u+v) = Lu + Lv = e^{2x} + \cos x\text{.}\)

Subsection 2.5.3 Variation of parameters

The method of undetermined coefficients works for many basic problems that crop up. But it does not work all the time. It only works when the right-hand side of the equation \(Ly = f(x)\) has finitely many linearly independent derivatives, so that we can write a guess that consists of them all. Some equations are a bit tougher. Consider
\begin{equation*} y''+y = \tan x . \end{equation*}
Each new derivative of \(\tan x\) looks completely different and cannot be written as a linear combination of the previous derivatives. If we start differentiating \(\tan x\text{,}\) we get:
\begin{multline*} \sec^2 x, \quad 2\sec^2 x \, \tan x, \quad 4 \sec^2 x \, \tan^2 x + 2 \sec^4 x, \\ 8 \sec^2 x \, \tan^3 x + 16 \sec^4 x \, \tan x, \quad 16\sec^2 x \, \tan^4 x + 88 \sec^4 x \tan^2 x + 16 \sec^6 x, \quad \ldots \end{multline*}
This equation calls for a different method. We present the method of variation of parameters, which handles any equation of the form \(Ly = f(x)\text{,}\) provided we can solve certain integrals. For simplicity, we restrict ourselves to second order constant coefficient equations, but the method works for higher order equations just as well (the computations become more tedious). The method also works for equations with nonconstant coefficients, provided we can solve the associated homogeneous equation.
Perhaps it is best to explain this method by example. Let us try to solve the equation
\begin{equation*} Ly = y''+y = \tan x . \end{equation*}
First we find the complementary solution (solution to \(Ly_c = 0\)). We get \(y_c = C_1 y_1 + C_2 y_2\text{,}\) where \(y_1 = \cos x\) and \(y_2 = \sin x\text{.}\) To find a particular solution to the nonhomogeneous equation we try
\begin{equation*} y_p = y = u_1 y_1 + u_2 y_2 , \end{equation*}
where \(u_1\) and \(u_2\) are functions and not constants. We are trying to satisfy \(Ly = \tan x\text{.}\) That gives us one condition on the functions \(u_1\) and \(u_2\text{.}\) Compute (note the product rule!)
\begin{equation*} y' = (u_1' y_1 + u_2' y_2) + (u_1 y_1' + u_2 y_2'). \end{equation*}
We can still impose one more condition at our discretion to simplify computations (we have two unknown functions, so we should be allowed two conditions). We require that \((u_1' y_1 + u_2' y_2) = 0\text{.}\) This makes computing the second derivative easier.
\begin{equation*} \begin{aligned} & y' = u_1 y_1' + u_2 y_2' , \\ & y'' = (u_1' y_1' + u_2' y_2') + (u_1 y_1'' + u_2 y_2'') . \end{aligned} \end{equation*}
Since \(y_1\) and \(y_2\) are solutions to \(y''+y = 0\text{,}\) we find \(y_1'' = - y_1\) and \(y_2'' = - y_2\text{.}\) (If the equation was a more general \(y''+p(x)y' +q(x)y = 0\text{,}\) we would have \(y_i'' = -p(x)y_i' -q(x)y_i\text{.}\)) So
\begin{equation*} y'' = (u_1' y_1' + u_2' y_2') - (u_1 y_1 + u_2 y_2) . \end{equation*}
We have \((u_1 y_1 + u_2 y_2) = y\) and so
\begin{equation*} y'' = (u_1' y_1' + u_2' y_2') - y , \end{equation*}
and hence
\begin{equation*} y'' + y = Ly = u_1' y_1' + u_2' y_2' . \end{equation*}
For \(y\) to satisfy \(Ly = f(x)\text{,}\) we must have \(f(x) = u_1' y_1' + u_2' y_2'\text{.}\)
What we need to solve are the two equations (conditions) we imposed on \(u_1\) and \(u_2\text{:}\)
\begin{equation*} \mybxbg{~~ \begin{aligned} & u_1' y_1 + u_2' y_2 = 0 ,\\ & u_1' y_1' + u_2' y_2' = f(x) . \end{aligned} ~~} \end{equation*}
We solve for \(u_1'\) and \(u_2'\) in terms of \(f(x)\text{,}\) \(y_1\) and \(y_2\text{.}\) We always get these formulas for any \(Ly = f(x)\text{,}\) where \(Ly = y''+p(x)y'+q(x)y\text{.}\) There is a general formula for the solution we could just plug into, but instead of memorizing that, it is better, and easier, to just repeat what we do below. In our case, the two equations are
\begin{equation*} \begin{aligned} u_1' \cos x + u_2' \sin x &= 0 ,\\ -u_1' \sin x + u_2' \cos x &= \tan x . \end{aligned} \end{equation*}
\begin{equation*} \begin{aligned} u_1' \cos x \sin x + u_2' \sin^2 x & = 0 ,\\ -u_1' \sin x \cos x + u_2' \cos^2 x & = \tan x \cos x = \sin x . \end{aligned} \end{equation*}
And thus
\begin{equation*} \begin{aligned} & u_2' \bigl(\sin^2 x + \cos^2 x\bigr) = \sin x , \\ & u_2' = \sin x , \\ & u_1' = \frac{- \sin^2 x}{\cos x} = \cos x - \sec x . \end{aligned} \end{equation*}
We integrate \(u_1'\) and \(u_2'\) to get \(u_1\) and \(u_2\text{.}\)
\begin{equation*} \begin{aligned} & u_1 = \int u_1'\,dx = \int ( \cos x-\sec x ) \,dx = \sin x - \ln \left\lvert \sec x + \tan x \right\rvert , \\ & u_2 = \int u_2'\,dx = \int \sin x\,dx = -\cos x . \end{aligned} \end{equation*}
We are looking for a particular solution, so we forget about the constants of integration. So our particular solution is
\begin{multline*} y_p = u_1 y_1 + u_2 y_2 = \cos x \sin x - \cos x \, \ln \lvert \sec x + \tan x \rvert -\cos x \sin x \\ = - \cos x \, \ln \lvert \sec x + \tan x \rvert . \end{multline*}
The general solution to \(y'' + y = \tan x\) is, therefore,
\begin{equation*} y = C_1 \cos x + C_2 \sin x - \cos x \, \ln \lvert \sec x + \tan x \rvert . \end{equation*}

Exercises 2.5.4 Exercises


Find a particular solution of \(y''-y' -6y = e^{2x}\text{.}\)


Find a particular solution of \(y''-4y' +4y = e^{2x}\text{.}\)


Solve the initial value problem \(y''+9y = \cos (3x) + \sin (3x)\) for \(y(0) = 2\text{,}\) \(y'(0) = 1\text{.}\)


Set up the form of the particular solution but do not solve for the coefficients for \(y^{(4)}-2y'''+y'' = e^x\text{.}\)


Set up the form of the particular solution but do not solve for the coefficients for \(y^{(4)}-2y'''+y'' = e^x + x + \sin x\text{.}\)


  1. Using variation of parameters find a particular solution of \(y''-2y'+y = e^x\text{.}\)
  2. Find a particular solution using undetermined coefficients.
  3. Are the two solutions you found the same? See also Exercise 2.5.10.


Find a particular solution of \(y''-2y' +y = \sin (x^2)\text{.}\) It is OK to leave the answer as a definite integral.


For an arbitrary constant \(c\) find a particular solution to \(y''-y=e^{cx}\text{.}\) Hint: Make sure to handle every possible real \(c\text{.}\)


  1. Using variation of parameters find a particular solution of \(y''-y = e^x\text{.}\)
  2. Find a particular solution using undetermined coefficients.
  3. Are the two solutions you found the same? What is going on?


Find a polynomial \(P(x)\text{,}\) so that \(y = 2 x^2 + 3 x + 4\) solves \(y''+5 y'+ y = P(x)\text{.}\)


Find a particular solution to \(y''-y'+y=2\sin(3x)\text{.}\)


  1. Find a particular solution to \(y''+2y=e^x + x^3\text{.}\)
  2. Find the general solution.
a) \(y=\frac{2e^x+3x^3-9x}{6}\)     b) \(y=C_1 \cos(\sqrt{2} x) + C_2 \sin(\sqrt{2} x) + \frac{2e^x+3x^3-9x}{6}\)


Solve \(y''+2y'+y = x^2\text{,}\) \(y(0)=1\text{,}\) \(y'(0)=2\text{.}\)
\(y(x) = x^2-4 x+6+e^{-x}(x-5)\)


Use variation of parameters to find a particular solution of \(y''-y = \frac{1}{e^x+e^{-x}}\text{.}\)
\(y = \frac{2xe^x-(e^x+e^{-x})\ln(e^{2x}+1)}{4}\)


For an arbitrary constant \(c\) find the general solution to \(y''-2y=\sin(x+c)\text{.}\)
\(y=\frac{-\sin(x+c)}{3}+C_1 e^{\sqrt{2}\,x}+C_2 e^{-\sqrt{2}\,x}\)


Undetermined coefficients can sometimes be used to guess a particular solution to other equations than constant coefficients. Find a polynomial \(y(x)\) that solves \(y'+ x y = x^3+2x^2+5x+2\text{.}\)
Note: Not every right hand side will allow a polynomial solution, for example, \(y'+xy=1\) does not, but a technique based on undetermined coefficients does work, see Chapter 7.
For a higher quality printout use the PDF version: