Hi all,

When attempting to find the roots of a Legendre polynomial:

In [3]: from sympy import Poly, legendre_poly

In [4]: lp = Poly(legendre_poly(5))

In [5]: [float(r.evalf()) for r in lp.all_roots()]
Out[5]:
[-0.5384693101056831,
 -0.5384693101056831,
 0.0,
 0.5384693101056831,
 0.906179845938664]

Observe now the first root, which should be -0.906, gets found as
-0.538.  I /suspect/ this is because the RootOf.evalf() method uses
nsolve -- or something analogous -- which requires an initial guess.

mpmath.polysolve does the job (and on account of the method used does
not have any trouble finding all of the roots) but has a less direct
syntax.  (Specifically, if one tries to pass the output from
.all_coeffs() as the coeffs parameter to mpmath.polysolve the method
enters an infinite loop; it is necessary to explicitly run:

mpmath.polysolve([float(c) for c in lp.all_coeffs()])

Regards, Freddie.

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to