# Method of Undetermined Coefficients

This page is about second order differential equations of this type:

\frac{d^{2}y}{dx^{2}} + P(x)\frac{dy}{dx} + Q(x)y = f(x)

where P(x), Q(x) and f(x) are functions of x.

The simpler case where f(x) = 0:

\frac{d^{2}y}{dx^{2}} + P(x)\frac{dy}{dx} + Q(x)y = 0

is "homogeneous" and is explained on Introduction to Second Order Differential Equations. Please learn that method first to help you understand this page.

## Two Methods

There are two main methods to solve equations like

\frac{d^{2}y}{dx^{2}} + P(x)\frac{dy}{dx} + Q(x)y = f(x)

Variation of Parameters which is a little messier but works on a wider range of functions.

**Undetermined Coefficients** (that we will learn here) which only works when f(x) is a polynomial, exponential, sine, cosine or a linear combination of those.

## Undetermined Coefficients

To keep things simple, we only look at the case:

\frac{d^{2}y}{dx^{2}} + p\frac{dy}{dx} + qy = f(x)

where **p** and **q** are constants.

The **complete solution** to such an equation can be found by combining two types of solution:

- The
**general solution**of the homogeneous equation **Particular solutions**of the non-homogeneous equation

\frac{d^{2}y}{dx^{2}} + p\frac{dy}{dx} + qy = 0

\frac{d^{2}y}{dx^{2}} + p\frac{dy}{dx} + qy = f(x)

Note that f(x) could be a single function or a sum of two or more functions.

Once we have found the general solution and all the particular solutions, then the final complete solution is found by adding all the solutions together.

### **Example 1:**

The homogeneous equation \frac{d^{2}y}{dx^{2}} − y = 0 has a general solution y = Ae^{x} + Be^{−x}

The non-homogeneous equation \frac{d^{2}y}{dx^{2}} − y = 2x^{2} − x − 3 has a particular solution

y = −2x^{2 }+ x − 1

So the complete solution of the differential equation **\frac{d^{2}y}{dx^{2}} − y = 2x ^{2} − x − 3 ** is

y = Ae^{x} + Be^{−x} − 2x^{2 }+ x − 1

Let’s check that the answer is correct:

y = Ae^{x} + Be^{−x} − 2x^{2 }+ x − 1

First and second derivatives:

\frac{dy}{dx} = Ae^{x} − Be^{−x} − 4x + 1

\frac{d^{2}y}{dx^{2}} = Ae^{x} + Be^{−x} − 4

So

\frac{d^{2}y}{dx^{2}} − y

= Ae^{x} + Be^{−x} − 4 − (Ae^{x} + Be^{−x} − 2x^{2 }+ x − 1)

= Ae^{x} + Be^{−x} − 4 − Ae^{x} − Be^{−x} + 2x^{2 }− x + 1

= 2x^{2} − x − 3

So, in this case we have shown that the answer is correct, but how do we find the particular solutions?

We can try *guessing* ... !

This method is only easy to apply if f(x) is one of the following:

And here is a guide to help us with a guess:

f(x) | y(x) guess |
---|---|

ae^{bx} | Ae^{bx} |

a cos(cx) + b sin(cx) | A cos(cx) + B sin(cx) |

kx^{n} (n=0,1,2,...) | A_{n}x^{n} + A_{n-1}x^{n-1} + … + A_{0} |

But there is one important rule that must be applied:

**You must first find the general solution to the homogeneous equation.**

You will see why as we continue on.

### **Example 1 (again)**: Solve \frac{d^{2}y}{dx^{2}} − y = 2x^{2} − x − 3

1. Find the general solution of

\frac{d^{2}y}{dx^{2}} − y = 0

The characteristic equation is: r^{2} − 1 = 0

Factor: (r − 1)(r + 1) = 0

r = 1 or −1

So the general solution of the differential equation is

y = Ae^{x} + Be^{−x}

2. Find the particular solution of

\frac{d^{2}y}{dx^{2}} − y = 2x^{2} − x − 3

We make a guess:

Let y = ax^{2} + bx + c

\frac{dy}{dx} = 2ax + b

\frac{d^{2}y}{dx^{2}} = 2a

Substitute these values into \frac{d^{2}y}{dx^{2}} − y = 2x^{2} − x − 3

2a − (ax^{2} + bx + c) = 2x^{2} − x − 3

2a − ax^{2} − bx − c = 2x^{2} − x − 3

− ax^{2} − bx + (2a − c) = 2x^{2} − x − 3

Equate coefficients:

x^{2} coefficients: | −a = 2 ⇒ a = −2 ... (1) |

x coefficients: | −b = −1 ⇒ b = 1 ... (2) |

Constant coefficients: | 2a − c = −3 ... (3) |

Substitute a = −2 from (1) into (3)

−4 − c = −3

c = −1

a = −2, b = 1 and c = −1, so the particular solution of** **the differential** **equation is** **

**y = − 2x ^{2} + x − 1**

Finally, we combine our two answers to get the complete solution:

**y = Ae ^{x} + Be^{−x} − 2x^{2 }+ x − 1**

Why did we guess y = ax^{2} + bx + c (a quadratic function) and not include a cubic term (or higher)?

The answer is simple. The function f(x) on the right side of the differential equation has no cubic term (or higher); so, if y did have a cubic term, its coefficient would have to be zero.

**Hence, for a differential equation of the type **

**\frac{d^{2}y}{dx^{2}} + p\frac{dy}{dx} + qy = f(x)**

**where f(x) is a polynomial of degree n, our guess for y will also be a polynomial of degree n.**

### **Example 2:** Solve

6\frac{d^{2}y}{dx^{2}} − 13\frac{dy}{dx} − 5y = 5x^{3} + 39x^{2} − 36x − 10

The characteristic equation is: 6r^{2} − 13r − 5 = 0

Factor: (2r − 5)(3r + 1) = 0

r = \frac{5}{2} or −\frac{1}{3}

So the general solution of the differential equation is

**y = Ae ^{(5/2)x} + Be^{(−1/3)x }**

2. Find the particular solution of 6\frac{d^{2}y}{dx^{2}} − 13\frac{dy}{dx} − 5y = 5x^{3} + 39x^{2} − 36x − 10

Guess a cubic polynomial because 5x^{3} + 39x^{2} − 36x − 10 is cubic.

Let y = ax^{3} + bx^{2} + cx + d

\frac{dy}{dx} = 3ax^{2} + 2bx + c

\frac{d^{2}y}{dx^{2}} = 6ax + 2b

Substitute these values into 6\frac{d^{2}y}{dx^{2}} − 13\frac{dy}{dx} −5y = 5x^{3} + 39x^{2} −36x −10

6(6ax + 2b) − 13(3ax^{2} + 2bx + c) − 5(ax^{3} + bx^{2} + cx + d) = 5x^{3} + 39x^{2} − 36x − 10

36ax + 12b − 39ax^{2 }− 26bx − 13c − 5ax^{3} − 5bx^{2} − 5cx − 5d = 5x^{3} + 39x^{2} − 36x − 10

−5ax^{3} + (−39a − 5b)x^{2} + (36a − 26b - 5c)x + (12b − 13c − 5d) = 5x^{3} + 39x^{2} − 36x − 10

Equate coefficients:

x^{3} coefficients: | −5a = 5 ⇒ a = −1 |

x^{2} coefficients: | −39a −5b = 39 ⇒ b = 0 |

x coefficients: | 36a −26b −5c = −36 ⇒ c = 0 |

Constant coefficients: | 12b − 13c −5d = −10 ⇒ d = 2 |

So the particular solution is:

**y = −x ^{3} + 2**

Finally, we combine our two answers to get the complete solution:

**y = Ae ^{(5/2)x} + Be^{(−1/3)x} − x^{3} + 2**

And here are some sample curves:

### **Example 3:** Solve \frac{d^{2}y}{dx^{2}} + 3\frac{dy}{dx} − 10y = −130cos(x) + 16e^{3x}

In this case we need to solve three differential equations:

1. Find the general solution to \frac{d^{2}y}{dx^{2}} + 3\frac{dy}{dx} − 10y = 0

2. Find the particular solution to \frac{d^{2}y}{dx^{2}} + 3\frac{dy}{dx} − 10y = −130cos(x)

3. Find the particular solution to \frac{d^{2}y}{dx^{2}} + 3\frac{dy}{dx} − 10y = 16e^{3x}

So, here’s how we do it:

1. Find the general solution to \frac{d^{2}y}{dx^{2}} + 3\frac{dy}{dx} − 10y = 0

The characteristic equation is: r^{2} + 3r − 10 = 0

Factor: (r − 2)(r + 5) = 0

r = 2 or −5

So the general solution of the differential equation is:

**y = Ae ^{2x}+Be^{−5x}**

2. Find the particular solution to \frac{d^{2}y}{dx^{2}} + 3\frac{dy}{dx} − 10y = −130cos(x)

Guess. Since f(x) is a cosine function, we guess that *y* is a linear combination of sine and cosine functions:

Try y = acos(x) + bsin(x)

\frac{dy}{dx} = − asin(x) + bcos(x)

\frac{d^{2}y}{dx^{2}} = − acos(x) − bsin(x)

Substitute these values into \frac{d^{2}y}{dx^{2}} + 3\frac{dy}{dx} − 10y = −130cos(x)

−acos(x) − bsin(x) + 3[−asin(x) + bcos(x)] − 10[acos(x)+bsin(x)] = −130cos(x)

cos(x)[−a + 3b − 10a] + sin(x)[−b − 3a − 10b] = −130cos(x)

cos(x)[−11a + 3b] + sin(x)[−11b − 3a] = −130cos(x)

Equate coefficients:

Coefficients of cos(x): | −11a + 3b = −130 ... (1) |

Coefficients of sin(x): | −11b − 3a = 0 ... (2) |

From equation (2), a = −\frac{11b}{3}

Substitute into equation (1)

\frac{121b}{3} + 3b = −130

\frac{130b}{3} = −130

b = −3

a = −\frac{11(−3)}{3} = 11

So the particular solution is:

**y = 11cos(x) − 3sin(x)**

3. Find the particular solution to \frac{d^{2}y}{dx^{2}} + 3\frac{dy}{dx} − 10y = 16e^{3x}

Guess.

Try y = ce^{3x}

\frac{dy}{dx} = 3ce^{3x}

\frac{d^{2}y}{dx^{2}} = 9ce^{3x}

Substitute these values into \frac{d^{2}y}{dx^{2}} + 3\frac{dy}{dx} − 10y = 16e^{3x}

9ce^{3x} + 9ce^{3x} − 10ce^{3x} = 16e^{3x}

8ce^{3x} = 16e^{3x}

c = 2

So the particular solution is:**y = 2e ^{3x}**

Finally, we combine our three answers to get the complete solution:

**y = Ae ^{2x} + Be^{−5x} + 11cos(x) − 3sin(x) + 2e^{3x}**

### **Example 4:** Solve \frac{d^{2}y}{dx^{2}} + 3\frac{dy}{dx} − 10y = −130cos(x) + 16e^{2x}

This is exactly the same as Example 3 except for the final term, which has been replaced by 16e^{2x}.

So Steps 1 and 2 are exactly the same. On to step 3:

3. Find the particular solution to \frac{d^{2}y}{dx^{2}} + 3\frac{dy}{dx} − 10y = 16e^{2x}

Guess.

Try y = ce^{2x}

\frac{dy}{dx} = 2ce^{2x}

\frac{d^{2}y}{dx^{2}} = 4ce^{2x}

Substitute these values into \frac{d^{2}y}{dx^{2}} + 3\frac{dy}{dx} − 10y = 16e^{2x}

4ce^{2x} + 6ce^{2x} − 10ce^{2x} = 16e^{2x}

0 = 16e^{2x}

Oh dear! Something seems to have gone wrong. How can 16e^{2x} = 0?

Well, it can’t, and there is nothing wrong here except that there is no particular solution to the differential equation \frac{d^{2}y}{dx^{2}} + 3\frac{dy}{dx} − 10y = 16e^{2x}

The general solution to the homogeneous equation \frac{d^{2}y}{dx^{2}} + 3\frac{dy}{dx} − 10y = 0

**,**which is y = Ae

^{2x}+ Be

^{−5x}, already has a term Ae

^{2x}, so our guess y = ce

^{2x}already satisfies the differential equation \frac{d^{2}y}{dx^{2}} + 3\frac{dy}{dx} − 10y = 0 (it was just a different constant.)

So we must guess y = cxe^{2x}

Let's see what happens:

\frac{dy}{dx} = ce^{2x} + 2cxe^{2x}

\frac{d^{2}y}{dx^{2}} = 2ce^{2x }+ 4cxe^{2x} + 2ce^{2x} = 4ce^{2x} + 4cxe^{2x}

Substitute these values into \frac{d^{2}y}{dx^{2}} + 3\frac{dy}{dx} − 10y = 16e^{2x}

4ce^{2x} + 4cxe^{2x }+ 3ce^{2x} + 6cxe^{2x }− 10cxe^{2x} = 16e^{2x}

7ce^{2x} = 16e^{2x}

c = *16*7

So in the present case our particular solution is

y = \frac{16}{7}xe^{2x}

y = Ae^{2x} + Be^{−5x} + 11cos(x) − 3sin(x) + \frac{16}{7}xe^{2x}

### **Example 5:** Solve \frac{d^{2}y}{dx^{2}} − 6\frac{dy}{dx} + 9y = 5e^{−2x}

1. Find the general solution to \frac{d^{2}y}{dx^{2}} − 6\frac{dy}{dx} + 9y = 0

The characteristic equation is: r^{2} − 6r + 9 = 0

(r − 3)^{2} = 0

r = 3, which is a repeated root.

Then the general solution of the differential equation is **y = Ae ^{3x} + Bxe^{3x}**

2. Find the particular solution to \frac{d^{2}y}{dx^{2}} − 6\frac{dy}{dx} + 9y = 5e^{−2x}

Guess.

Try y = ce^{−2x}

\frac{dy}{dx} = −2ce^{−2x}

\frac{d^{2}y}{dx^{2}} = 4ce^{−2x}

Substitute these values into \frac{d^{2}y}{dx^{2}} − 6\frac{dy}{dx} + 9y = 5e^{−2x}

4ce^{−2x} + 12ce^{−2x} + 9ce^{−2x} = 5e^{−2x}

25e^{−2x} = 5e^{−2x}

c = \frac{1}{5}

So the particular solution is:

y= \frac{1}{5}e^{−2x }

Finally, we combine our two answers to get the complete solution:

y= Ae^{3x} + Bxe^{3x }+ \frac{1}{5}e^{−2x }

### **Example 6: **Solve \frac{d^{2}y}{dx^{2}} + 6\frac{dy}{dx} + 34y = 109cos(5x)^{}

1. Find the general solution to \frac{d^{2}y}{dx^{2}} + 6\frac{dy}{dx} + 34y = 0^{}

The characteristic equation is: r^{2} + 6r + 34 = 0

Use the __quadratic equation formula__

r = \frac{−b ± √(b^{2 }− 4ac)}{2a}

with a = 1, b = 6 and c = 34

So

r = \frac{−6 ± √[6^{2 }− 4(1)(34)]}{2(1)}

r = \frac{−6 ± √(36−136)}{2}

r = \frac{−6 ± √(−100)}{2}

r = −3 ± 5i

And we get:

y =e^{−3x}(Acos(5x) + iBsin(5x))

Since f(x) is a sine function, we assume that y is a linear combination of sine and cosine functions:

Guess.

Try y = acos(5x) + bsin(5x)

Note: since we do not have sin(5x) or cos(5x) in the solution to the homogeneous equation (we have e^{−3x}cos(5x) and e^{−3x}sin(5x), which are different functions), our guess should work.

Let’s continue and see what happens:

\frac{dy}{dx} = −5asin(5x) + 5bcos(5x)

\frac{d^{2}y}{dx^{2}} = −25acos(5x) − 25bsin(5x)

Substitute these values into \frac{d^{2}y}{dx^{2}} + 6\frac{dy}{dx} + 34y = 109sin(5x)

−25acos(5x) − 25bsin(5x) + 6[−5asin(5x) + 5bcos(5x)] + 34[acos(5x) + bsin(5x)] = 109sin(5x)

cos(5x)[−25a + 30b + 34a] + sin(5x)[−25b − 30a + 34b] = 109sin(5x)

cos(5x)[9a + 30b] + sin(5x)[9b - 30a] = 109sin(5x)

Equate coefficients of cos(5x) and sin(5x):

Coefficients of cos(5x): | 9a + 30b = 109 ... (1) |

Coefficients of sin(5x): | 9b − 30a = 0 ... (2) |

From equation (2), a = \frac{3b}{10}

Substitute into equation (1)

9(\frac{3b}{10}) + 30b = 109

327b = 1090

b = \frac{10}{3}

a = 1

So the particular solution is:y = cos(5x) + \frac{10}{3}sin(5x)

Finally, we combine our answers to get the complete solution:

y = e^{−3x}(Acos(5x) + iBsin(5x)) + cos(5x) + \frac{10}{3}sin(5x)