SpecialFunctions.jl icon indicating copy to clipboard operation
SpecialFunctions.jl copied to clipboard

First try at implementing evaluation of legendrePolynomial

Open ludoro opened this issue 7 years ago • 5 comments

Hello everyone!

As I wrote in issue #124, I tried to implement an evaluation of Legendre Polynomials. As there are derivatives, I used a closed form, as found here: https://en.wikipedia.org/wiki/Legendre_polynomials

I am sure I should write some tests for this function, as well as some kind of documentation. However I wanted to put this out here so people can comment and give their opinions on things I should improve.

Let me know what you think!

Ludovico

ludoro avatar Dec 17 '18 21:12 ludoro

This doesn't seem like it would be very efficient or numerically robust approach. I would suggest looking in the literature on how these are used and evaluated.

simonbyrne avatar Dec 18 '18 21:12 simonbyrne

Thank you for your opinion. I tried again with a different approach using recursion. I took ispiration from here: http://people.sc.fsu.edu/~jburkardt/py_src/legendre_polynomial/legendre_polynomial.html I hope it is better than before. Let me know what you think.

Happy holidays!

Ludovico

ludoro avatar Dec 27 '18 12:12 ludoro

If you want pointwise evaluation of associated Legendre polynomials, you will definitely want to use Clenshaw-Smith recurrence. See here: https://github.com/MikaelSlevinsky/FastTransforms.jl/blob/master/src/SphericalHarmonics/sphfunctions.jl

MikaelSlevinsky avatar Dec 28 '18 03:12 MikaelSlevinsky

What about using tabulated coefficients? The coefficients are defined by that series https://oeis.org/A008316 Should be a fast start for small orders ...

PaulXiCao avatar Aug 15 '19 20:08 PaulXiCao

Definitely not. The coefficients of Legendre polynomials in the monomial basis grow geometrically, so any numerics based on this approach would be ill-conditioned.

The three-term recurrence relation is preferred. See also ApproxFun.jl for numerical computing with orthogonal polynomials.

MikaelSlevinsky avatar Aug 15 '19 20:08 MikaelSlevinsky