# Self-Adjoint Differential Equations III: Real Eigenvalues, Gram-Schmidt Orthogonalization

In here, I mentioned that the eigenvalues of a Hermitian operator are real and that the eigenfunctions of a Hermitian operator are orthogonal.

Let $\mathcal{L}$ be a Hermitian operator and let $u_i$, $u_j$ be eigenfunctions of $\mathcal{L}$ with eigenvalues $\lambda_i$, $\lambda_j$, respectively. Then
\begin{align*}
\mathcal{L}u_i+\lambda_iwu_i=0\ \ \ \ \ (1)\\
\mathcal{L}u_j+\lambda_jwu_j=0\ \ \ \ \ (2)
\end{align*}
The complex conjugation of (2) is
$$\mathcal{L}u_j^\ast+\lambda_j^\ast wu_j^\ast=0\ \ \ \ \ (3)$$
Multiply (1) by $u_j^\ast$ and (3) by $u_i$:
\begin{align*}
u_j^\ast\mathcal{L}u_i+u_j^\ast\lambda_iwu_i=0\ \ \ \ \ (4)\\
u_i\mathcal{L}u_j^\ast+u_i\lambda_j^\ast wu_j^\ast=0\ \ \ \ \ (5)
\end{align*}
Subtracting (5) from (4), we obtain
$$u_j^\ast\mathcal{L}u_i-u_i\mathcal{L}u_j^\ast=(\lambda_j^\ast-\lambda_i)wu_iu_j^\ast\ \ \ \ \ (6)$$
Integrating (6), we get
$$\int_a^bu_j^\ast\mathcal{L}u_i dx-\int_a^b u_i\mathcal{L}u_j^\ast dx=(\lambda_j^\ast-\lambda_i)\int_a^b u_iu_j^\ast wdx\ \ \ \ \ (7)$$
Since $\mathcal{L}$ is Hermitian, the LHS of (7) vanishes. Thus
$$(\lambda_j^\ast-\lambda_i)\int_a^bu_iu_j^\ast wdx=0$$ If $i=j$ then $\int_a^bu_iu_j^\ast wdx\ne 0$ so $\lambda_i^\ast=\lambda_i$, i.e. $\lambda_i$ is real.

If $i\ne j$ and if $\lambda_i\ne\lambda_j$, then $\int_a^bu_iu_j^\ast wdx=0$, i.e. $u_i$ and $u_j$ are orthogonal, where we consider
$$\langle u_i,u_j\rangle=\int_a^b u_iu_j^\ast wdx\ \ \ \ \ (8)$$ as an inner product. The inner product (8) is called the Hermitian product weight by $w(x)$.

What if $i\ne j$ but $\lambda_i=\lambda_j$? Then $\int_a^bu_iu_j^\ast wdx$ may not vanish, i.e. $u_i$ and $u_j$ may not orthogonal.Such case is labeled degenerate. For example, consider the differential equation
$$\frac{d^2}{dx^2}y(x)+n^2y(x)=0$$
Once can easily see that $y_1(x)=\cos nx$ and $y_2(x)=\sin nx$ both satisfy the differential equation. So $\cos nx$ and $\sin nx$ are eigenfunctions that correspond to the same eigenvalue $n^2$. That is, $\cos nx$ and $\sin nx$ are degenerate eigenfunctions. They are however orthogonal because
$$\int_0^{2\pi}\cos nx\sin nxdx=0$$

It is good to know the following formulas:
$$\int_{x_0}^{x_0+2\pi}\sin mx\sin nxdx=C_n\delta_{nm},$$
where
$$C_n=\left\{\begin{array}{ccc} \pi & \mbox{if} & n\ne 0\\ 0 & \mbox{if} & n=0 \end{array}\right.$$
$$\int_{x_0}^{x_0+2\pi}\cos mx\cos nxdx=D_n\delta_{nm},$$
where
$$D_n=\left\{\begin{array}{ccc} \pi & \mbox{if} & n\ne 0\\ 2\pi & \mbox{if} & n=0 \end{array}\right.$$
$$\int_{x_0}^{x_0+2\pi}\sin mx\cos nxdx=0$$

Orthogonal functions can be used to expand a functions, for example, as a Fourier series expansion. Certain classes of function (sectionally continuous or piecewise continuous) may be represented by a series of orthogonal functions to any desired degree of accuracy. Such property is referred to as completeness.

Example. Square Wave

Consider the square wave
$$f(x)=\left\{\begin{array}{ccc} \frac{h}{2} & \mbox{if} & 0<x<\pi,\\ -\frac{h}{2} & \mbox{if} & -\pi<x<0 \end{array}\right.$$

Note that the function may be expanded in any of a variety of orthogonal eigenfunctions such as Legendere, Hermite, Chebyshev, etc. The choice of eigenfunction is made on the basis of convenience. For example, we may choose to use $\cos nx$, $\sin nx$.  The eigenfunction series can then be written as a Fourier series
$$f(x)=\frac{a_0}{2}+\sum_{n=1}^\infty(a_n\cos nx+b_n\sin nx)\ \ \ \ \ (8)$$
where
\begin{align*}
a_n&=\frac{1}{\pi}\int_{-\pi}^\pi f(x)\cos nt dt,\\
b_n&=\frac{1}{\pi}\int_{-\pi}^\pi f(t)\sin nt dt,\ n=0,1,2,\cdots
\end{align*}
So by the formula (8) we find that
\begin{align*}
a_n&=0,\\
b_n&=\frac{h}{n\pi}(1-\cos n\pi)\\
&=\frac{h}{n\pi}(1-(-1)^n)\\
&=\left\{\begin{array}{ccc}
0 & \mbox{if} & n=\mbox{even}\\
\frac{2h}{n\pi} & \mbox{if} & n=\mbox{odd}
\end{array}\right.
\end{align*}
Hence the Fourier series expansion of $f(x)$ is given by
$$f(x)=\frac{2h}{\pi}\sum_{n=0}^\infty\frac{\sin(2n+1)x}{2n+1}$$

If $N$ liearly independent eigenfunctions correspond to the same eigenvalue, the eigenvalue is said to be $N$-fold degenerate. In the above example, for each $n$ there are two possible solutions $\cos nx$, $\sin nx$. We may say the eigenfunctions are degenerate or the eigenvalue is degenerate.

Gram-Schmidt Orthogonalization

Consider
$$\int_a^b \varphi_i^2wdx=N_i^2$$
Since $\mathcal{L}u(x)+\lambda w(x)u(x)=0$ is linear, $\mu_i\varphi_i$ would be a solution as well for any constant $\mu_i$. If we set $\psi_i=\frac{\varphi_i}{N_i}$ then
$$\int_a^b\psi_i^2wdx=1$$
and
$$\int_a^b\psi_i(x)\psi_j(x)w(x)dx=\delta_{ij}$$

Suppose that $\{u_n(x)\}_{n=0}^\infty$ are eigenfunctions that are not mutually orthogonal. Gram-Schmidt orthogonalization process allows us to come up with orthonormal eigenfunctions $\{\varphi_n\}_{n=0}^\infty$ from $\{u_n(x)\}_{n=0}^\infty$.
Let us start with $n=0$. Let $\psi_0(x)=u_0(x)$. Then the normalized eigenfunction is denoted by $\varphi_0(x)$.
$$\varphi_0(x)=\frac{\psi_0(x)}{\left[\int\psi_0^2(x)wdx\right]^{1/2}}$$
For $n=1$, let
\begin{align*}
\psi_1&=u_1(x)-\langle u_1(x),\varphi_0(x)\rangle\varphi_0(x)\\
&=u_1(x)-\int u_1\varphi_0wdx\varphi_0(x)\end{align*}
and
$$\varphi_1(x)=\frac{\psi_1}{\left[\int\psi_1^2wdx\right]^{1/2}}$$

Figure 1

Figure 1 clearly shows how we can come up with $\psi_1$ using a vector projection. Note that the angle $\theta$ appeared in Figure 1 is for an intuitive purpose only and does not depict a real angle.

Figure 2

For $n=2$, as one can see from Figure 2, $\psi_2$ that is orthogonal to both $\varphi_0$ and $\varphi_1$ can be obtained as
\begin{align*}
\psi_2&:=u_2(x)-\langle u_2(x),\varphi_0(x)\rangle\varphi_0(x)-\langle u_2(x),\varphi_1(x)\rangle\varphi_1(x)\\
&=u_2(x)-\int u_2(x)\varphi_0(x)w(x)dx\varphi_0(x)-\int u_2(x)\varphi_1(x)w(x)dx\varphi_1(x)
\end{align*}
The normalzed eigenfunction $\varphi_2$ is then
$$\varphi_2:=\frac{\psi_2}{\left[\int\psi_2^2wdx\right]^{1/2}}$$
Now we can see a clear pattern and $\psi_n$ which is orthogonal to $\varphi_0,\cdots,\varphi_{n-1}$ would be given by
\begin{align*}
\psi_n&:=u_n(x)-\sum_{j=0}^{n-1}\langle u_j(x),\varphi_j(x)\rangle\varphi_j(x)\\
&=u_n(x)-\sum_{j=0}^{n-1}\left[\int u_j(x)\varphi_j(x)w(x)dx\right]\varphi_j(x)
\end{align*}
with its normalization
$$\varphi_n:=\frac{\varphi_n}{\left[\int\psi_n^2wdx\right]^{1/2}}$$

Example. Find orthonormal set from
$$u_n(x)=x^n,\ n=0,1,2,\cdots$$
with $-1\leq x\leq 1$ and $w(x)=1$.

Solution. By Gram-Schmidt orthonormalization, we obtain
\begin{align*}
\varphi_0(x)&=\frac{1}{\sqrt{x}},\\
\varphi_1(x)&=\sqrt{\frac{3}{2}}x,\\
\varphi_2(x)&=\sqrt{\frac{5}{2}}\cdot\frac{1}{2}(3x^2-1),\\ \varphi_3(x)&=\sqrt{\frac{7}{2}}\cdot\frac{1}{2}(5x^3-3x),\\
\vdots\\
\varphi_n(x)&=\sqrt{\frac{2n+1}{2}}P_n(x),
\end{align*}
where $P_n(x)$ is the $n$th-order Legendre polynomial.

References:

G. Arfken, Mathematical Methods for Physicists, 3rd Edition, Academic Press 1985

# Self-Adjoint Differential Equations II: Hermitian Operators

Let $\mathcal{L}$ be a second-order self-adjoint differential operator. Then $\mathcal{L}u(x)$ may be written as
$$\mathcal{L}u(x)=\frac{d}{dx}\left[p(x)\frac{du(x)}{dx}\right]+q(x)u(x)\ \ \ \ \ (1)$$ as we discussed here. Multiply (1) by $v^\ast$ ($v^\ast$ is the complex conjugate of $v$) and integrate
\begin{align*}
\int_a^bv^\ast\mathcal{L}udx&=\int_a^bv^\ast\frac{d}{dx}\left[p(x)\frac{du(x)}{dx}\right]dx+\int_a^bv^\ast qudx\\
&=\int_a^bv^\ast d\left[p(x)\frac{du(x)}{dx}\right]+\int_a^bv^\ast qudx\\
&=v^\ast p\frac{du}{dx}|_a^b-\int_a^b {v^\ast}^\prime pu’dx+\int_a^bv^\ast qudx
\end{align*}
We may impose
$$v^\ast p\frac{du}{dx}|_a^b=0\ \ \ \ \ (2)$$
as a boundary condition.
\begin{align*}
-\int_a^b {v^\ast}^\prime pu’dx&=-\int_a^b {v^\ast}^\prime pdu\\
&=-{v^\ast}^\prime pu|_a^b+\int_a^b u(p{v^\ast}^\prime)’dx
\end{align*}
We may also impose
$$-{v^\ast}^\prime pu|_a^b=0\ \ \ \ \ (3)$$
as a boundary condition. Then
\begin{align*}
\int_a^bv^\ast\mathcal{L}udx&=\int_a^b u(p{v^\ast}^\prime)’dx+\int_a^bv^\ast qudx\\
&=\int_a^b u\mathcal{L}v^\ast dx
\end{align*}

Definition. A self-adjoint operator $\mathcal{L}$ is called a Hermitian operator with respect to the functions $u(x)$ and $v(x)$ if

$$\int_a^bv^\ast\mathcal{L}udx=\int_a^b u\mathcal{L}v^\ast dx\ \ \ \ \ (4)$$

That is, a self-adjoint operator $\mathcal{L}$ which satisfies the boundary conditions (2) and (3) is a Hermitian operator.

Hermitian Operators in Quantum Mechanics

In quantum mechanics, the differential operators need to be neither second-order nor real. For example, the momentum operator is given by $\hat p=-i\hbar\frac{d}{dx}$. Therefore we need an extended notion of Hermitian operators in quantum mechanics.

Definition. The operator $\mathcal{L}$ is Hermitian if
$$\int \psi_1^\ast\mathcal{L}\psi_2 d\tau=\int(\mathcal{L}\psi_1)^\ast\psi_2 d\tau\ \ \ \ \ (5)$$
Note that (5) coincides with (4) if $\mathcal{L}$ is real. In terms of Dirac’s braket notation (5) can be written as
$$\langle\psi_1|\mathcal{L}\psi_2\rangle=\langle\mathcal{L}\psi_1|\psi_2\rangle$$

The adjoint operator $A^\dagger$ of an operator $A$ is defined by
$$\int \psi_1^\ast A^\dagger \psi_2 d\tau=\int(A\psi_1)^\ast\psi_2 d\tau\ \ \ \ \ (6)$$ Again in terms of Dirac’s braket notation (6) can be written as
$$\langle\psi_1|A^\dagger\psi_2\rangle=\langle A\psi_1|\psi_2\rangle$$
If $A=A^\dagger$ then $A$ is said to be self-adjoint. Clearly, self-adjoint operators are Hermitian operators. However the converse need not be true. Although we will not delve into this any deeper here, the difference is that Hermitian operators are always assumed to be bounded while self-adjoint operators are not necessarily restricted to be bounded. That is, bounded self-adjoint operators are Hermitian operators. Physicists don’t usually distinguish self-adjoint operators and Hermitian operators, and often they mean self-adjoint operators by Hermitian operators. In quantum mechanics, observables such as position, momentum, energy, angular momentum are represented by (Hermitian) linear operators and the measurements of observables are given by the eigenvalues of linear operators. Physical observables are regarded to be bounded and continuous, because the measurements are made in a laboratory (so bounded) and points of discontinuity are mathematical points and nothing smaller than the Planck length can be observed. As well-known any bounded linear operator defined on a Hilbert space is continuous.

For those who are interested: This may cause a notational confusion, but in mathematics the complex conjugate $a^\ast$ is replaced by $\bar a$ and the adjoint $a^\dagger$ is replaced by $a^\ast$. Let $\mathcal{H}$ be a Hilbert space. By the Riesz Representation Theorem, it can be shown that for any bounded linear operator $a:\mathcal{H}\longrightarrow\mathcal{H}’$, there exists uniquely a bounded linear operator $a^\ast: \mathcal{H}’\longrightarrow\mathcal{H}$ such that
$$\langle a^\ast\eta|\xi\rangle=\langle\eta|a\xi\rangle$$ for all $\xi\in\mathcal{H}$, $\eta\in\mathcal{H}’$. This $a^\ast$ is defined to be the adjoint of the bounded operator $a$. ${}^\ast$ defines an involution on $\mathcal{B}(\mathcal{H})$, the set of all bounded lineart operators of $\mathcal{H}$ and $\mathcal{B}(\mathcal{H})$ with ${}^\ast$ becomes a C${}^\ast$-algebra. In mathematical formulation of quantum mechanics, observables are represented by self-adjoint operators of the form $a^\ast a$, where $a\in\mathcal{B}(\mathcal{H})$. Note that $a^\ast a$ is positive i.e. its eigenvalues are non-negative.

Definition. The expectation value of an operator $\mathcal{L}$ is
$$\langle\mathcal{L}\rangle=\int \psi^\ast\mathcal{L}\psi d\tau$$
$\langle\mathcal{L}\rangle$ corresponds to the result of a measurement of the physical quantity represented by $\mathcal{L}$ when the physical system is in a state described by $\psi$. The expectation value of an operator should be real and this is guaranteed if the operator is Hermitian. To see this suppose that $\mathcal{L}$ is Hermitian. Then
\begin{align*}
\langle\mathcal{L}\rangle^\ast&=\left[\int \psi^\ast\mathcal{L}\psi d\tau\right]^\ast\\
&=\int\psi\mathcal{L}^\ast\psi^\ast d\tau\\
&=\int(\mathcal{L}\psi)^\ast\psi d\tau\\
&=\int\psi^\ast\mathcal{L}\psi d\tau\ (\mbox{since $\mathcal{L}$ is Hermitian})\\
&=\langle\mathcal{L}\rangle
\end{align*}
That is, $\langle\mathcal{L}\rangle$ is real.

There are three important properties of Hermitian (self-adjoint) operators:

• The eigenvalues of a Hermitian operator are real.
• The eigenfunctions of a Hermitian operator are orthogonal.
• The eigenfunctions of a Hermitian operator form a complete set.

References:

1. G. Arfken, Mathematical Methods for Physicists, 3rd Edition, Academic Press 1985
2. W. Greiner, Quantum Mechanics, An Introduction, 4th Edition, Springer-Verlag 2001
3. P. Szekeres, A Course in Modern Mathematical Physics: Groups, Hilbert Space and Differential Geometry, Cambridge University Press 2004

Let $\mathcal{L}$ be the second-order linear differential operator
$$\mathcal{L}=p_0(x)\frac{d^2}{dx^2}+p_1(x)\frac{d}{dx}+p_2(x)$$
which acts on a function $u(x)$ as
$$\mathcal{L}u(x)=p_0(x)\frac{d^2u(x)}{dx^2}+p_1(x)\frac{du(x)}{dx}+p_2(x)u(x).\ \ \ \ \ (1)$$

Define an adjoint operator $\bar{\mathcal{L}}$ by
\begin{align*}
\bar{\mathcal{L}}&:=\frac{d^2}{dx^2}[p_0u]-\frac{d}{dx}[p_1u]+p_2u\\
&=p_0\frac{d^2u}{dx^2}+(2p_0^\prime-p_1)\frac{du}{dx}+(p_0^{\prime\prime}-p_1+p_2)u.
\end{align*}
If $\mathcal{L}=\bar{\mathcal{L}}$, $\mathcal{L}$ is said to be self-adjoint. One can immediately see that $\mathcal{L}=\bar{\mathcal{L}}$ if and only if $$p_0^\prime=p_1.\ \ \ \ \ (2)$$ Let $p(x)=p_0(x)$ and $q(x)=p_2(x)$. Then
\begin{align*}
\mathcal{L}=\bar{\mathcal{L}}&=p\frac{d^2u}{dx^2}+\frac{dp}{dx}\frac{du}{dx}+qu\\
&=\frac{d}{dx}\left[p(x)\frac{du(x)}{dx}\right]+qu(x).
\end{align*}
Note that one can transform a non-self-adjoint 2nd-order linear differential operator to a self-adjoint one. The idea is similar to that of finding a integrating factor to transform a non-separable first-order linear differential equation to a separable one.

Suppose that (1) is not self-adjoint, i.e. $p_1\ne p_0′$. Multiply $\mathcal{L}$ by $\frac{f(x)}{p_0(x)}$. Then
$$\mathcal{L}’:=\frac{f}{p_0}\mathcal{L}=f\frac{d^2u}{dx^2}+f\frac{p_1}{p_0}\frac{du}{dx}+f\frac{p_2}{p_0}u.$$
Suppose $\mathcal{L}’$ is self-adjoint. Then by (2)
$$f’=f\frac{p_1}{p_0}.$$
That is,
$$f(x)=\exp\left[\int^x\frac{p_(t)}{p_0(t)}dt\right].$$
If $p_1=p_0′$, then
\begin{align*}
\frac{f(x)}{p_0}&=\frac{1}{p_0}\exp\left[\int^x\frac{p_1}{p_0}dt\right]\\
&=\frac{1}{p_0}\exp\left[\int^x\frac{p_0^\prime}{p_0}dt\right]\\
&=\frac{1}{p_0}\exp(\ln p_0(x))\\
&=\frac{1}{p_0(x)}\cdot p_0\\
&=1
\end{align*}
i.e. $f(x)=p_0(x)$ as expected.

Eigenfunctions, Eigenvalues

From separation of variables or directly from a physical problem, we have second-order linear differential equation of the form
$$\mathcal{L}u(x)+\lambda w(x)u(x)=0,\ \ \ \ \ (3)$$
where $\lambda$ is a constant and $w(x)>0$ is a function called a density or weighting function. The constant $\lambda$ is called an eigenvalue and $u(x)$ is called an eigenfunction.

Example. [Shcrödinger Equation]

The Schrödinger equation
$$H\psi=E\psi$$
is of the form (3). Recall that $H$ is the Hamiltonian operator
$$H=-\frac{\hbar^2}{2m}\frac{d^2}{dx^2}+V(x)$$
where $V(x)$ is a potential. So $H$ is a second-order linear differential operator. The weight function $w(x)=-1$ and $E$ is energy as an eigenvalue. Clearly Schrödinger equation is self-adjoint.

Example. [Legendre's Equations]

Legendre’s equation
$$(1-x^2)y^{\prime\prime}-2xy’+n(n+1)y=0$$ is of the form (3), where $\mathcal{L}y=(1-x^2)y^{\prime\prime}-2xy’$, $w(x)=1$, and $\lambda=n(n+1)$. Since $p_0^\prime=-2x=p_1$, Legendre’s equations are self-adjoint.

# Legendre Functions II: Recurrence Relations and Special Properties

In this lecture, we derive some important recurrence relations of Legendre functions and use them to show that Legendre functions are indeed solutions of a differential equation, called Legendre’s differential equation.

Differentiating the generating function
$$g(x,t)=(1-2xt+t^2)^{-1/2}=\sum_{n=0}^\infty P_n(x)t^n,\ |t|<1\ \ \ \ \ \mbox{(1)}$$
with respect to $t$, we get
\begin{align*}
\frac{\partial g(x,t)}{\partial t}&=\frac{x-t}{(1-2xt+t^2)^{3/2}}\ \ \ \ \ \mbox{(2)}\\&=\sum_{n=0}^\infty nP_n(x)t^{n-1}.\ \ \ \ \ \mbox{(3)}\end{align*}
(2) can be written as
$$\frac{x-t}{(1-2xt+t^2)(1-2xt+t^2)^{1/2}}=\frac{(x-t)(1-2xt+t^2)^{-1/2}}{1-2xt+t^2}.$$
By (1) and (3), we obtain
$$(x-t)\sum_{n=0}^\infty P_n(x)t^n=(1-2xt+t^2)\sum_{n=0}^\infty nP_n(x) t^{n-1}$$ or
$$(1-2xt+t^2)\sum_{n=0}^\infty nP_n(x) t^{n-1}+(t-x)\sum_{n=0}^\infty P_n(x)t^n=0$$
which can be written out as
\begin{align*}
\sum_{n=0}^\infty nP_n(x)t^{n-1}-\sum_{n=0}^\infty &2xnP_n(x)t^n+\sum_{n=0}^\infty nP_n(x)t^{n+1}\\&+\sum_{n=0}^\infty P_n(x)t^{n+1}-\sum_{n=0}^\infty xP_n(x)t^n=0.\ \ \ \ \ \mbox{(4)}\end{align*}
In (4) replace $n$ by $n+1$ in the first term, and replace $n$ by $n-1$ in the third and fourth term. Then (4) becomes
\begin{align*}
\sum_{n=0}^\infty (n+1)P_{n+1}(x)t^n-\sum_{n=0}^\infty &2xnP_n(x)t^n+\sum_{n=0}^\infty (n-1)P_{n-1}(x)t^n\\&+\sum_{n=0}^\infty P_{n-1}(x)t^n-\sum_{n=0}^\infty xP_n(x)t^n=0.
\end{align*}
This can be simplified to
$$\sum_{n=0}^\infty[(n+1)P_{n+1}(x)-(2n+1)xP_n(x)+nP_{n-1}(x)]t^n=0$$
which implies that
$$(2n+1)xP_n(x)=(n+1)P_{n+1}(x)+nP_{n-1}(x).\ \ \ \ \ \mbox{(5)}$$
The recurrence relation (5) can be used to calculate Legendre polynomials. For example, we found $P_0(x)=1$ and $P_1(x)=x$ here. For $n=1$, (5) is
$$3xP_1(x)=2P_2(x)+P_0(x)$$
i.e.
$$P_2(x)=\frac{1}{2}(3x^2-1).$$
Continuing this using the recurrence relation (5), we obtain
\begin{align*}
P_3(x)&=\frac{1}{2}(5x^3-3x),\\
P_4(x)&=\frac{1}{8}(35x^4-30x^2+3),\\
P_5(x)&=\frac{1}{8}(63x^5-70x^3+15x),\\
\cdots.
\end{align*}
A great advantage of having the recurrence relation (5) is that one can easily calculate Legendre polynomials using a computer with a simple programming. This can be easily done for instance in Maxima.

Let us load the following simple program to run the recurrence relation (5).

(%i1) Legendre(n,x):=block ([],
if n = 0 then 1
else
if n = 1 then x
else  ((2*n – 1)*x*Legendre(n – 1, x)-(n – 1)*Legendre(n – 2,x))/n);

(%o1) Legendre(n, x) := block([], if n = 0 then 1
else (if n = 1 then x else ((2 n – 1) x Legendre(n – 1, x)
- (n – 1) Legendre(n – 2, x))/n))

Now we are ready to calculate Legendre polynomials. For example, let us calculate $P_3(x)$.

(%i2) Legendre(3,x);

The output is not exactly what we may like because it is not simplified.

In Maxima, simplification can be done by the command ratsimp.

(%i3) ratsimp(Legendre(3,x));

The output is

That looks better. Let us calculate one more, say $P_4(x)$.

Now we differentiate $g(x,t)$ with respect to $x$.
$$\frac{\partial g(x,t)}{\partial x}=\frac{t}{(1-2xt+t^2)^{3/2}}=\sum_{n=0}^\infty P_n’(x)t^n.$$
From this we obtain
$$(1-2xt+t^2)\sum_{n=0}^\infty P_n’(x)t^n-t\sum_{n=0}^\infty P_n(x)t^n=0$$
$$P_{n+1}’(x)+P_{n-1}’(x)=2xP_n’(x)+P_n(x).\ \ \ \ \ \mbox{(6)}$$
Add 2 times $\frac{d}{dx}(5)$ to $2n+1$ times (6). Then we get
$$(2n+1)P_n=P_{n+1}’(x)-P_{n-1}’(x).\ \ \ \ \ \mbox{(7)}$$
$\frac{1}{2}[(6)+(7)]$ results
$$P_{n+1}’(x)=(n+1)P_n(x)+xP_n’(x).\ \ \ \ \ \mbox{(8)}$$
$\frac{1}{2}[(6)-(7)]$ results
$$P_{n-1}’(x)=-nP_n(x)+xP_n’(x).\ \ \ \ \ \mbox{(9)}$$
Replace $n$ by $n-1$ in (7) and add the result to $x$ times (9):
$$(1-x^2)P_n’(x)=nP_{n-1}(x)-nxP_n(x).\ \ \ \ \ \mbox{(10)}$$
Differentiate (10) with respect to $x$ and add the result to $n$ times (9):
$$(1-x^2)P_n^{\prime\prime}(x)-2xP_n’(x)+n(n+1)P_n(x)=0.\ \ \ \ \ \mbox{(11)}$$
The linear second-order differential equation (11) is called Legendre’s differential equation and as seen $P_n(x)$ satisfies (11). This is why $P_n(x)$ is called a Legendre polynomial.

In physics (11) is often expressed in terms of differentiation with respect to $\theta$. Let $x=\cos\theta$. Then by the chain rule,
\begin{align*}
\frac{dP_n(\cos\theta)}{d\theta}&=-\sin\theta\frac{dP_n(x)}{dx},\ \ \ \ \ \mbox{(12)}\\ \frac{d^2P_n(\cos\theta)}{d\theta^2}&=-x\frac{dP_n(x)}{dx}+(1-x^2)\frac{d^2P_n(x)}{dx^2}.\ \ \ \ \ \mbox{(13)}
\end{align*}
Using (12) and (13), Legendre’s differential equation (11) can be written as
$$\frac{1}{\sin\theta}\frac{d}{d\theta}\left[\sin\theta\frac{dP_n(\cos\theta)}{d\theta}\right]+n(n+1)P_n(\cos\theta)=0.$$