Compute the roots of a Laguerre series with given complex roots in Python

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 output 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.

Syntax

numpy.polynomial.laguerre.lagroots(c)

Parameters:

  • c ? 1-D array of Laguerre series coefficients ordered from low to high degree

Returns: Array of the roots of the series

Example

Let's compute the roots of a Laguerre series with complex coefficients ?

from numpy.polynomial import laguerre as L

# Define complex coefficients
j = complex(0, 1)
coefficients = [-j, j]

# Compute the roots of the Laguerre series
roots = L.lagroots(coefficients)
print("Roots:")
print(roots)

# Check the datatype
print("\nDatatype:")
print(roots.dtype)

# Check the shape
print("\nShape:")
print(roots.shape)
Roots:
[0.+0.j]

Datatype:
complex128

Shape:
(1,)

Working with Real Coefficients

When using real coefficients, the roots may still be complex depending on the polynomial ?

from numpy.polynomial import laguerre as L

# Real coefficients
real_coeffs = [1, -2, 1]
roots_real = L.lagroots(real_coeffs)

print("Coefficients:", real_coeffs)
print("Roots:", roots_real)
print("Datatype:", roots_real.dtype)
Coefficients: [1, -2, 1]
Roots: [2.61803399 0.38196601]
Datatype: float64

Multiple Roots Example

Here's an example with multiple coefficients to demonstrate more complex root finding ?

from numpy.polynomial import laguerre as L
import numpy as np

# More complex coefficients
coeffs = [1, 0, -1, 2]
roots = L.lagroots(coeffs)

print("Coefficients:", coeffs)
print("Number of roots:", len(roots))
print("Roots:")
for i, root in enumerate(roots):
    print(f"Root {i+1}: {root}")
Coefficients: [1, 0, -1, 2]
Number of roots: 3
Roots:
Root 1: (0.41577455697103896+0j)
Root 2: (2.2942127215144805+1.0667575710326772j)
Root 3: (2.2942127215144805-1.0667575710326772j)

Conclusion

The lagroots() function efficiently computes Laguerre series roots using eigenvalue methods. For complex coefficients, it returns complex roots, while real coefficients may produce either real or complex roots depending on the polynomial structure.

Updated on: 2026-03-26T20:29:44+05:30

261 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements