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
Generate a Pseudo Vandermonde matrix of the Laguerre polynomial and x, y array of points in Python
To generate a pseudo Vandermonde matrix of the Laguerre polynomial, use the laguerre.lagvander2d() in Python NumPy. The method returns the pseudo-Vandermonde matrix where each element corresponds to the evaluation of Laguerre polynomials at given points.
The parameter x, y are arrays of points with the same shape. The dtype is converted to float64 or complex128 depending on whether any elements are complex. The parameter deg is a list of maximum degrees of the form [x_deg, y_deg].
Syntax
numpy.polynomial.laguerre.lagvander2d(x, y, deg)
Example
Let's create a pseudo Vandermonde matrix using coordinate points and specified polynomial degrees ?
import numpy as np
from numpy.polynomial import laguerre as L
# Create arrays of point coordinates
x = np.array([1, 2])
y = np.array([3, 4])
# Display the arrays
print("Array1...\n", x)
print("\nArray2...\n", y)
# Display the datatype
print("\nArray1 datatype...\n", x.dtype)
print("\nArray2 datatype...\n", y.dtype)
# Check the dimensions of both arrays
print("\nDimensions of Array1...\n", x.ndim)
print("\nDimensions of Array2...\n", y.ndim)
# Check the shape of both arrays
print("\nShape of Array1...\n", x.shape)
print("\nShape of Array2...\n", y.shape)
# Generate pseudo Vandermonde matrix of Laguerre polynomial
x_deg, y_deg = 2, 3
result = L.lagvander2d(x, y, [x_deg, y_deg])
print("\nResult...\n", result)
Array1... [1 2] Array2... [3 4] Array1 datatype... int64 Array2 datatype... int64 Dimensions of Array1... 1 Dimensions of Array2... 1 Shape of Array1... (2,) Shape of Array2... (2,) Result... [[ 1. -2. -0.5 1. 0. -0. -0. 0. -0.5 1. 0.25 -0.5 ] [ 1. -3. 1. 2.33333333 -1. 3. -1. -2.33333333 -1. 3. -1. -2.33333333]]
Understanding the Matrix Structure
The returned matrix has shape x.shape + (deg[0] + 1) * (deg[1] + 1). For degrees [2, 3], we get (2 + 1) * (3 + 1) = 12 columns, representing all combinations of Laguerre polynomial terms.
import numpy as np
from numpy.polynomial import laguerre as L
x = np.array([0.5, 1.5])
y = np.array([1.0, 2.0])
# Generate matrix with different degrees
matrix = L.lagvander2d(x, y, [1, 2])
print("Matrix shape:", matrix.shape)
print("Matrix:\n", matrix)
Matrix shape: (2, 6) Matrix: [[ 1. 0. -0.5 0.5 0. -0.25] [ 1. -0.5 -0.5 1.5 -0.75 -0.75]]
Key Points
- The matrix contains evaluations of 2D Laguerre polynomials at coordinate pairs (x[i], y[i])
- Each row corresponds to one point pair
- Columns represent different polynomial degree combinations
- The dtype matches the input arrays (converted to float64 for real inputs)
Conclusion
The lagvander2d() function generates pseudo Vandermonde matrices for 2D Laguerre polynomials, useful in polynomial fitting and numerical analysis. The matrix structure depends on the specified degrees and input point coordinates.
