Differential Equations for EngineersXYZ Homework Edition

⇩ Download ▾

2.5 Nonhomogeneous Equations

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 + 5 y + 6 y = 2 x + 1 y'' + 5y' + 6y = 2x + 1 \label{2.5.1}

(2.5.1)

We will write Ly=2x+1Ly = 2x + 1 when the exact form of the operator is not important. We solve (Equation \ref{2.5.1}) in the following manner. First, we find the general solution ycy_c to the associated homogeneous equation

y + 5 y + 6 y = 0 \label{eq:2}y'' + 5y' + 6y = 0

(2.5.2)

We call ycy_c the complementary solution. Next, we find a single particular solution ypy_p to (2.5.1) in some way. Then

y = y c + y p y = y_c + y_p \nonumber

is the general solution to (2.5.1). We have Lyc=0Ly_c = 0 and Lyp=2x+1Ly_p = 2x +1. As LL is a linear operator we verify that yy is a solution, Ly=L(yc+yp)=Lyc+Lyp=0+(2x+1)Ly = L(y_c + y_p) = Ly_c + Ly_p = 0 + ( 2x + 1). Let us see why we obtain the general solution.

Let ypy_p and y~p{\tilde {y}}_p be two different particular solutions to (2.5.1). Write the difference as w=ypy~pw = y_p - {\tilde {y}}_p. Then plug ww into the left hand side of the equation to get

w + 5 w + 6 w = ( y p + 5 y p + 6 y p ) ( y ~ p + 5 y ~ p + 6 y ~ p ) = ( 2 x + 1 ) ( 2 x + 1 ) = 0 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 \nonumber

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

L w = L ( y p y ~ p ) = L y p L y ~ p = ( 2 x + 1 ) ( 2 x + 1 ) = 0 Lw = L (y_p - {\tilde {y}}_p ) = L y_p - L {\tilde {y}}_p = (2x + 1) - ( 2x + 1) = 0 \nonumber

So w=ypy~pw = y_p - {\tilde {y}}_p is a solution to (2.5.2), that is Lw=0Lw = 0. Any two solutions of (2.5.1) differ by a solution to the homogeneous equation (2.5.2). The solution y=yc+ypy = y_c + y_p includes all solutions to (2.5.1), since ycy_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 will have to choose to satisfy the initial conditions may be different, but it is the same solution.

Undetermined Coefficients

The trick is to somehow, in a smart way, guess one particular solution to (2.5.1). Note that 2x+12x + 1 is a polynomial, and the left hand side of the equation will be a polynomial if we let yy be a polynomial of the same degree. Let us try

y p = A x + B y_p = Ax + B \nonumber

We plug in to obtain

y p + 5 y p + 6 y p = ( A x + B ) + 5 ( A x + B ) + 6 ( A x + B ) = 0 + 5 A + 6 A x + 6 B = 6 A x + ( 5 A + 6 B ) \begin{align}\begin{aligned} y_p'' + 5y_p' + 6y_p &= (Ax + B)'' + 5( Ax + B)' + 6(Ax + B) \\ &= 0 + 5A + 6Ax + 6B = 6Ax + ( 5A + 6B) \end{aligned}\end{align} \nonumber

So 6Ax+(5A+6B)=2x+16Ax + (5A + 6B) = 2x + 1. Therefore, A=13A = \dfrac {1}{3} and B=19B = - \dfrac {1}{9}. That means yp=13x19=3x19y_p = \dfrac {1}{3} x - \dfrac {1}{9} = \dfrac {3x - 1}{9}. Solving the complementary problem (exercise!) we get

y c = C 1 e 2 x + C 2 e 3 x y_c = C_1e^{-2x} + C_2 e^{-3x} \nonumber

Hence the general solution to (2.5.1) is

y = C 1 e 2 x + C 2 e 3 x + 3 x 1 9 y = C_1 e^{-2x} + C_2 e^{-3x} + \dfrac {3x - 1}{9} \nonumber

Now suppose we are further given some initial conditions. For example, y(0)=0y(0) = 0 and y(0)=13y' (0) = \dfrac {1}{3}. First find y=2C1e2x3C2e3x+13y' = -2C_1e^{-2x} - 3C_2e^{-3x} + \dfrac {1}{3}. Then

0 = y ( 0 ) = C 1 + C 2 1 9 , 1 3 = y ( 0 ) = 2 C 1 3 C 2 + 1 3 0 = y(0) = C_1 + C_2 - \dfrac {1}{9}, \dfrac {1}{3} = y'(0) = -2C_1 - 3C_2 + \dfrac {1}{3} \nonumber

We solve to get C1=13C_1 = \dfrac {1}{3} and C2=29C_2 = - \dfrac {2}{9}. The particular solution we want is

y ( x ) = 1 3 e 2 x 2 9 e 3 x + 3 x 1 9 = 3 e 2 x 2 e 3 x + 3 x 1 9 y(x) = \dfrac {1}{3} e^{-2x} - \dfrac {2}{9} e^{-3x} + \dfrac {3x - 1}{9} = \dfrac {3e^{-2x} - 2e^{-3x} + 3x - 1}{9} \nonumber

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

y + 2 y + 2 y = cos ( 2 x ) y'' + 2y' + 2y = \cos (2x) \nonumber

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

y p = A cos ( 2 x ) + B sin ( 2 x ) y_p = A \cos (2x) + B \sin (2x) \nonumber

We plug ypy_p into the equation and we get

4 A cos ( 2 x ) 4 B sin ( 2 x ) y p + 2 ( 2 A sin ( 2 x ) + 2 B cos ( 2 x ) ) y p + 2 ( A cos ( 2 x ) + 2 B sin ( 2 x ) ) y p = cos ( 2 x ) , \begin{gathered} \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{gathered} \nonumber

The left hand side must equal to right hand side. We group terms and we get that 4A+4B+2A=1-4A + 4B + 2A = 1 and 4B4A+2B=0-4B - 4A + 2B = 0. So 2A+4B=1-2A + 4B = 1 and 2A+B=02A + B = 0 and hence A=110A = \dfrac {-1}{10} and B=15B = \dfrac {1}{5}. So

y p = A cos ( 2 x ) + B sin ( 2 x ) = cos ( 2 x ) + 2 sin ( 2 x ) 10 y_p = A \cos (2x) + B \sin (2x) = \dfrac { - \cos (2x) + 2 \sin (2x) }{10} \nonumber

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

L y = e 3 x Ly = e^{3x} \nonumber

we will try y=Ae3xy = Ae^{3x} as our guess and try to solve for AA.

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

L y = ( 1 + 3 x 2 ) e x cos ( π x ) Ly = ( 1 + 3x^2) e^{-x} \cos ( \pi x ) \nonumber

For this equation, we will guess

y p = ( A + B x + C x 2 ) e x cos ( π x ) + ( D + E x + F x 2 ) e x sin ( π x ) y_p = ( A + Bx + Cx^2)e^{-x} \cos (\pi x) + ( D + Ex + Fx^2 ) e^{-x} \sin ( \pi x ) \nonumber

We will plug in and then hopefully get equations that we can solve for A,B,C,D,EA, B, C, D, Eand FF. As you can see this can make for a very long and tedious calculation very quickly.

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 9 y = e 3 x y'' - 9y = e^{3x} \nonumber

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

y 9 y = 9 A e 3 x 9 A e 3 x = 0 e 3 x y'' - 9y = 9Ae^{3x} - 9Ae^{3x} = 0 \ne e^{3x} \nonumber

There is no way we can choose AA to make the left hand side be e3xe^{3x}. The trick in this case is to multiply our guess by xx to get rid of duplication with the complementary solution. That is first we compute ycy_c (solution to Ly=0Ly = 0)

y c = C 1 e 3 x + C 2 e 3 x y_c = C_1e^{-3x} + C_2 e^{3x} \nonumber

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

y 9 y = 6 A e 3 x + 9 A x e 3 x 9 A x e 3 x = 6 A e 3 x y'' - 9y = 6Ae^{3x} + 9Axe^{3x} - 9Axe^{3x} = 6Ae^{3x} \nonumber

Thus 6Ae3x6Ae^{3x} is supposed to equal e3xe^{3x}. Hence, 6A=16A = 1 and so A=16A = \dfrac {1}{6}. We can now write the general solution as

y = y c + y p = C 1 e 3 x + C 2 e 3 x + 1 6 x e 3 x y = y_c + y_p = C_1e^{-3x} + C_2e^{3x} + \dfrac {1}{6} xe^{3x} \nonumber

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

y 6 y + 9 y = e 3 x y'' - 6y' + 9y = e^{3x} \nonumber

The complementary solution is yc=C1e3x+C2xe3xy_c = C_1e^{3x} + C_2xe^{3x}. Guessing y=Axe3xy = Axe^{3x} would not get us anywhere. In this case we want to guess yp=Ax2e3xy_p = Ax^2e^{3x}. Basically, we want to multiply our guess by xx 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

L y = e 2 x + cos x Ly = e^{2x} + \cos x \nonumber

In this case we find uu that solves Lu=e2xLu = e^{2x} and vv that solves Lv=cosxLv = \cos x (that is, do each term separately). Then note that if y=u+vy = u + v, then Ly=e2x+cosxLy = e^{2x} + \cos x. This is because LL is linear; we have Ly=L(u+v)=Lu+Lv=e2x+cosxLy = L(u + v) = Lu + Lv = e^{2x} + \cos x.

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)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 = tan x y'' + y = \tan x \nonumber

Note that each new derivative of tanx\tan x looks completely different and cannot be written as a linear combination of the previous derivatives. If we start differentiating tanx\tan x, we get

sec 2 x , 2 sec 2 x tan x , 4 sec 2 x tan 2 x + 2 sec 4 x , 8 sec 2 x tan 3 x + 16 sec 4 x tan x , 16 sec 2 x tan 4 x + 88 sec 4 x tan 2 x + 16 sec 6 x , \begin{gathered} \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{gathered} \nonumber

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

L y = y + y = tan x Ly = y'' + y = \tan x \nonumber

First we find the complementary solution (solution to Lyc=0Ly_c = 0). We get yc=C1y1+C2y2y_c = C_1y_1 + C_2y_2, where y1=cosxy_1 = \cos x and y2=sinxy_2 = \sin x. To find a particular solution to the nonhomogeneous equation we try

y p = y = u 1 y 1 + u 2 y 2 y_p = y = u_1y_1 + u_2y_2 \nonumber

where u1u_1 and u2u_2 are functions and not constants. We are trying to satisfy Ly=tanxLy = \tan x. That gives us one condition on the functions u1u_1 and u2u_2. Compute (note the product rule!)

y = ( u 1 y 1 + u 2 y 2 ) + ( u 1 y 1 + u 2 y 2 ) y' = (u'_1y_1 + u'_2y_2) + (u_1y'_1 + u_2y'_2) \nonumber

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 (u1y1+u2y2)=0(u'_1y_1 + u'_2y_2) = 0. This makes computing the second derivative easier.

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 ) \begin{align}\begin{aligned} y' &= u_1y'_1 + u_2y'_2 \\ y'' &= (u'_1y'_1 + u'_2y'_2) + (u_1y''_1 + u_2y''_2) \end{aligned}\end{align} \nonumber

Since y1y_1 and y2y_2 are solutions to y+y=0y'' +y = 0, we know that y1=y1y''_1 = -y_1 and y2=y2y''_2 = -y_2. (Note: If the equation was instead y+p(x)y+q(x)y=0y'' + p(x)y' + q(x)y = 0 we would have yi=p(x)yiq(x)yiy''_i = -p(x)y'_i - q(x) y_i.) So

y=(u1y1+u2y2)(u1y1+u2y2)y'' = ( u'_1y'_1 + u'_2y'_2) - (u_1y_1 + u_2y_2) \nonumber

We have (u1y1+u2y2)=y(u_1y_1 + u_2y_2) = y and so

y = ( u 1 y 1 + u 2 y 2 ) y y'' = (u'_1y'_1 + u'_2y'_2) - y \nonumber

and hence

y + y = L y = u 1 y 1 + u 2 y 2 y'' + y = Ly = u'_1y'_1 + u'_2y'_2 \nonumber

For yy to satisfy Ly=f(x)Ly = f(x) we must have f(x)=u1y1+u2y2f(x) =u'_1y'_1 + u'_2y'_2.

So what we need to solve are the two equations (conditions) we imposed on u1u_1 and u2u_2

u 1 y 1 + u 2 y 2 = 0 u 1 y 1 + u 2 y 2 = f ( x ) \begin{align}\begin{aligned} u'_1y_1 + u'_2y_2 &= 0 \\ u'_1y'_1 + u'_2y'_2 &= f(x) \end{aligned}\end{align} \nonumber

We can now solve for u1u'_1 and u2u'_2 in terms of f(x),y1f(x), y_1 and y2y_2. We will always get these formulas for any Ly=f(x)Ly = f(x), where Ly=y+p(x)y+q(x)yLy = 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 1 cos ( x ) + u 2 sin ( x ) = 0 u 1 sin ( x ) + u 2 cos ( x ) = tan ( x ) \begin{align}\begin{aligned} u'_1 \cos (x) + u'_2 \sin (x) &= 0 \\ -u'_1 \sin (x) + u'_2 \cos (x) &= \tan (x) \end{aligned}\end{align} \nonumber

Hence

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 ) \begin{align}\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{align} \nonumber

And thus

u 2 ( sin 2 ( x ) + cos 2 ( x ) ) = sin ( x ) u 2 = sin ( x ) u 1 = sin 2 ( x ) cos ( x ) = tan ( x ) sin ( x ) \begin{align}\begin{aligned} u'_2 ( {\sin}^2 (x) + {\cos}^2 (x)) &= \sin (x) \\ u'_2 &= \sin (x) \\ u'_1 &= \dfrac {-{\sin}^2 (x)}{ \cos (x)} = - \tan (x) \sin (x) \end{aligned}\end{align} \nonumber

Now we need to integrate u1u'_1 and u2u'_2 to get u1u_1 and u2u_2.

u 1 = u 1 d x = tan ( x ) sin ( x ) d x = 1 2 ln sin ( x ) 1 sin ( x ) + 1 + sin ( x ) u 2 = u 2 d x = sin ( x ) d x = cos ( x ) \begin{align}\begin{aligned} u_1 &= \int u'_1 dx = \int - \tan (x) \sin (x) dx = \dfrac {1}{2} \ln \mid \dfrac { \sin (x) - 1}{ \sin (x) + 1 } \mid + \sin (x) \\ u_2 &= \int u'_2 dx = \int \sin (x) dx = - \cos (x) \end{aligned}\end{align} \nonumber

So our particular solution is

y p = u 1 y 1 + u 2 y 2 = 1 2 cos ( x ) ln sin ( x ) 1 sin ( x ) + 1 + cos ( x ) sin ( x ) cos ( x ) sin ( x ) = 1 2 cos ( x ) ln sin ( x ) 1 sin ( x ) + 1 \begin{align}\begin{aligned} y_p &= u_1y_1 + u_2y_2 = \dfrac {1}{2} \cos (x) \ln \mid \dfrac { \sin (x) - 1}{ \sin (x) + 1} \mid + \cos (x) \sin (x) - \cos (x) \sin (x) \\ & = \dfrac {1}{2} \cos (x) \ln \mid \dfrac { \sin (x) - 1}{ \sin (x) + 1} \mid \end{aligned}\end{align} \nonumber

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

y = C 1 cos ( x ) + C 2 sin ( x ) + 1 2 cos ( x ) ln sin ( x ) 1 sin ( x ) + 1 y = C_1 \cos (x) + C_2 \sin (x) + \dfrac {1}{2} \cos (x) \ln \mid \dfrac {\sin (x) - 1}{\sin (x) + 1} \mid \nonumber

Adapted from Differential Equations for Engineers by Jiří Lebl (https://www.jirka.org/diffyqs/), © Jiří Lebl, licensed under CC BY-SA 4.0. Changes were made. License: CC-BY-SA-4.0.

These eBooks are a prerelease and are not yet certified conformant with WCAG 2.1 AA or ADA Title II. Every page is built against an automated accessibility gate, and the published editions will meet ADA Title II requirements when they release in late September 2026. If something is unusable, please tell us.