## Section 2.5 Nonhomogeneous equations

¶### 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

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*

We call \(y_c\) the *complementary solution*. Next, we find a single *particular solution* \(y_p\) to (2.6) in some way. Then

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

Using the operator notation the calculation becomes simpler. As \(L\) is a linear operator we write

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.

###### Theorem 2.5.1.

Let \(Ly=f(x)\) be a linear ODE (not necessarily constant coefficient). Let \(y_c\) be the complementary solution (the general solution to the associated homogeneous equation \(Ly = 0\)) and let \(y_p\) be any particular solution to \(Ly=f(x)\text{.}\) Then the general solution to \(Ly=f(x)\) is

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

We plug \(y_p\) into the left hand side to obtain

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

Hence the general solution to (2.6) is

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

We solve to get \(C_1 = \nicefrac{1}{3}\) and \(C_2 = \nicefrac{-2}{9}\text{.}\) The particular solution we want is

###### 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.

A right-hand side consisting of exponentials, sines, and cosines can be handled similarly. For example,

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

We plug \(y_p\) into the equation and we get

or

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

Similarly, if the right-hand side contains exponentials we try exponentials. If

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 \(Ly_p\) is of the same form, and has all the terms needed to for the right-hand side. For example,

For this equation, we guess

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

We would love to guess \(y = Ae^{3x}\text{,}\) but if we plug this into the left-hand side of the equation we get

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 \(Ly = 0\))

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

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

It is possible that multiplying by \(x\) does not get rid of all duplication. For example,

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.

Finally, what if the right-hand side has several terms, such as

In this case we find \(u\) that solves \(Lu = e^{2x}\) and \(v\) that solves \(Lv = \cos x\) (that is, do each term separately). Then note that if \(y = u+ v\text{,}\) then \(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

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:

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

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

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!)

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.

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

We have \((u_1 y_1 + u_2 y_2) = y\) and so

and hence

For \(y\) to satisfy \(Ly = 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{:}\)

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

Hence

And thus

We integrate \(u_1'\) and \(u_2'\) to get \(u_1\) and \(u_2\text{.}\)

So our particular solution is

The general solution to \(y'' + y = \tan x\) is, therefore,

### Subsection 2.5.4 Exercises

###### Exercise 2.5.2.

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

###### Exercise 2.5.3.

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

###### Exercise 2.5.4.

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

###### Exercise 2.5.5.

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

###### Exercise 2.5.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{.}\)

###### Exercise 2.5.7.

Using variation of parameters find a particular solution of \(y''-2y'+y = e^x\text{.}\)

Find a particular solution using undetermined coefficients.

Are the two solutions you found the same? See also Exercise 2.5.10.

###### Exercise 2.5.8.

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

###### Exercise 2.5.9.

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{.}\)

###### Exercise 2.5.10.

Using variation of parameters find a particular solution of \(y''-y = e^x\text{.}\)

Find a particular solution using undetermined coefficients.

Are the two solutions you found the same? What is going on?

###### Exercise 2.5.101.

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

\(y=\frac{-16\sin(3x)+6\cos(3x)}{73}\)

###### Exercise 2.5.102.

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

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}\)

###### Exercise 2.5.103.

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)\)

###### Exercise 2.5.104.

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})\log(e^{2x}+1)}{4}\)

###### Exercise 2.5.105.

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}\)