[SciPy-user] Legendre Polynomials

rgold@lsw.uni-heidelbe... rgold@lsw.uni-heidelbe...
Thu Aug 23 04:58:22 CDT 2007

Hi everybody,
I am using: Python 2.4 and Scipy 5.0.1-3ubuntu2

I have run into problems trying to expand a function into
The calculated coefficients start to explode from l=33 on...
The problem is that (for some reason) the evaluation of the Legendre
Polynomials  near x <= -1 starts to become wrong from l=33 on!
See for example:

>>> scipy.special.legendre(21)(-1)
>>> scipy.special.legendre(31)(-1)
>>> scipy.special.legendre(33)(-1)
>>> scipy.special.legendre(35)(-1)
>>> scipy.special.legendre(45)(-1)

Moreover the xrange of that error grows with l:

>>> scipy.special.legendre(35)(-0.8)
>>> scipy.special.legendre(45)(-0.8)
>>> scipy.special.legendre(45)(-0.5)

The problem occures also for the even Polynomials but interestingly again
for the negative arguments only as you can see here:

>>> scipy.special.legendre(36)(-1)
>>> x=arange(-1,1,0.01)
>>> plot(x,scipy.special.legendre(36)(x))
[<matplotlib.lines.Line2D instance at 0xb6053b2c>]
>>> show()

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!

Please help!

More information about the SciPy-user mailing list