2

I am given the Legendre expansion of the first kind. $$f(x)=\sum_{n=0}^{\infty}A_{n}P_{n}(x).$$

I have worked the coefficient to be $$A_{n}=\frac{1}{\left \| P_{n}(x) \right \|^{2}} \int_{x=-1}^{x=1}f(x)P_{n}dx $$

Here are my codes: enter image description here

The function f is also given. I'm trying to sum the expression as outlined. How should I go about implementing some kind of loop?

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
Physkid
  • 680
  • 5
  • 13

1 Answers1

5

When your book refers to the norm of the Legendre polynomials it is using the $L^2$ norm, because the orthogonality relationship is

$$ \int_{-1}^{1} P_m(x) P_n(x) dx = \frac{2}{(2 m+1)} \delta_{mn} $$

So,

f[x_] := x^3 - 4 x^2 + 4 x + 2
a[m_, f_] := a[m, f] = (2 m + 1)/2 Integrate[LegendreP[m, x] f[x], {x, -1, 1}]

Manipulate[
 k = Sum[a[m, f] LegendreP[m, #], {m, 0, i}] &;
 Plot[{k[t], f[t]}, {t, -1, 1}, PlotLabel -> "Order: " <> ToString@i],
 {i, 0, 5, 1}]

Mathematica graphics

Another example:

f[x_] := UnitStep[x]
a[m_, f_] := a[m, f] = (2 m + 1)/2 Integrate[LegendreP[m, x] f[x], {x, -1, 1}]
k = Sum[a[m, f] LegendreP[m, #], {m, 0, i}] &;
Plot[Evaluate@Join[{f[t]}, Table[k[t], {i, 1, 9, 2}]], {t, -1, 1}, PlotRange -> All]

Mathematica graphics

Dr. belisarius
  • 115,881
  • 13
  • 203
  • 453