2
$\begingroup$

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?

$\endgroup$
5
$\begingroup$

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

$\endgroup$
  • $\begingroup$ Why is there a # within the square bracket of the Legendre algorithm? Dummy variable? $\endgroup$ – Physkid Sep 3 '15 at 6:41
  • $\begingroup$ @Physkid It's paired with the & at the end, forming a function/argument pair. See for example this answer, and all the other answers in that question too, BTW. $\endgroup$ – Dr. belisarius Sep 3 '15 at 12:58
  • $\begingroup$ @Physkid It's more or less equivalent to k = Function[{s}, Sum[a[m, f] LegendreP[m, s], {m, 0, i}]] $\endgroup$ – Dr. belisarius Sep 3 '15 at 13:11
  • $\begingroup$ In particular, readers ought to notice the Gibbs ringing in the second picture… $\endgroup$ – J. M. will be back soon Sep 4 '15 at 1:46
  • $\begingroup$ @Guesswhoitis.I remember learning about it while reading a Michelson biography as a child. I was mesmerized :) $\endgroup$ – Dr. belisarius Sep 4 '15 at 1:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.