Section 21.3 Legendre Series: Worked Example
You are encouraged to explore the Legendre basis functions using the applet in Figure 21.2 before working through the example here.
The unrenormalized Legendre polynomials can be defined as
and satisfy the orthogonality condition
We can expand any function \(f(x)\) on the interval \(-1\le x\le1\) in terms of these Legendre polynomials as
and use (21.3.4) to determine the coefficients as
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 (21.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 21.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).
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.