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 points x with multidimensional coefficient array in Python
To evaluate a Laguerre series at points x with a multidimensional coefficient array, use the polynomial.laguerre.lagval() method in Python NumPy. This method allows you to evaluate multiple Laguerre polynomials simultaneously using a 2D coefficient matrix.
Syntax
numpy.polynomial.laguerre.lagval(x, c, tensor=True)
Parameters
The function accepts three parameters ?
- x − Points at which to evaluate the series. Can be scalar, list, or array
- c − Coefficient array where coefficients for degree n are in c[n]. For multidimensional arrays, additional indices represent multiple polynomials
- tensor − Boolean flag controlling evaluation behavior (default True)
Creating and Evaluating Laguerre Series
Let's create a multidimensional coefficient array and evaluate the Laguerre series at specific points ?
import numpy as np
from numpy.polynomial import laguerre as L
# Create a multidimensional array of coefficients
coefficients = np.array([[1, 2], [3, 4]])
print("Coefficient Array:")
print(coefficients)
print("\nArray Shape:", coefficients.shape)
print("Array Dimensions:", coefficients.ndim)
Coefficient Array: [[1 2] [3 4]] Array Shape: (2, 2) Array Dimensions: 2
Evaluating at Multiple Points
Now we'll evaluate the Laguerre series at points x = [1, 2] using our coefficient matrix ?
import numpy as np
from numpy.polynomial import laguerre as L
coefficients = np.array([[1, 2], [3, 4]])
points = [1, 2]
# Evaluate Laguerre series
result = L.lagval(points, coefficients)
print("Evaluation points:", points)
print("Result shape:", result.shape)
print("Result:")
print(result)
Evaluation points: [1, 2] Result shape: (2, 2) Result: [[ 1. -2.] [ 2. -2.]]
How It Works
With a 2D coefficient array, each column represents a separate polynomial. The Laguerre polynomial for degree n is defined as:
Understanding the Output
The result matrix shows evaluations for each polynomial column at each input point ?
import numpy as np
from numpy.polynomial import laguerre as L
coefficients = np.array([[1, 2], [3, 4]])
# Manual calculation for verification
# First column: [1, 3] ? 1*L?(x) + 3*L?(x) = 1*1 + 3*(1-x) = 4-3x
# Second column: [2, 4] ? 2*L?(x) + 4*L?(x) = 2*1 + 4*(1-x) = 6-4x
print("Manual calculation for x=1:")
print("First polynomial: 4 - 3*1 =", 4 - 3*1)
print("Second polynomial: 6 - 4*1 =", 6 - 4*1)
print("\nNumPy result:")
result = L.lagval([1, 2], coefficients)
print(result)
Manual calculation for x=1: First polynomial: 4 - 3*1 = 1 Second polynomial: 6 - 4*1 = 2 NumPy result: [[ 1. -2.] [ 2. -2.]]
Conclusion
The lagval() method efficiently evaluates multiple Laguerre polynomials simultaneously using coefficient matrices. Each column represents a different polynomial, and the function returns evaluations for all combinations of points and polynomials.
