Section 5.6 Guessing and Visualizing a Legendre Polynomial Series
In Section 5.2 we derived the algebra/calculus for finding the Legendre polynomial expansion of any sufficiently smooth function. In this section, you first try to guess the coefficients and later use Sage code to calculate the coefficients and verify their values graphically. You are encouraged to explore the overall shapes of the Legendre basis functions using the sage code in Section 5.2 before working through the examples in this section.
Figure 3 below allows you to see the effect of varying the Legendre coefficients individually while trying to guess the Legendre expansion of a given function.
and satisfy the orthogonality condition
\begin{equation}
\int_{-1}^1 P_m(x)P_n(x) = \frac{2}{2n+1} \delta_{mn} .\tag{5.6.1}
\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{5.6.2}
\end{equation}
and use (5.6.1) to determine the coefficients as
\begin{equation}
a_n = \frac{2n+1}{2} \int_{-1}^1 P_n(x) f(x), dx.\tag{5.6.3}
\end{equation}
Now we will use the integral expressions (5.6.3) 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 4, set the \(a_0\) slider to correspond to the value you just calcuated. Compare your approximate Legendre series, containing just one term (shown in green), to the actual function (shown in blue).
1
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.
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.