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 tuple of points x in Python
To evaluate a Laguerre series at points x, use the polynomial.laguerre.lagval() method in Python NumPy. The first parameter is x, which can be a list, tuple, or scalar. If x is a list or tuple, it is converted to an ndarray, otherwise it is left unchanged and treated as a scalar.
The second parameter c is an array of coefficients ordered so that the coefficients for terms of degree n are contained in c[n]. If c is multidimensional, the remaining indices enumerate multiple polynomials.
The third parameter tensor controls the evaluation behavior. If True (default), the shape of the coefficient array is extended with ones on the right, one for each dimension of x. If False, x is broadcast over the columns of c for the evaluation.
Syntax
numpy.polynomial.laguerre.lagval(x, c, tensor=True)
Parameters
- x − Points at which to evaluate the series (scalar, list, or tuple)
- c − Array of Laguerre series coefficients
- tensor − Boolean flag controlling evaluation method (default: True)
Example
Let's evaluate a Laguerre series with coefficients [1, 2, 3] at tuple points (5, 10, 15) −
import numpy as np
from numpy.polynomial import laguerre as L
# Create an array of coefficients
c = np.array([1, 2, 3])
# Display the array
print("Our Array...")
print(c)
# Check the Dimensions
print("\nDimensions of our Array...")
print(c.ndim)
# Get the Datatype
print("\nDatatype of our Array object...")
print(c.dtype)
# Get the Shape
print("\nShape of our Array object...")
print(c.shape)
# Here, x is a tuple
x = (5, 10, 15)
# To evaluate a Laguerre series at points x, use the polynomial.laguerre.lagval() method
print("\nResult...")
print(L.lagval(x, c))
Our Array... [1 2 3] Dimensions of our Array... 1 Datatype of our Array object... int64 Shape of our Array object... (3,) Result... [ 3.5 76. 223.5]
How It Works
The Laguerre polynomial series with coefficients [1, 2, 3] represents:
P(x) = 1×L?(x) + 2×L?(x) + 3×L?(x)
Where L?(x), L?(x), and L?(x) are the first three Laguerre polynomials. The function evaluates this series at each point in the tuple (5, 10, 15).
Multiple Points Example
import numpy as np
from numpy.polynomial import laguerre as L
# Coefficients for a simple Laguerre series
coefficients = np.array([2, -1, 0.5])
# Multiple evaluation points as a tuple
points = (1, 2, 3, 4)
# Evaluate the series
result = L.lagval(points, coefficients)
print("Evaluation points:", points)
print("Laguerre series values:", result)
Evaluation points: (1, 2, 3, 4) Laguerre series values: [1.5 1.5 2.5 4.5]
Conclusion
Use numpy.polynomial.laguerre.lagval() to evaluate Laguerre series at multiple points efficiently. The function accepts tuples, lists, or arrays as input points and returns the corresponding series values.
