Skip to main content

Section 2.5 Nonhomogeneous equations

Subsection Solving nonhomogeneous equations

We have solved linear constant coefficient homogeneous equations. What about nonhomogeneous linear ODEs? For example, the equations for forced mechanical vibrations, where we add a β€œforcing” term, which is a function on the right-hand side of the equation. That is, suppose we have an equation such as
\begin{equation} y'' + 5y'+ 6y = 2x+1 .\tag{2.5.1} \end{equation}
We will write \(L[y] = 2x+1\text{,}\) where \(L[y]\) represents the entire left-hand side of \(y'' + 5y' + 6y\text{,}\) when the exact form of the operator is not important. We solve (2.5.1) in the following manner. First, we find the general solution \(y_c\) to the associate homogeneous equation.
\begin{equation} y'' + 5y'+ 6y = 0 .\tag{2.5.2} \end{equation}
We call \(y_c\) the complemetary solution. Next, we find a single particular solution \(y_p\) to (2.5.1) in some way (that is the point of this section). Then
\begin{equation*} y = y_c + y_p \end{equation*}
is the general solution to (2.5.1). 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.5.1). 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*} L[w] = L[y_p - \tilde{y}_p] = L[y_p] - L[\tilde{y}_p] = (2x+1)-(2x+1) = 0 . \end{equation*}
So \(w = y_p - \tilde{y}_p\) is a solution to (2.5.2), that is \(Lw = 0\text{.}\) However, we know what all solutions to \(Lw = 0\) look like, as this is a homogeneous equation that we have solved previously. Therefore, any two solutions of (2.5.1) differ by a solution to the homogeneous equation (2.5.2). The solution \(y = y_c + y_p\) includes all solutions to (2.5.1), 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 Undetermined coefficients

The trick is to somehow, in a smart way, guess one particular solution to (2.5.1). Note that \(2x+1\) is a polynomial, and the left-hand side of the equation (with all of the derivatives) will still 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{align*} y_p'' + 5y_p'+ 6y_p \amp = (Ax+B)'' + 5(Ax+B)' + 6(Ax+B) \\ \amp = 0 + 5A + 6Ax + 6B = 6Ax+ (5A+6B) \text{.} \end{align*}
So \(6Ax+(5A+6B) = 2x+1\text{.}\) If we match up the coefficients of \(x\) in this equation, we get that \(6A = 2\) or \(A = \nicefrac{1}{3}\text{.}\) In order for the constant terms to match, we need that \(5A + 6B = 1\text{.}\) Since we know the value of \(A\text{,}\) this tells us that \(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.5.1) 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(x) = \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*}

Checkpoint 2.5.2.

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.
A right-hand side consisting of exponentials, sines, and cosines can be handled similarly.

Example 2.5.3. .

One example of this is
\begin{equation*} y''+2y'+2y = \cos (2x) . \end{equation*}
Solution.
Let us find some \(y_p\text{.}\) We start by guessing that the solution includes some multiple of \(\cos(2x)\text{.}\) We try
\begin{equation*} y_p = A \cos(2x) . \end{equation*}
Plugging this into the differential equation gives
\begin{equation*} \underbrace{-4 A \cos (2x)}_{y_p''} +2 \underbrace{\bigl(-2A \sin (2x)\bigr)}_{y_p'} + 2 \underbrace{\bigl(A \cos (2x)\bigr)}_{y_p} = \cos (2x). \end{equation*}
Simplifying this expression gives
\begin{equation*} -2A\cos(2x) - 4A\sin(2x) = \cos(2x) \end{equation*}
and we have a problem. Since there is no sine term on the right-hand side, we are forced to pick \(A = 0\text{,}\) which means our non-homogeneous solution is zero, and that’s not good. What happened here? In the previous example, when we differentiated a polynomial (as part of the \(y_p\) guess) the function stayed a polynomial, and so we did not add any new types of terms. In this case, however, when we differentiate the cosine term in our guess, it becomes a sine, which we did not have in our initial guess.
Thus, we will also want to 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{equation*} \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) + B \sin (2x)\bigr)}_{y_p} = \cos (2x)\text{,} \end{equation*}
or
\begin{equation*} (-4A+4B+2A) \cos(2x) + (-4B-4A+2B) \sin(2x) = \cos(2x)\text{.} \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\text{.}\) We can solve this system of equations to get that \(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*} L[y] = e^{3x}, \end{equation*}
we try \(y = 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 \(L[y_p]\) is of the same form, and has all the terms needed to for the right-hand side. For example,
\begin{equation*} L[y] = (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, suppose we have
\begin{equation*} y'' - 9y = e^{3x} . \end{equation*}
We would love to guess \(y = Ae^{3x}\text{,}\) but if we plug this into the left-hand side of the equation we get
\begin{equation*} y''-9y = 9Ae^{3x} - 9Ae^{3x} = 0 \not= e^{3x} . \end{equation*}
There is no way we can 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 compute \(y_c\) (solution to \(L[y] = 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 = Axe^{3x}\) so that there is no duplication anymore. Let us try: \(y' = Ae^{3x} + 3Axe^{3x}\) and \(y'' = 6Ae^{3x} + 9Axe^{3x}\text{,}\) so
\begin{equation*} y'' -9y = 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*}
Notice that the term of the form \(xe^{3x}\) does not show up on the left-hand side after differentiating the equation, and the only term that survives is the \(e^{3x}\) term that showed up from the derivatives. This works out because \(e^{3x}\) solves the homogeneous problem. With that though, make sure to remember to include the \(xe^{3x}\) when you write out the general solution at the end of the problem, because it does appear there.
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=A xe^{3x}\) would not get us anywhere. In this case we want to guess \(y_p = Ax^2e^{3x}\text{.}\) Basically, we want to multiply our guess by \(x\) until all duplication is gone. But no more! Multiplying too many times will not work (in that case, the derivatives won’t actually get down to the plain \(e^{3x}\) term that you need in order to solve the problem).
Finally, what if the right-hand side has several terms, such as
\begin{equation*} L[y] = e^{2x} + \cos x . \end{equation*}
In this case we find \(u\) that solves \(L[u] = e^{2x}\) and \(v\) that solves \(L[v] = \cos x\) (that is, do each term separately). Then note that if \(y = u+ v\text{,}\) then \(L[y] = e^{2x} + \cos x\text{.}\) This is because \(L\) is linear; we have \(L[y] = L[u+v] = L[u] + L[v] = e^{2x} + \cos x\text{.}\)
To summarize all of this, we can make a table of the different guesses we should make given the form of the right hand side.
Table 2.5.4.
Right hand side Guess
\(a_nx^n + a_{n-1}x^{n-1} + \cdots + a_1x + a_0\) \(Ax^n + Bx^{n-1} + \cdots + Nx + P\)
\(e^{ax}\) \(Ae^{ax}\)
\(\cos{ax}\) \(A\cos{ax} + B\sin{ax}\)
\(\sin{ax}\) \(A\cos{ax} + B\sin{ax}\)
  • If there is a product of above terms, guess the product of the guesses. So, for a right hand side of \(xe^{ax}\text{,}\) the guess should be \((Ax + B)e^{ax}\text{,}\) and for a right hand side of \(x\cos{ax}\text{,}\) the guess should be \((Ax + B)\cos{ax} + (Cx+D)\sin{ax}\text{.}\)
  • If any part solves the homogeneous problem, multiply that entire component by \(x\) until nothing does.

Example 2.5.5.

Find the solution to the initial value problem
\begin{equation*} y'' - 3y' - 4y = 2e^{-x} + 4 \sin(x) \qquad y(0) = -2,\ y'(0) = 1 \end{equation*}
Solution.
To start this problem, we look for the solution to the homogeneous problem. The characteristic equation for the left hand side is \(r^2 - 3r - 4\text{,}\) which factors as \((r-4)(r+1)\text{.}\) Therefore the general solution to the homogeneous problem (or the complementary solution) is
\begin{equation*} y_c(x) = C_1e^{4x} + C_2e^{-x} . \end{equation*}
Next, we want to use undetermined coefficients to solve the non-homogeneous problem. Note that we have to wait until after this part to meet the initial conditions. Since our right-hand side is \(2e^{-x} + 4 \sin(x)\text{,}\) we need to guess two components for the two different terms in this function. For the first term, we would want to guess \(Ae^{-x}\text{,}\) but this function solves the homogeneous problem. Therefore, we need to multiply by \(x\) to use \(Axe^{-x}\) as our guess. For the sine term, we need to guess both sine and cosine, so we add \(B\sin(x) + C\cos(x)\) to our guess. Therefore, our total guess for the non-homogeneous solution is
\begin{equation*} y_p(x) = Axe^{-x} + B\sin(x) + C\cos(x). \end{equation*}
We take two derivatives of this function and then plug it into the differential equation
\begin{align*} y_p(x) \amp= Axe^{-x} + B\sin(x) + C\cos(x) \\ y_p'(x) \amp= Ae^{-x} - Axe^{-x} + B\cos(x) - C\sin(x) \\ y_p''(x) \amp= Axe^{-x} - 2Ae^{-x} - B\sin(x) - C\cos(x) \end{align*}
so that
\begin{align*} y_p'' - 3y_p' - 4y_p \amp= (Axe^{-x} - 2Ae^{-x} - B\sin(x) - C\cos(x))\\ \amp\ \ - 3(Ae^{-x} - Axe^{-x} + B\cos(x) - C\sin(x))\\ \amp \ \ - 4(Axe^{-x} + B\sin(x) + C\cos(x)) \end{align*}
which can be simplified to
\begin{equation*} y_p'' - 3y_p' - 4y_p = -5Ae^{-x} + (3C - 5B)\sin(x) + (-3B-5C)\cos(x). \end{equation*}
Since we want this to equal \(2e^{-x} + 4\sin(x)\text{,}\) this means that we need \(-5A = 2\text{,}\) so \(A = -\nicefrac{2}{5}\text{,}\) as well as \(3C - 5B = 4\) and \(-3B-5C = 0\text{.}\) The second of these implies that \(3B = -5C\text{,}\) or \(B = -\nicefrac{5}{3}C\text{,}\) so that the first equation gives \(3C - 5(-\nicefrac{5}{3}C) = 4\text{.}\) This implies that \((3 + \nicefrac{25}{3})C = 4\) so that
\begin{equation*} C = \frac{4}{(3 + \frac{25}{3})} = \frac{4}{\frac{34}{3}} = \frac{6}{17}. \end{equation*}
We can then find \(B\) as
\begin{equation*} B = -\frac{5}{3}C = -\frac{5}{3} \cdot \frac{6}{17} = -\frac{10}{17}. \end{equation*}
Therefore, the general solution to this non-homogeneous problem is
\begin{equation*} y(x) = C_1e^{4x} + C_2e^{-x} - \frac{2}{5}xe^{-x} - \frac{10}{17}\sin(x) + \frac{6}{17}\cos(x). \end{equation*}
Now we can look to meet the initial conditions. We want to differentiate this expression to get
\begin{equation*} y'(x) = 4C_1e^{4x} - C_2e^{-x} - \frac{2}{5}e^{-x} + \frac{2}{5}xe^{-x} - \frac{10}{17}\cos(x) - \frac{6}{17}\sin(x) \end{equation*}
and then plug zero into both \(y\) and \(y'\) to get that
\begin{align*} y(0) \amp= C_1 + C_2 + \frac{6}{17} = -2 \\ y'(0) \amp= 4C_1 - C_2 - \frac{2}{5} - \frac{10}{17} = 1 \end{align*}
which gives rise to the system
\begin{equation*} C_1 + C_2 = -\frac{40}{17} \qquad 4C_1 - C_2 = \frac{169}{85}. \end{equation*}
Adding the equations together gives \(5C_1 = - \frac{31}{85}\) so that \(C_1 = -\frac{31}{425}\) and then \(C_2 = -\frac{969}{425} = -\frac{57}{25}\text{.}\) Therefore the solution to the initial value problem is
\begin{equation*} y(x) = -\frac{31}{425}e^{4x} - \frac{57}{25}e^{-x} - \frac{2}{5}xe^{-x} - \frac{10}{17}\sin(x) + \frac{6}{17}\cos(x). \end{equation*}

Checkpoint 2.5.6.

Subsection 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 \(L[y] = 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{align*} f(x) \amp = \tan x \\ f'(x) \amp = \sec^2 x\\ f''(x) \amp = 2\sec^2 x \, \tan x\\ f^{(3)}(x) \amp = 4 \sec^2 x \, \tan^2 x + 2 \sec^4 x\\ f^{(4)}(x) \amp = 8 \sec^2 x \, \tan^3 x + 16 \sec^4 x \, \tan x\\ f^{(5)}(x) \amp = 16\sec^2 x \, \tan^4 x + 88 \sec^4 x \tan^2 x + 16 \sec^6 x \\ \vdots \amp = \vdots \end{align*}
This equation calls for a different method. We present the method of variation of parameters, which handles any equation of the form \(L[y] = 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*} L[y] = y''+y = \tan x . \end{equation*}
First we find the complementary solution (solution to \(L[y_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 \(L[y] = \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{align*} \amp y' = u_1 y_1' + u_2 y_2' , \\ \amp y'' = (u_1' y_1' + u_2' y_2') + (u_1 y_1'' + u_2 y_2'') \text{.} \end{align*}
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 = L[y] = u_1' y_1' + u_2' y_2' . \end{equation*}
For \(y\) to satisfy \(L[y] = f(x)\) 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{align*} u_1' y_1 + u_2' y_2 \amp = 0 ,\\ u_1' y_1' + u_2' y_2' \amp = f(x)\text{.} \end{align*}
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 \(L[y] = f(x)\text{,}\) where \(L[y] = 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{align*} u_1' \cos (x) + u_2' \sin (x) \amp= 0 \\ -u_1' \sin (x) + u_2' \cos (x) \amp= \tan (x) \text{.} \end{align*}
Hence
\begin{align*} u_1' \cos (x) \sin (x) + u_2' \sin^2 (x) \amp = 0 \\ -u_1' \sin (x) \cos (x) + u_2' \cos^2 (x) \amp = \tan (x) \cos (x) = \sin (x) \text{.} \end{align*}
And thus
\begin{align*} \amp u_2' \bigl(\sin^2 (x) + \cos^2 (x)\bigr) = \sin (x) \\ \amp u_2' = \sin (x) \\ \amp u_1' = \frac{- \sin^2 (x)}{\cos (x)} = - \tan (x) \sin(x) \text{.} \end{align*}
We integrate \(u_1'\) and \(u_2'\) to get \(u_1\) and \(u_2\text{.}\)
\begin{align*} \amp u_1 = \int u_1'\,dx = \int - \tan (x) \sin (x)\,dx = \frac{1}{2} \ln \left\lvert \frac{\sin (x)-1}{\sin (x) + 1} \right\rvert + \sin (x) , \\ \amp u_2 = \int u_2'\,dx = \int \sin (x)\,dx = -\cos (x) \text{.} \end{align*}
So our particular solution is
\begin{align*} y_p \amp = u_1 y_1 + u_2 y_2 \\ \amp = \frac{1}{2} \cos (x) \ln \left\lvert \frac{\sin (x)-1}{\sin (x) + 1} \right\rvert + \cos (x) \sin (x) -\cos (x) \sin (x) \\ \amp = \frac{1}{2} \cos (x) \ln \left\lvert \frac{\sin (x)-1}{\sin (x) + 1} \right\rvert \text{.} \end{align*}
The general solution to \(y'' + y = \tan x\) is, therefore,
\begin{equation*} y = C_1 \cos (x) + C_2 \sin (x) + \frac{1}{2} \cos (x) \ln \left\lvert \frac{\sin (x)-1}{\sin (x) + 1} \right\rvert\text{.} \end{equation*}
In more generality, we can take the system of equations
\begin{align*} u_1' y_1 + u_2' y_2 \amp = 0 ,\\ u_1' y_1' + u_2' y_2' \amp = f(x) \text{.} \end{align*}
and solve out for \(u_1'\) and \(u_2'\) using elimination. If we do that, we get that
\begin{equation*} u_1' = -\frac{y_2(x)f(x)}{y_1(x)y_2'(x) - y_1'(x)y_2(x)} \qquad u_2' = \frac{y_1(x)f(x)}{y_1(x)y_2'(x) - y_1'(x)y_2(x)}. \end{equation*}
We know that solving the equations this way will work out because we start with the assumption that \(y_1\) and \(y_2\) are linearly independent solutions, and the denominator of both of these fractions is exactly what we know is not zero from this assumption. Therefore, both of these functions can be written this way, we can integrate both of them, and set up our particular solution of the form \(y_p(x) = u_1y_1 + u_2y_2\) to get
\begin{equation} y_p(x) = -y_1(x)\int_{x_0}^x \frac{y_2(r)f(r)}{y_1(r)y_2'(r) - y_1'(r)y_2(r)}\ dr + y_2(x)\int_{x_0}^x \frac{y_1(r)f(r)}{y_1(r)y_2'(r) - y_1'(r)y_2(r)}\ dr\tag{2.5.3} \end{equation}
where \(x_0\) is any conveniently chosen value (usually zero). Notice the use of \(r\) as a dummy variable here to separate the functions being integrated from the actual variable that shows up in the solution. This formula will always work for finding a particular solution to a non-homogeneous equation given that we know the solution to the homogeneous equation, but we may not be able to work out the integrals explicitly. This is the downside of this method, it may always work, but can be very tedious and may not result in nice, closed-form expressions like we might get from other methods.

Example 2.5.7.

Find the general solution to the differential equation
\begin{equation*} y'' + 4y' + 3y = e^{3x} + 2 \end{equation*}
using both undetermined coefficients and variation of parameters.
Solution.
For both methods of solving non-homogeneous equations, we need the solution to the homogeneous problem. For this equation, the characteristic polynomial is \(r^2 + 4r + 3\text{,}\) which factors as \((r+1)(r+3)\text{,}\) so the general solution to the homogeneous problem is
\begin{equation*} y_c(x) = C_1 e^{-x} + C_2e^{-3x}. \end{equation*}
To use undetermined coefficients, we need to get the appropriate guess for the right-hand side, which in this case is \(y_p(x) = Ae^{3x} + B\text{.}\) Plugging this in to the differential equation gives
\begin{equation*} 9Ae^{3x} + 4(3Ae^{3x}) + 3(Ae^{3x} + B) = e^{3x} + 2 \end{equation*}
which simplifies to
\begin{equation*} 24Ae^{3x} + 3B = e^{3x} + 2 \end{equation*}
so that \(A = \nicefrac{1}{24}\) and \(B = \nicefrac{2}{3}\text{.}\) Thus, the general solution to the non-homogeneous equation is
\begin{equation*} y(x) = C_1e^{-x} + C_2e^{-3x} + \frac{1}{24}e^{3x} + \frac{2}{3}. \end{equation*}
In order to use variation of parameters, we let \(y_1(x) = e^{-x}\) and \(y_2(x) = e^{-3x}\) be the two linearly independent solutions that we found to the homogeneous problem. Our right-hand side function is \(f(x) = e^{3x} + 2\) and we can compute the expression
\begin{equation*} y_1(x)y_2'(x) - y_1'(x)y_2(x) = e^{-x}(-3e^{-3x}) - (-e^{-x})e^{-3x} = -2e^{-4x}. \end{equation*}
Therefore, we can use the formulas from the method of variation of parameters to compute that
\begin{align*} u_1' \amp= -\frac{y_2(x)f(x)}{y_1(x)y_2'(x) - y_1'(x)y_2(x)} = -\frac{e^{-3x}(e^{3x} + 2)}{-2e^{-4x}} = \frac{1}{2}e^{4x} + e^x \\ u_2' \amp= \frac{y_1(x)f(x)}{y_1(x)y_2'(x) - y_1'(x)y_2(x)} = \frac{e^{-x}(e^{3x} + 2)}{-2e^{-4x}} = -\frac{1}{2}e^{6x} - e^{3x} \text{.} \end{align*}
Then we can compute
\begin{equation*} u_1 = \frac{1}{8}e^{4x} + e^x + C_1 \qquad u_2 = -\frac{1}{12}e^{6x} - \frac{1}{3}e^{3x} + C_2. \end{equation*}
Then, we can write out the full general solution as \(y(x) = u_1(x)y_1(x) + u_2(x)y_2(x)\) or
\begin{align*} y(x) \amp= e^{-x}\left( \frac{1}{8}e^{4x} + e^x + C_1 \right) + e^{-3x}\left(-\frac{1}{12}e^{6x} - \frac{1}{3}e^{3x} + C_2 \right) \\ \amp= \frac{1}{8}e^{3x} + 1 + C_1e^{-x} - \frac{1}{12}e^{3x} - \frac{1}{3} + C_2e^{-3x} \end{align*}
which, after combining the terms, is the same as the solution that we obtained via undetermined coefficients.

Exercises Exercises

4.

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

5.

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

6.

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{.}\)
Answer.
\(Ax^3 + Bx^2 + Cx^2e^x + D\sin(x) + E\cos(x)\)

8.

Use the method of undetermined coefficients to solve the DE \(y''+4y'=2t+30\text{.}\)
Answer.
\(y(t) = C_1 + C_2e^{-4t} + \frac{1}{4}t + \frac{59}{8}\)

11.

Find the general solution to \(y'' - 3y' - 4y = e^{2t} + 1\text{.}\)
Answer.
\(y(t) = C_1e^{4t} + C_2e^{-t} - \frac{1}{6}e^{2t} - \frac{1}{4}\)

12.

Find the general solution to \(y'' - 2y' + 5y = \sin(3t) + 2\cos(3t)\text{.}\)
Answer.
\(y(t) = C_1e^t\cos(2t) + C_2e^t\sin(2t) - \frac{4}{13}\sin(3t) - \frac{1}{26}\cos(3t)\)

13.

Find the general solution to \(y'' - 4y' - 21y = e^{-3t} + e^{4t}\text{.}\)
Answer.
\(y(t) = C_1e^{7t} + C_2e^{-3t} - \frac{1}{10}te^{-3t} - \frac{1}{21}e^{4t}\)

14.

Find the general solution to \(y'' - 2y' + y = e^t - t\text{.}\)
Answer.
\(y(t) = C_1e^t + C_2te^t + \frac{1}{2}t^2e^t - t - 2\)

15.

Find the general solution to \(y'' + 4y = \sec(2t)\) using variation of parameters.
Answer.
\(y(t) = C_1\cos(2t) + C_2\sin(2t) + \frac{1}{4}\cos(2t)\ln(\cos(2t)) + \frac{1}{2}t\sin(2t)\)

16.

Find the solution of the initial value problem \(y'' - 2y' - 15y = e^{5t} + 3\text{,}\) \(y(0) = 2\text{,}\) \(y'(0) = -1\text{.}\)
Answer.
\(y(t) = \frac{219}{320}e^{5t} + \frac{97}{64}e^{-3t} + \frac{1}{8}te^{5t} - \frac{1}{5}\)

17.

Find the solution of the initial value problem \(y'' + 4y' + 5y = \cos(3t) + t\text{,}\) \(y(0) = 0\text{,}\) \(y'(0) = 2\text{.}\)
Answer.
\(y(t) = \frac{37}{200}e^{-2t}\cos(t) + \frac{389}{200}e^{-2t}\sin(t) - \frac{1}{40}\cos(3t) + \frac{3}{40}\sin(3t) + \frac{t}{5} - \frac{4}{25}\)

18.

The following differential equations are all related. Find the general solution to each of them and compare and contrast the different solutions and the methods used to approach them.
(d)
\(y'' - 2y' - 15y = 2e^{5t} - \sin(t)\)
Answer.
\(C_1e^{5t} + C_2e^{-3t} + \frac{1}{4}te^{5t} - \frac{1}{130}\cos(t) + \frac{4}{65}\sin(t)\)

19.

The following differential equations are all related. Find the general solution to each of them and compare and contrast the different solutions and the methods used to approach them.
(b)
\(y'' - 2y' + 5y = e^{2t} + 3e^{4t}\)
Answer.
\(C_1e^{t}\cos(2t) + C_2e^t\sin(2t) + \frac{1}{20}e^{2t} + \frac{3}{13}e^{4t}\)

20.

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

21.

Use variation of parameters to find a particular solution of \(y''-y = \frac{1}{e^x+e^{-x}}\text{.}\) Hint: To make this problem easier, you can use \(C_1 (e^x + e^{-x}) + C_2 (e^{x} - e^{-x})\) as the general solution to the homogeneous problem.
Answer.
\(y = \frac{2xe^x-(e^x+e^{-x})\ln(e^{2x}+1)}{4} = -\frac{1}{4}\ln(e^x + e^{-x})(e^x + e^{-x}) + \frac{1}{4}x(e^x - e^{-x})\)

22.

Recall that a homogeneous Euler Equation is one of the form \(t^2y'' + aty' + by = 0\) and is solved by using the guess \(y(t) = t^r\) and solving for the potential values of \(r\text{.}\)
(b)
Let \(y_1\) and \(y_2\) be the two linearly independent parts of a general solution for the above equation, so that the general solution is \(C_1y_1 + C_2y_2\text{.}\) Use the variation of parameters equations \(\displaystyle u_1=-\int \frac{y_2\, g(t)}{y_1y_2' - y_2y_1'}\,dt\text{,}\) \(\displaystyle y_2=\int \frac{y_1\, g(t)}{y_1y_2' - y_2y_1'}\,dt\) to solve the non-homogeneous equation \(\displaystyle y''-\frac{2}{t} - \frac{10}{t^2}=t^3\text{.}\) (Do not attempt method of undetermined coefficients instead; it won’t work.)
Answer.
\(y(t) = C_1t^5 + C_2t^{-2} + t^5\left(\frac{1}{7}\ln(|t|) - \frac{1}{49}\right)\)

23.

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

24.

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{.}\)
Answer.
  • \(c\neq \pm1\text{:}\) \(C_1e^x + C_2e^{-x} + \frac{1}{c^2 - 1}e^{cx}\)
  • \(c=1\text{:}\) \(C_1e^x + C_2e^{-x} + \frac{1}{2}xe^x\)
  • \(c=-1\text{:}\) \(C_1e^x + C_2e^{-x} - \frac{1}{2}xe^{-x}\)