Artificial Intelligence 🤖
Differential equations
Ordinary differential equations
Nonhomogeneous LODEs with constant coefficients

Nonhomogeneous LODEs with constant coefficients

In Section 13.2 we solved the homogeneous equation with constant coefficients, i.e. Eq. (13.18) through the associated characteristic equation. Here, we look at solutions to the nonhomogeneous equation given by Eq. (13.1). This section focuses on the method of undetermined coefficients (MUC), which applies to the case where P(x),Q(x)P(x), Q(x) in Eq. (13.1) are replaced by constants, p,qp, q and when f(x)f(x) has a finite number of linearly independent derivatives (see Subsec. 13.3.2 for details). The nonhomogeneous equation with constant coefficients is given by Eq. (13.62),

y+py+qy=f(x).y^{\prime \prime}+p y^{\prime}+q y=f(x) .

Before we proceed to see how to use the MUC to solve (13.62), let us look at the structure of the general solution to the nonhomogeneous ODE given by (13.1) without requiring that P(x)P(x) and Q(x)Q(x) are constants and without the restriction of finite linearly independent derivatives of f(x)f(x).

Nonhomogeneous equations: general solution

The general solution to the nonhomogeneous ODE (13.1) is given as

y(x)=yh(x)+yp(x),y(x)=y_{h}(x)+y_{p}(x),

where yhy_{h} is the solution to the homogeneous ODE given by (13.2) and ypy_{p} is any particular solution to the nonhomogeneous ODE (13.1). This general solution structure is true for any linear nonhomogeneous ODE.

Proof

Here, we show that y=yh+ypy=y_{h}+y_{p} given by (13.63) is a solution to Eq. (13.1). We start off by assuming that yy is a solution to the nonhomogeneous ODE so it satisfies Eq. (13.1). We also assume that whatever ypy_{p} is, it should also satisfy Eq. (13.1) such that,

yp+P(x)yp+Q(x)yp=f(x).y_{p}^{\prime \prime}+P(x) y_{p}^{\prime}+Q(x) y_{p}=f(x) .

Now, take Eq. (13.64) and subtract it from (13.1):

(yyp)+P(x)(yyp)+Q(x)(yyp)=0.\left(y-y_{p}\right)^{\prime \prime}+P(x)\left(y-y_{p}\right)^{\prime}+Q(x)\left(y-y_{p}\right)=0 .

Equation (13.65) looks like the homogeneous equation given by (13.2). This implies that yypy-y_{p} must be a solution to the homogeneous ODE which, in turn, implies that the difference, yypy-y_{p} must equal to yhy_{h} (the solution to the homogeneous equation):

yyp=yhy-y_{p}=y_{h}

which is,

y=yh+ypy=y_{h}+y_{p}

So, yy is a solution to the nonhomogeneous equation and it is made up of yhy_{h} and ypy_{p} as shown in Eq. (13.67). When solving the ODE (13.1), we need to first solve the homogeneous ODE (13.2) to obtain yhy_{h}, and then find a particular solution ypy_{p} so we can put it together with yhy_{h} and form the general solution to the nonhomogeneous problem.

The method of undetermined coefficients

We are now ready to look for solutions to Eq. (13.62), where pp and qq are constants and f(x)0f(x) \neq 0. Note that sometimes the f(x)f(x) term is referred to as the forcing term.

When does the method work?

Before we introduce the method let us just state when it can be used. The MUC can only be used when:

  1. the ODE is linear (works for higher order LODEs as well);
  2. the coefficients of the derivatives of the function yy are constant (i.e. for second order, pp and qq are constants);
  3. f(x)f(x) consists of the following classes of functions:

(a) exponentials;

(b) sines & cosines;

(c) polynomials.

Sums and products of these functions work as well. These types of functions are the only ones that work with this method and the underlying reason has to do with linear independence. What all of the above classes of functions have in common is that they have a finite number of linearly independent derivatives. We refer to these functions as 'elementary' in these notes. For example, take the function f(x)=sinxf(x)=\sin x and differentiate wrt xx a few times:

f=cosx,f=sinx, etc f^{\prime}=\cos x, f^{\prime \prime}=-\sin x, \text { etc }

The functions f=sinxf=\sin x and f=cosxf^{\prime}=\cos x are linearly independent. The next order derivative i.e f=sinxf^{\prime \prime}=-\sin x is linearly dependent to the original function. As an additional example consider the polynomial f(x)=x3f(x)=x^{3}; the first three derivatives are:

f=3x2,f=6x,f=6.f^{\prime}=3 x^{2}, f^{\prime \prime}=6 x, f^{\prime \prime \prime}=6 .

Each function produced by the next derivative is linearly independent to the previous ones; however the addition of the fourth derivative, which is equal to 0 , renders the set linearly dependent. Recall that you can check for linear independence using the Wronskian determinant (see Section 13.1.2). To contrast the above, consider the functions f(x)=1/xf(x)=1 / x and f(x)=lnxf(x)=\ln x; these functions have an infinite number of linearly independent derivatives: as you differentiate them wrt xx, you obtain higher and higher powers of xx in the denominator.

The only functions that have the property of having a finite number of linearly independent derivatives are the three classes specified above. In what follows, we will look at examples where the forcing term, i.e. f(x)f(x), is made up of exponentials, sines and cosines, or polynomials.

Exponentials

Consider the nonhomogeneous ODE,

y3y4y=3e2x.y^{\prime \prime}-3 y^{\prime}-4 y=3 e^{2 x} .

We know that the general solution to a nonhomogeneous ODE is made up of the solution to the homogeneous version of Eq. (13.68), i.e.

y3y4y=0y^{\prime \prime}-3 y^{\prime}-4 y=0

together with a particular solution to (13.68). The solution to (13.69) is:

yh(x)=c1e4x+c2ex.y_{h}(x)=c_{1} e^{4 x}+c_{2} e^{-x} .

Next, we move on to obtaining a particular solution to the nonhomogeneous ODE using the MUC. The method really boils down to having an educated guess for ypy_{p}. We obtain a first guess by looking at the forcing term, f(x)f(x) and choosing ypy_{p} to have a similar form. So, in this case, since f(x)=3e2xf(x)=3 e^{2 x}, our guess for a particular solution is

yp(x)=Ae2x,y_{p}(x)=A e^{2 x},

where AA is the undetermined coefficient that we need to determine. Note that the exponent in ypy_{p} matches the one in the exponential function in f(x)f(x). All we are left to do is determine AA and, if everything works out smoothly, Eq. (13.71) should give us a particular solution to (13.68).

We proceed as follows. We want to determine AA in such a way that ypy_{p} satisfies (13.68). If ypy_{p} is to satisfy the nonhomogeneous equation, then we expect the following equation to hold true,

yp3yp4yp=3e2x.y_{p}^{\prime \prime}-3 y_{p}^{\prime}-4 y_{p}=3 e^{2 x} .

From Eq. (13.71), we obtain ypy_{p}^{\prime} and ypy_{p}^{\prime \prime}

yp=2Ae2x,yp=4Ae2x.\begin{aligned} & y_{p}^{\prime}=2 A e^{2 x}, \\ & y_{p}^{\prime \prime}=4 A e^{2 x} . \end{aligned}

Next, we substitute Eqs. (13.71), (13.73) and (13.74) in (13.72):

(4A6A4A)e2x=3e2x.(4 A-6 A-4 A) e^{2 x}=3 e^{2 x} .

Finally, comparing coefficients of e2xe^{2 x} on both sides of (13.75), we get A=1/2A=-1 / 2. Substituting A=1/2A=-1 / 2 in Eq. (13.71) we have

yp=12e2xy_{p}=-\frac{1}{2} e^{2 x}

as the desired particular solution. Putting together the homogeneous solution and the particular solution just found, we obtain the general solution to (13.68) as,

y(x)=c1e4x+c2ex12e2x.y(x)=c_{1} e^{4 x}+c_{2} e^{-x}-\frac{1}{2} e^{2 x} .

Failure of first guess

The method of undetermined coefficients is a relatively simple 'guessing' method which seems to work well, albeit for a small class of functions. However, there are situations where the method will fail to allow us to determine the undetermined coefficient(s). More specifically, this will happen when f(x)f(x) contains a function which already appears in the homogeneous solution.

For example, if we were looking for a particular solution satisfying

y3y4y=4e4x,y^{\prime \prime}-3 y^{\prime}-4 y=4 e^{4 x},

and started off with a guess yp=Ae4xy_{p}=A e^{4 x} then, it follows (and it is easily verified) that substituting ypy_{p} in y3y4yy^{\prime \prime}-3 y^{\prime}-4 y, yields zero; this isn't surprising since we already know that e4xe^{4 x} is one of the fundamental solutions satisfying the homogeneous equation. With the LHS of (13.77) being zero though, the undetermined coefficient, AA, vanishes and we are left with no way of determining it. As a general rule, if f(x)f(x) clashes with one of the fundamental solutions in yhy_{h}, we multiply our initial guess of ypy_{p} with xx (or higher powers of xx if needed 25{ }^{25} ). For instance, in the ODE given by (13.77), our first initial guess of yp=Ae4xy_{p}=A e^{4 x} does not work since this is the same solution as one of the fundamental solutions (ignoring constants). Our 'educated' guess therefore for ypy_{p} becomes yp=Axe4xy_{p}=A x e^{4 x}. If we now proceed to determine AA as before, we find that A=4/5A=4 / 5 and our desired particular solution is

yp=45xe4xy_{p}=\frac{4}{5} x e^{4 x}

Sines & cosines

Now, consider the same ODE as before [Eq. (13.68)] with the RHS replaced by a sine term,

y3y4y=2sinx.y^{\prime \prime}-3 y^{\prime}-4 y=2 \sin x .

The homogeneous solution is given by (13.70). The RHS of (13.78) is f(x)=2sinxf(x)=2 \sin x and we note that f(x)f(x) does not contain any terms that belong in the homogeneous solution. So, in this case we can go ahead and guess a form of ypy_{p} that is similar to 2sinx2 \sin x,

yp=Asinx.y_{p}=A \sin x .

So, we have assumed a form of ypy_{p} which we hope it works and again, all we are left to determine is AA. Upon differentiating yp=Asinxy_{p}=A \sin x and substituting in Eq. (13.78), we have,

5Asinx3Acosx=2sinx+0cosx.-5 A \sin x-3 A \cos x=2 \sin x+0 \cos x .

Note we have included the +0cosx+0 \cos x term on the RHS of (13.80) to easily compare coefficients of sinx\sin x and cosx\cos x on both sides. It is obvious that we cannot determine AA since the two equations we are left with, i.e.

5A=2 and 3A=0-5 A=2 \text { and } 3 A=0

leave us with no choice of AA that satisfies both of them.

25{ }^{25} This can happen when xyp(x)x y_{p}(x) also clashes with the functions comprising the homogeneous solution. We need to rethink our guess of ypy_{p}. To determine AA correctly, we must include all the linearly independent derivatives of f(x)f(x). In this case, the set of linearly independent functions is {sinx,cosx}\{\sin x, \cos x\}. A better guess therefore would be to start off with a ypy_{p} that includes both sine and cosine terms

yp=Asinx+Bcosx,y_{p}=A \sin x+B \cos x,

where AA and BB are the undetermined coefficients. Differentiating (13.82) to get yp,ypy_{p}^{\prime}, y_{p}^{\prime \prime} and substituting back in (13.78) gives us:

(5A+3B)sinx+(5B3A)cosx=2sinx(-5 A+3 B) \sin x+(-5 B-3 A) \cos x=2 \sin x

Comparing coefficients of sinx\sin x and cosx\cos x, we have A=5/17A=-5 / 17 and B=3/17B=3 / 17. The desired particular solution is therefore,

yp=517sinx+317cosxy_{p}=-\frac{5}{17} \sin x+\frac{3}{17} \cos x

and the general solution is,

y(x)=c1e4x+c2ex517sinx+317cosx.y(x)=c_{1} e^{4 x}+c_{2} e^{-x}-\frac{5}{17} \sin x+\frac{3}{17} \cos x .

Polynomials

For our final example we consider

y3y4y=x2,y^{\prime \prime}-3 y^{\prime}-4 y=x^{2},

where f(x)=x2f(x)=x^{2}.

Again, the homogeneous solution is given by (13.70). Though it would make sense to choose yp=Ax2y_{p}=A x^{2} to match f(x)f(x), for the same reasons discussed in Subsec. 13.3.4, we choose a form for ypy_{p} that contains x2x^{2} as well as all its linearly independent derivatives. Ignoring coefficients, the set of linearly independent functions is {x2,x,1}\left\{x^{2}, x, 1\right\}. So, our chosen form for ypy_{p} is:

yp=Ax2+Bx+Cy_{p}=A x^{2}+B x+C

where A,BA, B, and CC are to be determined. Proceeding in the same way as for the previous examples, we take (13.87), differentiate wrt xx for ypy_{p}^{\prime} and ypy_{p}^{\prime \prime} and substitute in (13.86). This gives,

4Ax2+x(6A4B)+(4C+2A3B)=x2.-4 A x^{2}+x(-6 A-4 B)+(-4 C+2 A-3 B)=x^{2} .

Comparing coefficients of x2,xx^{2}, x and the constants on both sides (note on the RHS the only term is x2x^{2} which means that coefficients of xx and the constants, are 0 ):

4A=1,6A+4B=0 and 4C+2A3B=0.-4 A=1, \quad 6 A+4 B=0 \text { and }-4 C+2 A-3 B=0 .

From Eqs. (13.89), we have A=1/4,B=3/8A=-1 / 4, B=3 / 8, and C=13/32C=-13 / 32. Hence, the desired particular solution is,

yp=14x2+38x1332.y_{p}=-\frac{1}{4} x^{2}+\frac{3}{8} x-\frac{13}{32} .

Putting yhy_{h} and ypy_{p} together, gives the general solution to (13.86) as:

y(x)=c1e4x+c2ex14x2+38x1332.y(x)=c_{1} e^{4 x}+c_{2} e^{-x}-\frac{1}{4} x^{2}+\frac{3}{8} x-\frac{13}{32} .

Example 13.5 Find the general solution to the following nonhomogeneous ODE:

y2y3y=4x5+6e2x.y^{\prime \prime}-2 y^{\prime}-3 y=4 x-5+6 e^{2 x} .

Solution The solution is y=yh+ypy=y_{h}+y_{p} where yhy_{h} is the homogeneous solution with characteristic equation

m22m3=0m^{2}-2 m-3=0

with roots m1=3m_{1}=3 and m2=1m_{2}=-1 yielding

yh=c1e3x+c2ex.y_{h}=c_{1} e^{3 x}+c_{2} e^{-x} .

Next we solve for ypy_{p} using the MUC. We break the RHS of (13.92) into two functions, one made up of the polynomials, i.e. f1(x)=4x5f_{1}(x)=4 x-5 and another made up of the exponential, f2(x)=6e2xf_{2}(x)=6 e^{2 x}. For the particular solution corresponding to f1(x)f_{1}(x), we have

yp1=Ax+By_{p_{1}}=A x+B

while for f2(x)f_{2}(x),

yp2=Ce2x.y_{p_{2}}=C e^{2 x} .

Putting the two guesses together we have

yp=Ax+B+Ce2x,y_{p}=A x+B+C e^{2 x},

where A,BA, B, and CC are constants to be determined. Since the functions in ypy_{p} do not clash with yhy_{h}, we can proceed using (13.94) to obtain the particular solution.

Products of exponentials, polynomials & sines and cosines

As mentioned earlier, the MUC can be used when the forcing function is made up of products of elementary functions. We carry out an example where the forcing term is made up of a product of the simple forms of f(x)f(x) discussed above. Consider,

y+4y=xcosx.y^{\prime \prime}+4 y=x \cos x .

In this case, the homogeneous solution is given by yh(x)=c1cos(2x)+c2sin(2x)y_{h}(x)=c_{1} \cos (2 x)+c_{2} \sin (2 x). The forcing term is f(x)=xcosxf(x)=x \cos x which is the product of a polynomial (degree 1 ) and the cosine function. A reasonable guess for ypy_{p} would therefore be to start from the product of a polynomial guess and the cosine/sine guess. The correct form of the trial solution for ypy_{p} should be a linear combination of all the linearly independent derivatives. Let us see what this means with the example in (13.95). Since f(x)=xcosxf(x)=x \cos x then,

f(x)=xsinx+cosxf(x)=xcosx2sinxf(x)=xsinx3cosx\begin{aligned} f^{\prime}(x) & =-x \sin x+\cos x \\ f^{\prime \prime}(x) & =-x \cos x-2 \sin x \\ f^{\prime \prime \prime}(x) & =x \sin x-3 \cos x \end{aligned}

We observe that the third derivative, f(x)f^{\prime \prime \prime}(x) does not generate any linearly independent derivatives to the functions included in f(x)f^{\prime}(x) and f(x)f^{\prime \prime}(x). The set of linearly independent functions we need to consider are:

{xcosx,xsinx,cosx,sinx}.\{x \cos x, x \sin x, \cos x, \sin x\} .

It follows that a good first guess for ypy_{p} is,

yp=(Ax+B)cosx+(Cx+D)sinxy_{p}=(A x+B) \cos x+(C x+D) \sin x

where A,B,CA, B, C and DD are the coefficients we need to determine.

Independent coefficients

We note that the undetermined coefficients multiplying each linearly independent function in ypy_{p} need to be independent from each other. A common mistake is to start from the following ypy_{p} as a guess for the solution to (13.95):

yp=(Ax+B)(Ccosx+Dsinx).y_{p}=(A x+B)(C \cos x+D \sin x) .

Now, while we still get 4 unknown coefficients, AA - DD in (13.97), they are not independent. Given any 3, we can determine the fourth one. We can see this by expanding Eq. (13.97),

yp=ACxcosx+BCcosx+ADxsinx+BDsinx.y_{p}=A C x \cos x+B C \cos x+A D x \sin x+B D \sin x .

From (13.98), the four unknown coefficients are A1=AC,A2=BC,A3=ADA_{1}=A C, A_{2}=B C, A_{3}=A D, and A4=BDA_{4}=B D. They are not independent however since, given any 3 , say A1,A2A_{1}, A_{2}, and A3A_{3}, we can determine A4A_{4}.

Summary

Given a second order linear, nonhomogeneous equation

y+P(x)y+Q(x)y=f(x)y^{\prime \prime}+P(x) y^{\prime}+Q(x) y=f(x)

its general solution is given by

y(x)=yh(x)+yp(x),y(x)=y_{h}(x)+y_{p}(x),

where yh(x)y_{h}(x) is the solution to the homogeneous ODE (when f(x)=0f(x)=0 ) and yp(x)y_{p}(x) is a particular solution to the nonhomogeneous equation. We use the MUC to obtain a particular solution to (13.99) when the coefficients PP and QQ are constants and when f(x)f(x) takes an exponential function, sines and/or cosines, polynomials or any sums and products of the aforementioned classes of functions. A key point to remember is that the form of ypy_{p} is a linear combination of all linearly independent functions that are generated by repeated differentiation of f(x)f(x).

Trial particular solutions

Table 13.1 summarises basic forms of f(x)f(x) that work with the method and the corresponding guess for yp(x)y_{p}(x). Finally, note that if f(x)f(x) contains a term that belongs to the homogeneous solution, then the guess for yp(x)y_{p}(x) included in Table 13.1, needs to be multiplied by xx (or, if needed, higher powers of xx ).