Takeaways
- Variation of parameters and undetermined coefficients are for inhomogeneous linear second order ODEs of the form: \[ y’’ + p(x) y’ + q(x)y = r(x) \]
- When solving for the overall solution, you will still need to use the homogeneous equation solution methods (reduction of order, characteristic equation) to find the homogeneous part of the solution
- Variation of parameters applies to any inhomogeneous linear second order ODE. The only requirement is that you know the basis functions (which are either given, or you solve for using one of our known methods). The solution is given by: \[ y_p = - y_1 \int \frac{y_2 r}{W}dx + y_2 \int \frac{y_1r}{W}dx \] where \(W = y_1y_2' - y_2 y_1'\) is known as the Wronskian of the equation.
- Undetermined coefficients only applies to constant coefficient ODEs. You use the right hand side function \(r(x)\) to pick the form of the assumed solution, then plug the assumed solution into the ODE to find the coefficients in teh assumed solution.
- If one of the terms in the assumed solution matches one of the homogeneous solution basis functions, you need to apply modification rule to this term by multiplying the term by \(x\) before plugging into the equation. (You will need to do this up to two times—once for each homogeneous basis function.)
Differences from Previous Section
The previous section of notes focused on solution methods for homogeneous linear second order ODEs i.e. \(r(x)=0\). In this section, we focus on inhomogeneous ODEs. Be sure to keep this distinction in mind: the methods presented in this section of notes—variation of parameters and undetermined coefficients—are only for inhomogeneous ODEs. It is a common mistake to confuse which methods apply to homogeneous vs. inhomogeneous problems, so I am emphasizing this point before we proceed any further. The sticking point often arises because inhomogeneous ODEs have both homogeneous and particular solutions. In this case, you will use the solution methods from the last section to solve for the homogeneous solution, then use the methods presented here to solve for the particular solution.
Throughout this section we’ll be considering ODEs of the form:
\[y'' + p(x) y' + q(x)y = r(x)\]This ODE is in standard form, which is important because very often the original ODE will not be in standard form (especially if the homogeneous problem is an Euler-Cauchy equation), so it is up to you to first put it into standard form, then follow the solution methods in this section. Also note that the ODE being in standard form or not does not actually matter for solving the homogeneous problem, only for solving the inhomogeneous problem.
With all that said, let’s dive in.
Variation of Parameters
Variation of parameters is the only valid method for non-constant coefficient inhomogeneous linear second order ODEs we learn in this class. This is a common hiccup for many students, so I want to emphasize it early on before I even explain the method.
The main motivation for variation of parameters is this: if we know the homogeneous solution basis and the right hand side function (when the ODE is in standard form—an important point as you’ll see), then we can find the particular solution to the inhomogeneous problem as some combination of the homogeneous basis and the right hand side.
The first step is to recognize that the particular solution cannot have any terms in common with the homogeneous basis. On a high level, this is because any term that they have in common would get absorbed into the homogeneous solution. This means that our particular solution needs to be a linear combination of the homogeneous basis solutions with each multiplied by some function of \(x\). That is, we have \(y_p\) of the form:
\[y_p = u_1(x)y_1(x) + u_2(x)y_2(x)\]We assume in variation of parameters that we’ve already solved the homogeneous problem, so we already know \(y_1\) and \(y_2\). Therefore, the goal of the problem is to solve for \(u_1\) and \(u_2\) .
We first take the derivative of this assumed form of the solution:
\[y_p' = u_1'y_1 + u_1y_1' + u_2'y_2 + u_2y_2'\]Next, we need to add an additional constraint. We choose to relate the functions \(u_1\) and \(u_2\) by requiring:
\[u_1' y_1 + u_2'y_2 = 0\]While this assumption does have some theoretical backing, we will not go further with it here. From here, we have:
\[y_p' = u_1y_1' + u_2y_2'\]which we differentiate again to find:
\[y_p'' = u_1y_1'' + u_1'y_1' + u_2y_2'' + u_2'y_2'\]We then plug this into the ODE (and using that \(y_1\) and \(y_2\) are homogeneous solutions):
\[\begin{gather} (u_1y_1'' + u_1'y_1' + u_2y_2'' + u_2'y_2') + p(x) (u_1y_1' + u_2y_2') + q(x)(u_1(x)y_1(x) + u_2(x)y_2(x)) = r(x) \\ u_1(y_1'' + p(x) y_1' + q(x)y_1) + u_2(y_2'' + p(x) y_2' + q(x)y_2) + u_1'y_1' + u_2'y_2' = r(x) \\ u_1'y_1' + u_2'y_2' = r(x) \end{gather}\]So, we now have the linear system of ODEs:
\[\begin{align} u_1' y_1 + u_2'y_2 &= 0 \\ u_1'y_1' + u_2'y_2' &= r(x) \end{align}\]which we can solve for \(u_1'\) and \(u_2'\). When we solve the linear system, we find:
\[\begin{align} u_1' &= -\frac{y_1 r(x)}{y_1y_2' - y_2y_1'} \\ u_2' &= \frac{y_2 r(x)}{y_1y_2' - y_2y_1'} \end{align}\]We call the denominator in these equations the Wronskian of the ODE. The Wronskian has special theoretical importance for ODEs, but this is not taken any further in CME 102. Here, we simply denote it as \(W = y_1y_2' - y_2y_1'\). (For a short glimpse into the theoretical importance of the Wronskian, note that if \(W = 0\), we will not have a valid solution to the ODE.) After this slight change in notation, we can write the solution to the linear system as:
\[\begin{align} u_1' &= -\frac{y_1 r(x)}{W} \\ u_2' &= \frac{y_2 r(x)}{W} \end{align}\]which after we integrate becomes:
\[\begin{align} u_1 &= -\int \frac{y_2 r(x)}{W} dx \\ u_2 &= \int \frac{y_1 r(x)}{W} dx \end{align}\]Using these, we can write the final particular solution as:
\[\begin{gather} y_p = -y_1(x) \int \frac{y_2(x) r(x)}{W} dx + y_2(x)\int \frac{y_1(x) r(x)}{W} dx \end{gather}\]A few remarks on what we have done so far:
- This formula is a “plug and chug” formula. This means that if you correctly solve for the homogeneous basis, you can simply calculate the Wronskian, put the ODE in standard form to find \(r(x)\), and compute the integrals to find the solution
- Just to re-emphasize, the ODE must be in standard form or this method will not work. If you follow the derivation closely, you’ll notice that this would not give the correct solution to the linear equations if the ODE was not in standard form
- On an exam, you should never rederive this formula; this is something to use (when appropriate)
To close this part, let’s work through a quick problem. Consider the ODE:
\[y'' + 2y' + y = \cos(x)\]This ODE has homogeneous solution:
\[y_h = e^{-x}(C_1 + C_2x)\]so we have
\[y_1 = e^{-x} \quad y_2 = xe^{-x}\](Remember that the homogeneous basis is just the functions themselves and does not include the constants.) The ODE is already in standard form, so we can plug in to find the solution:
\[\begin{align} y_p &= -y_1(x) \int \frac{y_2(x) r(x)}{W} dx + y_2(x)\int \frac{y_1(x) r(x)}{W} dx \\ W &= y_1y_2' - y_2y_1' \\ &= e^{-x}(e^{-x} - xe^{-x}) + xe^{-2x} \\ &= e^{-2x} \\ y_p &= -e^{-x} \int \frac{xe^{-x} \cos(x)}{e^{-2x}} dx + xe^{-x}\int \frac{e^{-x} \cos(x)}{e^{-2x} } dx \\ &= -e^{-x} \int xe^{x} \cos(x) dx + xe^{-x}\int e^{x} \cos(x) dx \\ &= -e^{-x} \left(\frac{1}{2} e^x ((x - 1) sin(x) + x cos(x))\right) + xe^{-x}\left( \frac{1}{2} e^x (sin(x) + cos(x))\right) \\ &= \frac{1}{2} \sin (x) \quad\blacksquare \end{align}\]So, by simply plugging into the formula, we can arrive at the solution. While variation of parameters is a very attractive method for this reason, as we’ll see below, it may not always be the most efficient or straightforward.
Undetermined Coefficients: Guessing the Solution
Variation of parameters is nice because it’s a “plug and chug” method: identify the right inputs to the equation, hack through the integrals, and you’ll arrive at the right solution. However, when we have a constant coefficient second order linear inomogeneous ODE, we can use a considerably simple method, the method of undetermined coefficients.
The method of constant coefficients essentially reduces our differential equation into a system of algebraic equations. The general workflow for method of undetermined coefficients is:
- Check that the ODE is linear and constant coefficient (in this class we only ask you to solve the second order case, but this method is readily applied to higher order ODEs as well)
- Using the right hand side function \(r(x)\), guess the proper form for the solution
- Take derivatives of the assumed solution and plug into the ODE
- Solve for the coefficients in the assumed solution by matching coefficients in the ODE
While there is a bit more book-keeping involved with undetermined coefficients, something important to keep in mind is that the method of undetermined coefficients only involves solving algebraic equations and not integration. In general, integraton is much harder than algebra, so even if you can solve a problem using variation of parameters, it is almost always better to use undetermined coefficients since there is a lower probability you will make a mistake in solving algebraic equations than computing integrals.
Let’s walk through these steps and discuss their justification by working through an example problem. Consider the ODE:
\[y'' + 2y' + y = \cos(x)\]It is easy to see that the ODE is linear, second order and inhomogeneous. From above, the homogeneous solution is:
\[y_h = e^{-x}(C_1 + C_2x)\]Next, we need to pick our assumed solution. While the full table is given in Prof. Le’s course reader (or is available online elsewhere), the most important rule in all of these tables (and the last row in Prof. Le’s) is for \(r(x)\) of the form:
\[r(x) = x^n e^{\gamma x} \cos(\omega x) \quad \text{or} \quad x^n e^{\gamma x} \sin (\omega x)\]we assume a solution of the form:
\[\begin{align} y_p &= (A_n x^n + A_{n-1}x^{n-1} + \cdots + A_1x + A_0) e^{\gamma x} \cos (\omega x) + \\ &\qquad (B_n x^n + B_{n-1}x^{n-1} + \cdots + B_1x + B_0) e^{\gamma x} \sin (\omega x) \end{align}\]This rule encompasses all of the others in the table (the others are just a bit more readable). In this example problem, we see that we do not have any \(x\) terms on the right hand side, so \(n = 0\). There are also no exponentials, so \(\gamma = 0\). The right hand side in the above example is a cosine with \(\omega = 1\), so we assume a solution of the form:
\[y_p = A \cos(x) + B \sin(x)\]From here, we need to take derivatives of the assumed solution:
\[\begin{align} y_p &= A \cos(x) + B \sin(x) \\ y_p' &= -A\sin(x) + B \cos(x) \\ y_p'' &= - A \cos(x) - B \sin (x) \end{align}\]and plug into the ODE:
\[\begin{gather} y'' + 2y' + y = \cos(x) \\ - A \cos(x) - B \sin (x) + 2 (-A\sin(x) + B \cos(x)) + A \cos(x) + B \sin(x) = \cos(x) \\ 2 B \cos(x) - 2A \sin(x) = \cos(x) \end{gather}\]From here, we match coefficients to solve for \(A\) and \(B\). The argument for matching coefficients is that if we want both sides of the equation to be equal for all values of \(x\), we need the coefficients for similar terms to match. Here, we have \(\sin(x)\) and \(\cos(x)\) on both sides, so we need their coefficients to match i.e. we need:
\[\begin{gather} 2B = 1 \\ -2A = 0 \end{gather}\]We quickly see that this has solution \(B = 1/2\) and \(A = 0\). So, now that we have solved for the coefficients, we can write down the final particular solution:
\[y_p = \frac{1}{2} \sin(x)\]and the overall solution for the ODE:
\[y(x) = y_h + y_p = e^{-x}(C_1 + C_2x) + \frac{1}{2} \sin(x) \quad\blacksquare\]Choosing the form of the solution is the most important part of the method of undetermined coefficients. When choosing the method, there are two facts to be aware of:
- If you choose too many terms, the coefficients for the superfluous terms will be zero when you solve for the coefficients
- If you choose too few terms, the method will fail
- It is better to choose too many instead of too few terms, but too many terms makes this method inefficient (meaning you should probably use variation of parameters instead), so don’t go overboard
The Sticking Point: Modification Rule
While undetermined coefficients is a fairly straightforward solution method, there is a bit of a twist known as the modification rule. Before we proceed any further though, make sure you understand 1) what a homogeneous basis is, and 2) the basic outline of how to solve problems via undetermiend coefficients. Understanding these is absolutely critical to modification rule.
We hinted earlier in the derivation for variation of parameters that if the particular solution has a term in common with one of the homogeneous basis functions, then that term will just get absorbed into the homogeneous basis. This is the main motivation for the modification rule. The modification rule for undetermined coefficients states that if our assumed solution has any terms in common with the homogeneous solution basis, we need to multiply those terms by \(x\). For example, if our equation had \(r(x) = e^x\) but our homogeneous solution basis was \(y_1 = e^{x}\) and \(y_2 = e^{-x}\), then our assumed solution should be \(y_p = Axe^x\) since \(e^x\), our original assumed solution, is one of the homogeneous basis functions.
Let’s work through a short problem to demonstrate how this would work in practice. Suppose you are given the ODE:
\[y'' + y = \cos(x)\]The homogeneous solution to this is:
\[y_h = A \cos(x) + B \sin(x)\]For the particular solution we have \(r(x) = \cos(x)\), so we would pick \(y_p = A \sin(x) + B \cos(x)\). However, both of these terms appear in the homogeneous basis, so we need to multiply them by \(x\). This gives us an assumed solution:
\[y_p = A x\sin(x) + B x\cos(x)\]We then take derivatives and plug this solution into the ODE to solve for the coefficients:
\[\begin{gather} y_p = A x\sin(x) + B x\cos(x) \\ y_p'' = -A x \sin(x) + 2 A \cos(x) - 2 B \sin(x) - B x \cos(x) \\ y'' + y = \cos(x) \\ -A x \sin(x) + 2 A \cos(x) - 2 B \sin(x) - B x \cos(x) + A x\sin(x) + B x\cos(x) = \cos(x) \\ 2 A \cos(x) - 2 B \sin(x) = \cos(x) \\ -2B = 0 \implies B = 0\\ 2A = 1 \implies A = \frac{1}{2} \\ y_p = \frac{1}{2} x \sin(x) \quad\blacksquare \end{gather}\]So to sum up, the solution algorithm for undetermined coefficients (including the modification rule) would be:
- Solve for the homogeneous basis
- Put the ODE in standard form and pick a solution based on \(r(x)\)
- If the assumed solution has any terms in common with the homogeneous basis, multiply these terms by \(x\)
- If there are still any terms in common with the homogeneous basis, multiply the term by \(x\) again.
- Take derivatives of the assumed solution and plug into the ODE
- Match coefficients to form a linear system for the coefficients in the assumed solution
- Solve the linear system for the coefficients to obtain the final solution
So much time is devoted to method of undetermined coefficients in these notes because this is the single most useful solution method you learn in this class, and the method you will probably see the most in classes after CME 102.
Some Final Points
Second order linear inhomogeneous ODEs are probably the most important class of ODEs you’ll learn about this quarter. Some final notes on these types of problems:
- When solving these, it is tempting to just try to always plug everything into the variation of parameters formula, but this formula can sometimes be very tricky to work through. Essentially, just because you can doesn’t mean you should.
- Variation of parameters only applies to second order ODEs, whereas undetermined coefficients can apply to any linear constant coefficient ODE. (In CME 102, something having to do with this fact would make a great multiple choice question on an exam.)
- If \(r(x)\) is separated into two or more functions \(r(x) = r_1(x) + \cdots + r_n(x)\), then for variation of parameters we would plug the entire expression into the formula, and for undetermined coefficients we pick a separate assumed solution for each term in the right hand side.
- When choosing which method to use for a constant coefficient ODE, my rule of thumb is that if you have to solve for more than 3 coefficients in undetermined coefficients, you should use variation of parameters instead. Solving systems of 4 or more equations gets very tricky and time consuming, so at that point I believe it is best to just use the plug and chug approach.