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 2D Laguerre series at points (x,y) in Python
To evaluate a 2D Laguerre series at points (x,y), use the polynomial.laguerre.lagval2d() method in Python NumPy. The method returns the values of the two-dimensional polynomial at points formed with pairs of corresponding values from x and y.
Syntax
numpy.polynomial.laguerre.lagval2d(x, y, c)
Parameters
The function takes three parameters:
- x, y − The two dimensional series is evaluated at the points (x, y), where x and y must have the same shape. If x or y is a list or tuple, it is first converted to an ndarray, otherwise it is left unchanged and if it isn't an ndarray it is treated as a scalar.
- c − Array of coefficients ordered so that the coefficient of the term of multi-degree i,j is contained in c[i,j]. If c has dimension greater than two, the remaining indices enumerate multiple sets of coefficients.
Example
Let's create a coefficient array and evaluate the 2D Laguerre series at specific points ?
import numpy as np
from numpy.polynomial import laguerre as L
# Create a multidimensional array of coefficients
c = np.array([[1,2],[3,4]])
# Display the array
print("Our Array...\n",c)
# Check the Dimensions
print("\nDimensions of our Array...\n",c.ndim)
# Get the Datatype
print("\nDatatype of our Array object...\n",c.dtype)
# Get the Shape
print("\nShape of our Array object...\n",c.shape)
# To evaluate a 2D Laguerre series at points (x,y), use lagval2d()
print("\nResult...\n",L.lagval2d([1,2],[1,2],c))
Our Array... [[1 2] [3 4]] Dimensions of our Array... 2 Datatype of our Array object... int64 Shape of our Array object... (2, 2) Result... [1. 0.]
Evaluating at Different Points
You can evaluate the series at different x and y coordinates ?
import numpy as np
from numpy.polynomial import laguerre as L
# Coefficient array
c = np.array([[1,2],[3,4]])
# Evaluate at origin (0,0)
result_origin = L.lagval2d(0, 0, c)
print("At (0,0):", result_origin)
# Evaluate at multiple points
x_points = [0, 1, 2]
y_points = [0, 1, 2]
result_multiple = L.lagval2d(x_points, y_points, c)
print("At multiple points:", result_multiple)
At (0,0): 10.0 At multiple points: [10. 1. 0.]
How It Works
The 2D Laguerre polynomial is constructed using the coefficient matrix where c[i,j] represents the coefficient for the term Li(x) × Lj(y). The function evaluates this polynomial at the specified (x,y) coordinates using the Laguerre basis functions.
Conclusion
Use lagval2d() to evaluate 2D Laguerre series at coordinate pairs. The coefficient array structure determines the polynomial terms, and the function efficiently computes values at single or multiple points simultaneously.
