# 15.4. Solving differential equations#

A *differential equation* is an equation which contains derivatives of the function to be determined. They can be very simple. For example, you may be given the (constant) velocity of a car, which is the derivative of its position, which we’d write mathematically as:

To determine where the car ends up after one hour, we need to solve this differential equation. We also need a second piece of information: where the car was at some reference time (usually \(t=0\)), the *initial condition*. If \(x(0) = 0\), you don’t need advanced maths skills to figure out that \(x(1\;\text{hour}) = v_0 \cdot (1\;\text{hour})\). Unfortunately, things aren’t usually this easy.

Before we proceed to a few techniques for solving differential equations, we need some terminology. The *order* of a differential equation is the order of the highest derivative found in the equation; equation (15.49) is thus of first order. A differential equation is called *ordinary* if it only contains derivatives with respect to one variable, and *partial* if it contains derivatives to multiple variables. The equation is *linear* if it does not contain any products of (derivatives of) the unknown function. Finally, a differential equation is *homogeneous* if it only contains terms that contain the unknown function, and *inhomogeneous* if it also contains other terms. Equation (15.49) is ordinary and inhomogeneous, as the \(v_0\) term on the right does not contain the unknown function \(x(t)\). In the sections below, we discuss the various cases you’ll encounter in this book; there are many others (many of which can’t be solved explicitly) to which a whole subfield of mathematics is dedicated.

## 15.4.1. First-order linear ordinary differential equations#

Suppose we have a general equation of the form

where \(a(t)\), \(b(t)\) and \(f(t)\) are known functions of \(t\), and \(x(t)\) is our unknown function. Equation (15.50) is a first-order, ordinary, linear, inhomogeneous differential equation. In order to solve it we will use two techniques that are tremendously useful: separation of variables and separation into homogeneous and particular solutions.

Suppose we had \(f(t) = 0\). Then, if we had two solutions \(x_1(t)\) and \(x_2(t)\) of equation (15.50), we could construct a third as \(x_1(t) + x_2(t)\) (or any linear combination of \(x_1(t)\) and \(x_2(t)\)), since the equation is linear. Now since \(f(t)\) is not zero, we can’t do this, but we can do something else. First, we find the most general solution to the equation where \(f(t) = 0\), which we call the *homogeneous solution* \(x_\mathrm{h}(t)\). Second, we find a solution (any at all) of the full equation (15.50), which we call the *particular solution* \(x_\mathrm{p}(t)\). The full solution is then the sum of these two solutions, \(x(t) = x_\mathrm{h}(t) + x_\mathrm{p}(t)\). You may worry that there may be multiple particular solutions: how would we pick the ‘right’ one? Fortunately, we don’t need to worry: the homogeneous solution will contain an unknown variable, which will be set by the initial condition. Changing the particular solution will change the value of the variable, such that the final solution will be the same and satisfy both the differential equation and the initial condition.

To find the solution to the homogeneous equation

we’re going to use a technique called *separation of variables*. There are two variables in this system: the independent parameter \(t\) and the dependent parameter \(x\). The trick is to get everything depending on \(t\) on one side of the equals sign, and everything depending on \(x\) on the other. To do so, we’re going to treat \(\mathrm{d}x/\mathrm{d}t\) as if it were an actual fraction^{[1]}. In that case, it’s not hard to see that we can re-arrange equation (15.51) to

By itself, equation (15.52) means little, but if we integrate both sides, we get something that makes sense:

or

where \(A = \exp(C)\) is an integration constant (the unknown constant that will be set by our initial condition). Of course, in principle it may not be possible to evaluate the integral in equation (15.54), but even then the solution is valid. In practice, you’ll often encounter situations in which \(a(t)\) and \(b(t)\) are simple functions or even constants, and the evaluation of the integral is straightforward.

Now that we have our homogeneous solution, we still need a particular one. Sometimes you’re lucky, and you can easily guess one - for instance one in which \(x_\mathrm{p}(t)\) doesn’t depend on \(t\) at all. In case you’re not lucky, there’s are two other techniques you may try, either using *variation of constants* or finding an *integrating factor*. To demonstrate variation of constants, we’ll pick a specific example, to not get lost in a bunch of abstract functions. Let \(a(t) = a\) be a constant and \(b(t) = b t\) be linear. The homogeneous solution then becomes \(x_\mathrm{h}(t) = A \exp\left[-\frac12 \frac{b}{a} t^2 \right]\). The constant we’re going to vary is our integration constant \(A\), so our guess for the particular solution will be

We substitute (15.55) back into the full differential equation (15.50), which gives:

A big part of the left-hand side thus cancels, and that’s not a coincidence - that’s because it is based on the homogeneous equation. What remains is a differential equation in \(A(t)\) that can be trivially solved by direct integration:

Again, it may not be possible to evaluate the integral in equation (15.56), but in principle the solution could be inserted in equation (15.55) to give us our particular solution, and the whole differential equation will be solved.

Alternatively, we may try to find an *integration factor* for equation (15.50). This means that we try to re-write the left hand side of the equation as a total derivative, after which we can simply integrate to get the solution. To do so, we first divide the whole equation by \(a(t)\), then look for a function \(\mu(t)\) that satisfies the condition that

from which we can read off that we need to solve the homogeneous equation

We can solve (15.58) by separation of constants, which gives us

where we set the integration constant to one, as it drops out of the equation for \(x(t)\) anyway. With this function \(\mu(t)\), we can rewrite equation (15.50) as

which we can integrate to find \(x(t)\):

## 15.4.2. Second-order linear ordinary differential equations with constant coefficients#

Second order ordinary differential equations are essential for the study of mechanics, as its central equation, Newton’s second law of motion (equation (2.4)) is of this type. In the case that the equation is also linear, we have some hopes of solving it analytically. There are several examples of this type of equation in the main text, especially in Section 2.6, where we solve the equation of motion resulting from Newton’s second law for three special cases, and Section 8.1, where we study a number of variants of the harmonic oscillator.

For the case that the equation is homogeneous and has constant coefficients, we can write down the general solution^{[2]}. The equation to be solved is of the form

For the case that \(a=0\), we retrieve a first-order differential equation, whose solution is an exponential (as can be found by separation of variables and integration): \(x(t) = C \exp(c t / b)\). In many cases an exponential is also a solution of equation (15.62). To figure out which exponential, let’s start with the trial function (or ‘Ansatz’) \(x(t) = \exp(\lambda t)\), where \(\lambda\) is an unknown parameter. Substituting this Ansatz into equation (15.62) yields the *characteristic polynomial* for this ode:

which almost always has two solutions:

Note that the solutions can be real or complex. If there are two of them, we can write the general solution^{[3]} of equation (15.62) as a linear combination of the Ansatz with the two cases:

where \(A\) and \(B\) are set by either initial or boundary conditions. Since the \(\lambda_\pm\) may be complex, so may \(A\) and \(B\); it’s their combination that should give a real number (as \(x(t)\) is real), see Exercise 15.7a.

In the case that equation (15.64) gives only one solution, the corresponding exponential function is still a solution of equation (15.62), but it is not the most general one, as we only can put a single undetermined constant in front of it. We therefore need a second, independent solution. To guess one, here’s a third useful trick^{[4]}: take the derivative of our known solution, \(e^{\lambda t}\), with respect to the parameter \(\lambda\). This gives a second Ansatz: \(t e^{\lambda t}\), where \(\lambda = -b/2a\). Substituting this Ansatz into equation (15.62) for the case that \(c = b^2/2a\), we find:

so our Ansatz is again a solution. For this special case, the general solution is therefore given by

In Section 8.2, where we discuss the damped harmonic oscillator, the special case corresponds to the critically damped oscillator. We get an underdamped oscillator when the roots of the characteristic polynomial are complex, and an overdamped one when they are real.

## 15.4.3. Second-order linear ordinary differential equations of Euler type#

There’s a second class of linear ordinary differential equations that we can solve explicitly: those of Euler (or Cauchy-Euler) type, where the coefficient in front of a derivative contains the variable to the power of the derivative, i.e., for a second-order differential equation, we have as the most general form:

Note that we are now solving for \(y(x)\); we do so because this type of equation typically occurs in the context of position- rather than time-dependent functions. An example is the Laplace equation (\(\nabla^2 y = 0\)) in polar coordinates. Like for the second order ode with constant coefficients, the ode of Euler type can be generalized to higher-order equations.

There are (at least) two ways to solve equation (15.67): through an Ansatz, and through a change of variables. For the Ansatz, note that for any polynomial, the derivative of each term reduces the power by one, and here we’re multiplying each such term with the variable to the power the number of derivatives^{[5]}. This suggests we simply try a polynomial, so our Ansatz here will be \(y(x) = x^n\). Substituting in equation (15.67) gives:

so we get another second order polynomial to solve, this time in \(n\):

If the roots in equation (15.68) are both real (the most common case in physics problems), we have two independent solutions, and we are done. If the roots are complex, we also have two independent solutions, though they involve complex powers of \(x\); like for the equation with constant coefficients, we can rewrite these as real functions with Euler’s formula. For the case that we have only one root, we again apply our trick to get a second: we try \(\mathrm{d}x^n / \mathrm{d}n = x^n \ln(x)\), which turns out to be indeed a solution, and the general solution is again a linear combination of the two solutions found (see Exercise 15.7).

Alternatively, we could have solved equation (15.67) by a change of variables. Although this method is occasionally useful (and so it’s good to be aware of its existence), there is no systematic way of deriving which change of variables will do the trick, so you’ll have to go by trial-and-error (without a priori guarantee of success). In this case, this process leads to the following substitution:

where we introduce \(\phi(t)\) for convenience. Taking derivatives of \(y(x)\) with the chain rule gives

where we kept the \(1/x\) and \(1/x^2\) as they’ll cancel the coefficients in equation (15.67). Substituting (15.69) and (15.70) in equation (15.67), we get

which is a second order differential equation with constant coefficients, and thus of the form given in equation (15.62). We therefore know how to find its solutions, and can use equation (15.69) to transform those solutions back to functions \(y(x)\).

## 15.4.4. Reduction of order#

If you find yourself with a non-homogeneous second order differential equation where the homogeneous equation either has constant coefficients or is of Euler type, you can again use the technique of variation of constants to find a particular solution. A similar technique, known as reduction of order, may help you find solutions to a second (or higher) order equation where the coefficients are not constant. In order to be able to use this technique, you need to know a solution to the homogeneous equation, so it is not as universally applicable as the techniques in the previous two sections, but still frequently very helpful.

Let us write the general non-homogeneous second-order linear differential equation as

Note that this is the most general form: if there is a coefficient (constant or otherwise) in front of the second derivative, we simply divide the whole equation by that coefficient and redefine the coefficients to match equation (15.72). Now suppose we have a solution \(y_1(x)\) of the homogeneous equation (so for the case that \(r(x) = 0\)). As the equation is homogeneous, for any constant \(v\) the function \(v y_1(x)\) will also be a solution. As an Ansatz for the second solution, we’ll try a variant of variation of constants, and take

where \(v(x)\) is an arbitrary function. Substituting (15.73) back into (15.72), we find

We recognize the prefactor of \(v(x)\) as exactly the homogeneous equation, which \(y_1(x)\) satisfies, so this term vanishes. Now defining \(w(x) = \mathrm{d}v / \mathrm{d}x\), we are left with a first-order equation for \(w(x)\):

Equation (15.75) is a first-order linear differential equation, and can be solved by the techniques from Section 15.4.1. Integrating the equation \(w(x) = \mathrm{d}v / \mathrm{d}x\) then gives us \(v(x)\), and hence the second solution (15.73) of the (inhomogeneous) second order differential equation.

## 15.4.5. Power series solutions#

If none of the techniques in the sections above apply to your differential equation, there’s one last Ansatz you can try: a power series expansion of your solution. To illustrate, we’ll again pick a concrete example: Legendre’s differential equation, given by

where \(n\) is an integer. As an Ansatz for the solution, we’ll try a power series expansion of \(y(x)\):

Our task is now to find numbers \(a_k\) (many of which may be zero) such that (15.77) is a solution of (15.76). Fortunately, we can simply substitute our trial solution and re-arrange to get

where in the last line, we ‘shifted’ the index of the last term^{[6]}. We do so in order to get at an expression for the coefficient of \(x^i\) for any value of \(k\). As the functions \(x^k\) are linearly independent^{[7]} (i.e., you can’t write \(x^k\) as a linear combination of other functions \(x^m\) where \(m \neq k\)), the coefficient of each of the powers in the sum in equation (15.78)D has to vanish for the sum to be identically zero. This gives us a *recurrence relation* between the coefficients \(a_k\):

Given the values of \(a_0\) and \(a_1\) (the two degrees of freedom that our second-order differential equation allows us), we can repeatedly apply equation (15.79) to get all coefficients. Note that for \(k=n\) the coefficient equals zero. Therefore, if for an even value of \(n\), we set \(a_1 = 0\), and for an odd value of \(n\), we set \(a_0 = 0\), we get a finite number of nonzero coefficients. The resulting solutions are polynomials, characterized by the number \(n\); in this case, they’re known as the *Legendre polynomials*, typically denoted \(P_n(x)\), and normalized (by setting the value of the remaining free coefficient) such that \(P_n(1) = 1\). Table 15.1 lists the first five, which are also plotted in Fig. 15.7a.

\(n\) |
\(P_n(x)\) |
---|---|

\(0\) |
\(1\) |

\(1\) |
\(x\) |

\(2\) |
\(\frac12 (3x-1)\) |

\(3\) |
\(\frac12 (5x^3 - 3x)\) |

\(4\) |
\(\frac18 (35 x^4 - 30 x^2 +3)\) |

\(5\) |
\(\frac18 (63 x^5 - 70 x^3 + 15 x)\) |

The first five (and zeroth, for good measure) Legendre polynomials, the solutions of equation (15.76) for the given value of \(n\) and the appropriate choice of \(a_0\) and \(a_1\).

Legendre polynomials have many other interesting properties (many of which can be found in either math textbooks or on their Wikipedia page). They occur frequently in physics, for example in solving problems involving Newtonian gravity or Laplace’s equation from electrostatics.

If we replace the \(n(n+1)\) factor in the Legendre differential equation with an arbitrary number \(\lambda\), the series solution remains a solution, but it no longer terminates^{[8]}. There are many other differential equations that lead to both infinite series and polynomial solutions. A well-known example is the Bessel differential equation:

The solutions to this equation are known as the Bessel functions of the first and second kind (see Exercise 15.9, where you’ll prove that for these functions the series never terminates). These functions generalize the sine and cosine function and occur in the vibrations of two-dimensional surfaces. Other examples include the Hermite and Laguerre polynomials, which feature in quantum mechanics, and Airy functions, which you can encounter when studying optics.

## 15.4.6. Problems#

(Solutions of a second-order ordinary differential equation)

Suppose we have a solution of equation (15.62) where the roots \(\lambda_\pm\) of the characteristic polynomial (equation (15.64)) are complex, so \(\lambda_\pm = \alpha \pm i \beta\). Rewrite the general solution (15.65) in real functions with real coefficients \(C\) and \(D\), and express \(C\) and \(D\) in terms of \(A\) and \(B\).

*Hint*: use Euler’s formula \(e^{ix} = \cos(x) + i \sin(x)\).Suppose we have a solution of equation (15.68) where the roots \(n_\pm\) are complex, so \(n_\pm = \alpha \pm i \beta\). To get a solution of equation (15.67) without complex numbers, we make the substitution \(x = e^t\), so

Use Euler’s formula again to rewrite the complex exponential in terms of sines and cosines, and make the back-substitution to \(x\) to show that the general solution of equation (15.67) in this case is given by

Suppose we have a solution of equation (15.68) for which there is only a single root \(n\). Show that the derivative of \(x^n\) with respect to \(n\) is in this case also a solution of equation (15.67), and that the general solution is given by

(Reduction of order)

Use the method of reduction of order to obtain a second solution of equation (15.62) for the case that the characteristic polynomial (equation (15.64)) has only a single root.

(Bessel functions)

Use the power series technique to find a solution to Bessel’s differential equation (15.80). Why doesn’t the series terminate in this case? Why do you only get one family of solutions? We’ll call these solutions ‘Bessel functions of the first kind’ and label them as \(J_n(x)\) (see Fig. 15.7b).

Use the method of reduction of order to find a second family of solutions to the Bessel differential equation, known as ‘Bessel functions of the second kind’ (\(Y_n(x)\), see Fig. 15.7c).