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
Evaluate a Laguerre series at array of points x in Python
To evaluate a Laguerre series at array of points x, use the polynomial.laguerre.lagval() method in Python NumPy. This method evaluates a Laguerre polynomial series at given points using the coefficients and evaluation points you provide.
Syntax
The lagval() method has the following syntax:
numpy.polynomial.laguerre.lagval(x, c, tensor=True)
Parameters
- x − Array of points at which to evaluate the polynomial. If x is a list or tuple, it is converted to an ndarray. Elements must support addition and multiplication with coefficient elements.
- c − Array of coefficients ordered so that coefficients for terms of degree n are in c[n]. For multidimensional arrays, remaining indices enumerate multiple polynomials.
- tensor − If True (default), extends coefficient array shape for broadcasting. If False, x is broadcast over columns of c.
Example
Let's evaluate a Laguerre series with coefficients [1, 2, 3] at various points:
import numpy as np
from numpy.polynomial import laguerre as L
# Create an array of coefficients
c = np.array([1, 2, 3])
# Display the coefficient array
print("Coefficient Array:")
print(c)
# Check array properties
print("\nArray Properties:")
print("Dimensions:", c.ndim)
print("Datatype:", c.dtype)
print("Shape:", c.shape)
# Evaluate Laguerre series at points
x = np.array([[1, 2], [3, 4]])
print("\nEvaluation points:")
print(x)
result = L.lagval(x, c)
print("\nLaguerre series evaluation result:")
print(result)
Coefficient Array: [1 2 3] Array Properties: Dimensions: 1 Datatype: int64 Shape: (3,) Evaluation points: [[1 2] [3 4]] Laguerre series evaluation result: [[-0.5 -4. ] [-4.5 -2. ]]
How It Works
The Laguerre polynomial series is evaluated using the formula:
L?(x) = 1, L?(x) = 1 - x, L?(x) = (2 - 4x + x²)/2
For coefficients [1, 2, 3], the series becomes: 1×L?(x) + 2×L?(x) + 3×L?(x)
Different Evaluation Points
import numpy as np
from numpy.polynomial import laguerre as L
# Same coefficients
c = np.array([1, 2, 3])
# Single point evaluation
x_single = 2.0
result_single = L.lagval(x_single, c)
print(f"At x = {x_single}: {result_single}")
# Multiple points in 1D array
x_multiple = np.array([0, 1, 2, 3])
result_multiple = L.lagval(x_multiple, c)
print(f"At x = {x_multiple}: {result_multiple}")
At x = 2.0: -4.0 At x = [0 1 2 3]: [ 6. -0.5 -4. -4.5]
Conclusion
The lagval() method efficiently evaluates Laguerre polynomial series at given points. Use it with coefficient arrays and evaluation points to compute Laguerre series values for mathematical and scientific applications.
