[Math] Finding coefficients of Legendre Polynomials

approximationleast squareslegendre polynomialsorthogonal-polynomialspolynomials

By considering the 2-norm(least squares) approximation of $f(x)=e^x$ for $-1\le x\le 1$ by a polynomial of degree $N$ which is expanded into a series of Legendre polynomials $P_j(x):$

$$Q_N(x)=\sum_{j=0} ^N \lambda_jP_j(x)$$

Calculate the expansion coefficients $\lambda_0,\lambda_1,\lambda_2,\lambda_3 $.


So given that $N=3$, I know that the Legendre Polynomials are $P_0(x)=1$, $P_1(x)=x$, $P_1(x)=\frac{1}{2}(3x^2-1)$ and $P_3(x)=\frac{1}{2}(5x^3-2x)$.

I also understand that the 2-norm(least squares) approximation seeks to minimise $$E^2=\int_{-1}^{1} (e^x-Q_N(x))^2dx $$

Where $Q_N(x)$ is the polynomial of degree N asked for in the question.

I think you need to do $$\lambda_j=\frac{2(j)+1} {2}\int_{-1}^{1}P_je^x dx $$

which for $j=0, P_0=1$ gives $\lambda_0=\frac{1}{2}(e-e^{-1}) $ and then you continue to do so for $j=1,2,3$.

Is this the correct approach?

Best Answer

The goal is to approximate a function $f(x)$ over the interval $(-1,1)$ with a sequence of Legendre polynomials $P_{k}(x)$ through order $d$: $$ f(x) = \lambda_{0} P_{0}(x) + \lambda_{1} P_{1}(x) + \dots + \lambda_{d} P_{d}(x) = \sum_{k=0}^{d} \lambda_{k} P_{k}(x) $$ What amplitudes $\lambda$ provide the best fit?

Projection will extract the $\lambda$ values without having to form a linear system. The Legendre functions are an orthogonal basis over the domain: $$ \int_{-1}^{1} P_{j}(x) P_{k}(x) dx = \frac{2(k+1)}{2} \delta_{j}^{k} $$ Orthogonality allows the amplitudes to be computed independently. This will project out each $\lambda$ value; integrate both side of the approximation equation over the domain. $$ \int_{-1}^{1} f(x) P_{j}(x) dx = \int_{-1}^{1} \left( \sum_{k=0}^{d} \lambda_{k} P_{k}(x) \right) P_{j}(x) dx = \int_{-1}^{1} \lambda_{j} P_{j}^{2}(x) dx $$ Therefore $$ \lambda_{j} = \frac{2}{2(j+1)} \int_{-1}^{1} f(x) P_{j}(x) dx $$ The computed fit parameters are $$ \lambda = \left[ \begin{array}{c} \lambda_{0} \\ \lambda_{1} \\ \lambda_{2} \\ \lambda_{3} \end{array} \right] = \left[ \begin{array}{c} \frac{1}{2} \left(e-\frac{1}{e}\right) \\[2pt] \frac{3}{e} \\ \frac{5}{2} \left(e-\frac{7}{e}\right) \\[3pt] \frac{7}{2} \left(\frac{37}{e}-5 e\right) \end{array} \right] $$ The following plot shows the error $$ r(x) = f(x) - \sum_{k=0}^{3}\lambda_{k} P_{k}(x) $$ plotted over the domain.

enter image description here

Related Question