# Compute the roots of a Laguerre series in Python

PythonNumpyServer Side ProgrammingProgramming

To Compute the roots of a Laguerre series, use the laguerre.lagroots() method in Python Numpy. The method returns an array of the roots of the series. If all the roots are real, then out is also real, otherwise it is complex.

The root estimates are obtained as the eigenvalues of the companion matrix, Roots far from the origin of the complex plane may have large errors due to the numerical instability of the 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 origin can be improved by a few iterations of Newton’s method.

## Steps

At first, import the required library −

from numpy.polynomial import laguerre as L

To Compute the roots of a Laguerre series, use the laguerre.lagroots() method in Python Numpy −

print("Result...\n",L.lagroots([0, 1, 2]))

Get the datatype −

print("\nType...\n",L.lagroots([0, 1, 2]).dtype)

Get the shape −

print("\nShape...\n",L.lagroots([0, 1, 2]).shape)


## Example

from numpy.polynomial import laguerre as L

# To Compute the roots of a Laguerre series, use the laguerre.lagroots() method in Python Numpy.
# The method returns an array of the roots of the series. If all the roots are real, then out is also real, otherwise it is complex..
print("Result...\n",L.lagroots([0, 1, 2]))

# Get the datatype
print("\nType...\n",L.lagroots([0, 1, 2]).dtype)

# Get the shape
print("\nShape...\n",L.lagroots([0, 1, 2]).shape)

## Output

Result...
[0.69722436 4.30277564]

Type...
float64

Shape...
(2,)
Updated on 04-Mar-2022 06:23:40