Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Generate a Laguerre series with given roots in Python
To generate a Laguerre series with given roots in Python NumPy, use the laguerre.lagfromroots() method. This function returns a 1-D array of coefficients representing the polynomial. If all roots are real, the output is a real array; if some roots are complex, the output is complex even if all resulting coefficients are real.
Syntax
numpy.polynomial.laguerre.lagfromroots(roots)
Parameters:
- roots ? Sequence containing the roots of the polynomial
Returns: 1-D array of Laguerre series coefficients ordered from lowest to highest degree.
Example with Real Roots
Let's generate a Laguerre series with roots at -1, 0, and 1 ?
from numpy.polynomial import laguerre as L
# Generate Laguerre series with given roots
roots = (-1, 0, 1)
result = L.lagfromroots(roots)
print("Roots:", roots)
print("Coefficients:", result)
print("Data type:", result.dtype)
print("Shape:", result.shape)
Roots: (-1, 0, 1) Coefficients: [ 5. -17. 18. -6.] Data type: float64 Shape: (4,)
Example with Complex Roots
When using complex roots, the output array becomes complex ?
from numpy.polynomial import laguerre as L
# Generate Laguerre series with complex roots
complex_roots = (1+2j, 1-2j, 0)
result = L.lagfromroots(complex_roots)
print("Complex roots:", complex_roots)
print("Coefficients:", result)
print("Data type:", result.dtype)
Complex roots: ((1+2j), (1-2j), 0) Coefficients: [-10. +0.j 23. +0.j -18. +0.j 5. +0.j] Data type: complex128
How It Works
The Laguerre polynomial with roots r?, r?, ..., r? is constructed by multiplying the factors (x - r?) and then converting to the Laguerre basis. The resulting coefficients represent the polynomial in terms of Laguerre basis functions.
Conclusion
Use lagfromroots() to generate Laguerre series coefficients from given roots. The function automatically handles both real and complex roots, returning appropriate data types.
