Generate a Laguerre series with given roots in Python


To generate a Laguerre series with given roots, use the laguerre.lagfromroots() method in Python Numpy. The method returns a 1-D array of coefficients. If all roots are real then out is a real array, if some of the roots are complex, then out is complex even if all the coefficients in the result are real. The parameter roots are the sequence containing the roots.

Steps

At first, import the required library −

from numpy.polynomial import laguerre as L

To generate a Laguerre series with given roots, use the laguerre.lagfromroots() method in Python Numpy −

print("Result...\n",L.lagfromroots((-1,0,1)))

Get the datatype −

print("\nType...\n",L.lagfromroots((-1,0,1)).dtype)

Get the shape −

print("\nShape...\n",L.lagfromroots((-1,0,1)).shape)

Example

from numpy.polynomial import laguerre as L

# To generate a Laguerre series with given roots, use the laguerre.lagfromroots() method in Python Numpy.
# The method returns a 1-D array of coefficients. If all roots are real then out is a real array, if some of the roots are complex, then out is complex even if all the coefficients in the result are real.

# The parameter roots are the sequence containing the roots.
print("Result...\n",L.lagfromroots((-1,0,1)))

# Get the datatype
print("\nType...\n",L.lagfromroots((-1,0,1)).dtype)

# Get the shape
print("\nShape...\n",L.lagfromroots((-1,0,1)).shape)

Output

Result...
   [ 5. -17. 18. -6.]

Type...
float64

Shape...
(4,)

Updated on: 04-Mar-2022

85 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements