Sturm-Liouville Theory; Functional Basis

Establish by example the orthogonality relations for the Lengendre Polynomials

Table[
      Integrate[
        LegendreP[i, x] LegendreP[5, x], {x, -1, 1}], {i, -10, 
        10}]

Calculate the norm as a function of the order of the Legendre polynomial

Table[
      Integrate[LegendreP[i, x] LegendreP[i, x], {x, -1, 1}], {i, 0, 
        15}]

Make a guess at what the norm looks like

Table[(2/(2 i  +  1)),  {i, 0, 15}]

The orthogonality relation is most probably: (∫_(-1)^1) LegendreP[i, x]  LegendreP[
            j, x] dx = ({{(2/(2  i  +  1)), if i = j}, {0, if i  ≠ j}})

Representation of a function in terms of the Legendre basis

A function to calculate the coefficients

LegendreCoefficient[f_,  i_]   :=  ((2 i  +  1)/2) 
        Integrate[f[x] LegendreP[i, x], {x, -1, 1}]

This is an example function:

AFunc[x_]  := Exp[-x^2]

Calculate the first twenty coefficients

Lcofs  =  Table[LegendreCoefficient[AFunc, i], {i, 0, 20}]

Construct a vector of the eigenfunctions

Lfuncs  =  Table[LegendreP[i, x], {i, 0, 20}];

Visualize the approximation of the first twenty terms

Plot[{Lcofs . Lfuncs, Exp[-x^2]}, {x, -1, 1}, 
      PlotStyle -> {{Hue[0], Thickness[0.01]}, {Hue[0.66], 
            Thickness[0.005]}}]

Try another function

AFunc[x_]  := Sin[5  x] Sin[(5  +  (1/10)) x]

Coefficients out to 10 terms

Lcofs  =  Table[LegendreCoefficient[AFunc, i], {i, 0, 10}]

Lfuncs  =  Table[LegendreP[i, x], {i, 0, 10}];

Visualize the approximation

Plot[{Lcofs . Lfuncs, AFunc[x]}, {x, -1, 1}, 
      PlotStyle -> {{Hue[0], Thickness[0.01]}, {Hue[0.66], 
            Thickness[0.005]}}]