numpy.polynomial.legendre.legroots

numpy.polynomial.legendre.legroots(cs)

Compute the roots of a Legendre series.

Returns the roots (a.k.a “zeros”) of the Legendre series represented by cs, which is the sequence of coefficients from lowest order “term” to highest, e.g., [1,2,3] is the series L_0 + 2*L_1 + 3*L_2.

Parameters :

cs : array_like

1-d array of Legendre series coefficients ordered from low to high.

maxiter : int, optional

Maximum number of iterations of Newton to use in refining the roots.

Returns :

out : ndarray

Sorted array of the roots. If all the roots are real, then so is the dtype of out; otherwise, out‘s dtype is complex.

See also

polyroots, chebroots

Notes

The root estimates are obtained as the eigenvalues of the companion matrix, Roots far from the real interval [-1, 1] in the complex plane may have large errors due to the numerical instability of the Lengendre series for such values. Roots with multiplicity greater than 1 will also show larger errors as the value of the series near such points is relatively insensitive to errors in the roots. Isolated roots near the interval [-1, 1] can be improved by a few iterations of Newton’s method.

The Legendre series basis polynomials aren’t powers of x so the results of this function may seem unintuitive.

Examples

>>> import numpy.polynomial.legendre as leg
>>> leg.legroots((1, 2, 3, 4)) # 4L_3 + 3L_2 + 2L_1 + 1L_0 has only real roots
array([-0.85099543, -0.11407192,  0.51506735])

Next topic

numpy.polynomial.legendre.legfromroots

This Page