Skip to main content

Section 15.3 Legendre Series: Worked Example

You are encouraged to explore the Legendre basis functions using the applet in Figure 15.2 before working through the example here.

The unrenormalized Legendre polynomials can be defined as

\begin{align} P_0(x) \amp= 1,\tag{15.3.1}\\ P_1(x) \amp= x,\tag{15.3.2}\\ (n+1)P_{n+1}(x) \amp= (2n+1)x P_n(x) - nP_{n-1}(x)\tag{15.3.3} \end{align}

and satisfy the orthogonality condition

\begin{equation} \int_{-1}^1 P_m(x)P_n(x) = \frac{2}{2n+1} \delta_{mn} .\tag{15.3.4} \end{equation}

We can expand any function \(f(x)\) on the interval \(-1\le x\le1\) in terms of these Legendre polynomials as

\begin{equation} f(x) = \sum_0^\infty a_m P_m(x)\tag{15.3.5} \end{equation}

and use (15.3.4) to determine the coefficients as

\begin{equation} a_n = \frac{2n+1}{2} \int_{-1}^1 f(x) P_n(x) .\tag{15.3.6} \end{equation}

You can use the Sage code below to display the Legendre polynomial \(P_n(x)\) for any integer value of \(n\text{,}\) and then its graph.

Now we will use the integral expressions (15.3.6) for the coefficients in a Legendre expansion to work out an example, the Legendre series for the function \(f(x)=\frac32(x^2+x^3)\text{.}\) Then you will plot the individual terms in the Legendre series and their partial sums using an applet.

You can use the Sage code below to calculate the value of the integral for the first coefficient, \(a_0\text{.}\)

Using the applet in Figure 15.5, set the \(a_0\) slider to correspond to the value you just calcuated.  1  Compare your approximate Legendre series, containing just one term (shown in green), to the actual function (shown in blue).

Figure 15.5. Varying the individual Legendre coefficients, using unnormalized Legendre polynomials.

Now you can alter the Sage code above to compute the other coefficients. After each calculation, move the corresponding slider to the value you obtain, and compare the approximation to the given function.

If you move the sliders one by one, resetting the others to zero, you will see how much each individual term contributes to the Legendre series.

If you don't reset the other sliders, but instead combine the contributions from each slider, the applet plots the sum of the corresponding terms (in green), representing an approximation to the actual function (in blue). In the given example, you should obtain an exact match when you include all of the terms with \(m=0,1,2,3\text{.}\) In general, there are an infinite number of nonzero terms in the Legendre series; your approximation will get better and better as you include more terms.

You can use the right and left arrow keys to move the selected slider in increments of 0.5; holding down the shift key as well changes the increment to 0.05.