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 when coefficients are multi-dimensional in Python
To evaluate a Laguerre series at points x with multi-dimensional coefficients, use the polynomial.laguerre.lagval() method in Python NumPy. This method allows evaluation of multiple polynomials simultaneously when coefficients are arranged in a multi-dimensional array.
Parameters
The lagval() method takes three main parameters:
- x: The evaluation points. Can be a scalar, list, or array
- c: Array of coefficients where coefficients for degree n are in c[n]. For multi-dimensional arrays, additional indices represent multiple polynomials
- tensor: Boolean parameter (default True) controlling how x and c interact during evaluation
Basic Example with Multi-dimensional Coefficients
Let's create a 2D coefficient array and evaluate the Laguerre series at multiple points ?
import numpy as np
from numpy.polynomial import laguerre as L
# Create a multidimensional array of coefficients
c = np.arange(4).reshape(2,2)
print("Coefficient Array:")
print(c)
print(f"Shape: {c.shape}")
# Evaluate at points [1, 2]
result = L.lagval([1, 2], c)
print("\nResult:")
print(result)
Coefficient Array: [[0 1] [2 3]] Shape: (2, 2) Result: [[ 0. -2.] [ 1. -2.]]
Understanding the Coefficient Structure
In the 2D case, each column represents a separate polynomial. The coefficient array structure is ?
import numpy as np
from numpy.polynomial import laguerre as L
c = np.array([[0, 1], # degree 0 coefficients for poly1, poly2
[2, 3]]) # degree 1 coefficients for poly1, poly2
print("Polynomial 1 coefficients: [0, 2] (degrees 0, 1)")
print("Polynomial 2 coefficients: [1, 3] (degrees 0, 1)")
# Evaluate both polynomials at x=0.5
result = L.lagval(0.5, c)
print(f"\nEvaluation at x=0.5: {result}")
Polynomial 1 coefficients: [0, 2] (degrees 0, 1) Polynomial 2 coefficients: [1, 3] (degrees 0, 1) Evaluation at x=0.5: [1. 2.5]
Effect of Tensor Parameter
The tensor parameter controls how evaluation points and coefficients interact ?
import numpy as np
from numpy.polynomial import laguerre as L
c = np.arange(6).reshape(3,2)
x = [0, 1]
print("Coefficients:")
print(c)
# tensor=True (default): each x evaluates all polynomials
result_true = L.lagval(x, c, tensor=True)
print(f"\nWith tensor=True, shape: {result_true.shape}")
print(result_true)
# tensor=False: broadcasting behavior
result_false = L.lagval(x, c, tensor=False)
print(f"\nWith tensor=False, shape: {result_false.shape}")
print(result_false)
Coefficients: [[0 1] [2 3] [4 5]] With tensor=True, shape: (2, 2) [[ 0. 1.] [-4. -7.]] With tensor=False, shape: (2,) [ 0. -7.]
Conclusion
The lagval() method efficiently evaluates multiple Laguerre polynomials simultaneously using multi-dimensional coefficient arrays. Use tensor=True to evaluate all polynomials at all points, or tensor=False for element-wise evaluation.
