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
Selected Reading
Evaluate a Laguerre series at list of points x in Python
To evaluate a Laguerre series at points x, use the polynomial.laguerre.lagval() method in NumPy. This function takes evaluation points and coefficients to compute the series values.
Syntax
numpy.polynomial.laguerre.lagval(x, c, tensor=True)
Parameters
The function accepts three parameters:
- x ? Array of points at which to evaluate the series. Can be a scalar, list, or array
- c ? Array of coefficients ordered from lowest to highest degree
- tensor ? Boolean controlling evaluation behavior for multidimensional arrays (default: True)
Example
Let's evaluate a Laguerre series with coefficients [1, 2, 3] at multiple 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 array
print("Coefficients:", c)
# Check array properties
print("Dimensions:", c.ndim)
print("Datatype:", c.dtype)
print("Shape:", c.shape)
# Define evaluation points
x = [5, 10, 15]
print("Evaluation points:", x)
# Evaluate Laguerre series at points x
result = L.lagval(x, c)
print("Result:", result)
Coefficients: [1 2 3] Dimensions: 1 Datatype: int64 Shape: (3,) Evaluation points: [5, 10, 15] Result: [ 3.5 76. 223.5]
How It Works
The Laguerre series is evaluated using the formula:
L(x) = c[0]*L?(x) + c[1]*L?(x) + c[2]*L?(x) + ...
Where L?(x), L?(x), L?(x) are the Laguerre polynomials of degrees 0, 1, 2 respectively.
Single Point Evaluation
You can also evaluate at a single point ?
import numpy as np
from numpy.polynomial import laguerre as L
c = np.array([1, 2, 3])
x = 5
# Evaluate at single point
result = L.lagval(x, c)
print(f"Laguerre series at x={x}: {result}")
Laguerre series at x=5: 3.5
Conclusion
The lagval() function efficiently evaluates Laguerre series at specified points using coefficient arrays. It handles both single points and arrays of evaluation points seamlessly.
Advertisements
