[SciPy-user] Legendre Polynomials
Mon Aug 27 23:23:14 CDT 2007
On 23/08/07, email@example.com <firstname.lastname@example.org> wrote:
> A first quick (but not satisfying) idea was to use the values calculated
> for x>=0 and copy them (of course correcting for the minus sign if l is
> Problems remaining:
> -> WHY is the evaluation wrong for x close to -1?
> -> Can I trust the routine at all?
> As a test I tried to expand cos(x) over Legendre-Polynomials because I
> know the result: Coefficient 1 should be 1 and the others as small as
> It works quite fine as long as l<33!
All of scipy's orthogonal polynomials are implemented using recurrence
relations. These are a fairly good way to address the problem in
general, but they can go berserk for high orders. I ran into a similar
problem when trying to evaluate high-order orthogonal polynomials of
several types (to construct my own with custom weights).
In some cases there are other approaches for evaluating them
accurately (for example the nth Chebyshev polynomial is
cos(n*arccos(X))); you might check Abramowitz and Stegun for some
helpful analytic relations. I think scipy.special might also have some
legendre functions, implemented using cephes, that might be more
In terms of improving scipy, I don't think there's a better wayto
handle arbitrary families of orthogonal polynomials. But it would be
nice to have certain classes of orthogonal polynomial - chebyshev, for
example - implemented using special-case, more reliable, methods. I
haven't looked to see whether the orthogonal polynomial class (which
is in pure python) admits this kind of extensibility.
More information about the SciPy-user