[Notes on Diffy Qs home] [PDF version] [Buy cheap paperback version]

[next] [prev] [prev-tail] [tail] [up]

2.5 Nonhomogeneous equations

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

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

y′′ + 5y′ + 6y = 2x + 1.
(2.6)

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 yc to the associated homogeneous equation

 ′′ ′ y + 5y + 6y = 0.
(2.7)

We call yc the complementary solution. Next, we find a single particular solution yp to (2.6) in some way. Then

y = yc + yp

is the general solution to (2.6). We have Ly = 0 c and Ly = 2x + 1 p . As L is a linear operator we verify that y is a solution, Ly = L (yc + yp) = Lyc + Lyp = 0 + (2x + 1) . Let us see why we obtain the general solution.

Let yp and ~yp be two different particular solutions to (2.6). Write the difference as w = yp - y~p . Then plug w into the left hand side of the equation to get

 ′′ ′ ′′ ′ ′′ ′ w + 5w + 6w = (yp + 5yp + 6yp) - (y~p + 5~yp + 6~yp) = (2x + 1) - (2x + 1) = 0.

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

Lw = L(yp - ~yp) = Lyp - L ~yp = (2x + 1) - (2x + 1) = 0.

So w = y - ~y p p is a solution to (2.7), that is Lw = 0 . Any two solutions of (2.6) differ by a solution to the homogeneous equation (2.7). The solution y = yc + yp includes all solutions to (2.6), since yc 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 yc be the complementary solution (the general solution to the associated homogeneous equation Ly = 0 ) and let yp be any particular solution to Ly = f(x) . Then the general solution to Ly = f(x) is

y = yc + yp.

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 will have to choose to satisfy the initial conditions may be different, but it is the same solution.

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

yp = Ax + B.

We plug in to obtain

y′′p + 5y′p + 6yp = (Ax + B )′′ + 5(Ax + B )′ + 6(Ax + B) = 0 + 5A + 6Ax + 6B = 6Ax + (5A + 6B).

So 6Ax + (5A + 6B ) = 2x + 1 . Therefore, A = 1∕3 and B = -1∕9 . That means yp = 13x - 19 = 3x9-1 . Solving the complementary problem (exercise!) we get

y = C e-2x + C e-3x. c 1 2

Hence the general solution to (2.6) is

y = C1e-2x + C2e-3x + 3x --1-. 9

Now suppose we are further given some initial conditions. For example, y(0) = 0 and y′(0) = 1∕3 . First find y′ = -2C 1e-2x - 3C2e-3x + 1∕3 . Then

 1- 1- ′ 1- 0 = y(0) = C1 + C2 - 9, 3 = y (0) = -2C 1 - 3C 2 + 3.

We solve to get C = 1∕3 1 and C = -2∕9 2 . The particular solution we want is

 1--2x 2--3x 3x---1 3e-2x---2e-3x +-3x---1 y (x) = 3e - 9e + 9 = 9 .

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 yp after that. That will not work. You need to first compute y = yc + yp 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,

 ′′ ′ y + 2y + 2y = cos(2x).

Let us find some yp . We start by guessing the solution includes some multiple of cos(2x ) . We may have to also add a multiple of sin(2x) to our guess since derivatives of cosine are sines. We try

yp = A cos(2x) + B sin (2x ).

We plug yp into the equation and we get

-4A cos(2x) - 4B sin(2x) - 4A sin(2x) + 4B cos(2x) + 2A cos(2x ) + 2B sin(2x ) = c

The left hand side must equal to right hand side. We group terms and we get that - 4A + 4B + 2A = 1 and - 4B - 4A + 2B = 0 . So - 2A + 4B = 1 and 2A + B = 0 and hence  -1 A = ∕10 and  1 B = ∕5 . So

 - cos(2x) + 2 sin(2x ) yp = A cos(2x ) + B sin(2x) =--------------------. 10

Similarly, if the right hand side contains exponentials we try exponentials. For example, for

Ly = e 3x,

we will try  3x y = Ae as our guess and try to solve for A .

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 yp such that Lyp is of the same form, and has all the terms needed to for the right hand side. For example,

Ly = (1 + 3x2)e-xcos(πx).

For this equation, we will guess

 2 -x 2 -x yp = (A + Bx + Cx )e c os(πx ) + (D + Ex + Fx )e sin(πx).

We will plug in and then hopefully get equations that we can solve for A, B,C, D,E, and F . 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

y′′ - 9y = e3x.

We would love to guess y = Ae 3x , but if we plug this into the left hand side of the equation we get

 ′′ 3x 3x 3x y - 9y = 9Ae - 9Ae = 0 ⇔ e .

There is no way we can choose A to make the left hand side be e3x . 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 yc (solution to Ly = 0 )

yc = C 1e-3x + C2e3x

and we note that the e3x term is a duplicate with our desired guess. We modify our guess to y = Axe 3x and notice there is no duplication anymore. Let us try. Note that  ′ 3x 3x y = Ae + 3Axe and  ′′ 3x 3x y = 6Ae + 9Axe . So

y′′ - 9y = 6Ae3x + 9Axe 3x - 9Axe 3x = 6Ae 3x.

Thus 6Ae 3x is supposed to equal e3x . Hence, 6A = 1 and so A = 1∕6 . We can now write the general solution as

y = yc + yp = C 1e-3x + C 2e3x + 1-xe3x. 6

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

 ′′ ′ 3x y - 6y + 9y = e .

The complementary solution is yc = C1e3x + C 2xe3x . Guessing y = Axe3x would not get us anywhere. In this case we want to guess yp = Ax 2e3x . 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

 2x Ly = e + cos x.

In this case we find u that solves Lu = e2x and v that solves Lv = cos x (that is, do each term separately). Then note that if y = u + v , then Ly = e2x + co sx . This is because L is linear; we have Ly = L (u + v) = Lu + Lv = e2x + cosx .

2.5.3 Variation of parameters

The method of undetermined coefficients will work 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 only finitely many linearly independent derivatives, so that we can write a guess that consists of them all. Some equations are a bit tougher. Consider

 ′′ y + y = tanx.

Note that each new derivative of tan x looks completely different and cannot be written as a linear combination of the previous derivatives. We get sec2x , 2 sec2x tan x , etc….

This equation calls for a different method. We present the method of variation of parameters, which will handle any equation of the form Ly = f(x) , 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

 ′′ Ly = y + y = tan x.

First we find the complementary solution (solution to Lyc = 0 ). We get yc = C 1y1 + C2y2 , where y1 = cosx and y2 = sin x . To find a particular solution to the nonhomogeneous equation we try

yp = y = u 1y1 + u2y2,

where u 1 and u2 are functions and not constants. We are trying to satisfy Ly = tan x . That gives us one condition on the functions u1 and u2 . Compute (note the product rule!)

 ′ ′ ′ ′ ′ y = (u1y1 + u2y2) + (u 1y1 + u2y2).

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′y1 + u′y2) = 0 1 2 . This makes computing the second derivative easier.

y′ = u y′+ u y′, ′′ 1′1′ 2 2′ ′ ′′ ′′ y = (u1y1 + u2y2) + (u 1y1 + u2y2).
Since y1 and y2 are solutions to y′′ + y = 0 , we know that y′′1 = -y1 and y′′2 = -y2 . (Note: If the equation was instead y′′ + p(x)y′ + q(x)y = 0 we would have y′i′= -p (x )y′i - q (x)yi .) So
 ′′ ′ ′ ′ ′ y = (u1y1 + u2y2) - (u1y1 + u2y2).

We have (u 1y1 + u2y2) = y and so

 ′′ ′ ′ ′ ′ y = (u1y1 + u2y2) - y,

and hence

 ′′ ′ ′ ′ ′ y + y = Ly = u1y1 + u2y2.

For y to satisfy Ly = f(x) we must have f (x ) = u′1y′1 + u ′2y′2 .

So what we need to solve are the two equations (conditions) we imposed on u 1 and u 2

|--′-----′-----------| | u1y1 + u2y2 = 0, | | u′1y′1 + u′2y′2 = f(x).| ----------------------

We can now solve for u′ 1 and u′ 2 in terms of f (x) , y1 and y2 . We will always get these formulas for any Ly = f(x) , where  ′′ ′ Ly = y + p (x)y + q(x)y . There is a general formula for the solution we can just plug into, but it is better to just repeat what we do below. In our case the two equations become

 u′1cos(x) + u′2 sin(x) = 0, ′ ′ - u1sin(x) + u2cos(x) = tan (x).
Hence
 u′1cos(x)sin(x) + u′2sin2(x) = 0, ′ ′ 2 -u1 sin(x)cos(x) + u2cos (x) = tan(x)cos(x) = sin(x).
And thus
 ′( 2 2 ) u2 sin (x) + cos (x) = sin(x), u′= sin(x), 2 2 ′ --sin-(x)- u1 = cos(x) = - tan(x)sin(x).
Now we need to integrate  ′ u1 and  ′ u2 to get u1 and u2 .
 ∫ ∫ ′ 1 |||sin(x) - 1 ||| u1 = u1 dx = - tan(x)sin(x) dx = -ln ||-------- || + sin(x), ∫ ∫ 2 sin(x) + 1 u = u′ dx = sin(x) dx = - cos(x ). 2 2
So our particular solution is
 | | y = u y + u y = 1co s(x)ln |||sin(x) --1 |||+ cos(x) sin(x) - co s(x)sin(x) = p 11 2 2 2 |sin(x) + 1 | 1 ||sin(x) - 1|| = --cos(x)ln |||---------|||. 2 sin(x) + 1
The general solution to y′′ + y = tanx is, therefore,
 || || y = C1 cos(x ) + C2 sin(x) + 1cos(x)ln ||sin(x) --1 ||. 2 |sin(x) + 1 |

2.5.4 Exercises

Exercise 2.5.2: Find a particular solution of y′′ - y′ - 6y = e2x .

Exercise 2.5.3: Find a particular solution of y′′ - 4y′ + 4y = e2x .

Exercise 2.5.4: Solve the initial value problem y′′ + 9y = cos(3x) + sin(3x) for y(0) = 2 , y′(0) = 1 .

Exercise 2.5.5: Setup the form of the particular solution but do not solve for the coefficients for y(4) - 2y′′′ + y′′ = ex .

Exercise 2.5.6: Setup the form of the particular solution but do not solve for the coefficients for y(4) - 2y′′′ + y′′ = ex + x + sin x .

Exercise 2.5.7: a) Using variation of parameters find a particular solution of y′′ - 2y′ + y = ex . b) Find a particular solution using undetermined coefficients. c) Are the two solutions you found the same? What is going on?

Exercise 2.5.8: Find a particular solution of y′′ - 2y′ + y = sin(x2) . 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 = ecx . Hint: Make sure to handle every possible real c .

Exercise 2.5.101: Find a particular solution to y′′ - y′ + y = 2sin(3x)

Exercise 2.5.102: a) Find a particular solution to y′′ + 2y = ex + x3 . b) Find the general solution.

Exercise 2.5.103: Solve y′′ + 2y′ + y = x2 , y(0) = 1 , y′(0) = 2 .

Exercise 2.5.104: Use variation of parameters to find a particular solution of  ′′ --1-- y - y = ex+e-x .

Exercise 2.5.105: For an arbitrary constant c find the general solution to y′′ - 2y = sin (x + c) .