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 given degree with complex array of points coordinates in Python
To generate a Pseudo-Vandermonde matrix of given degree with complex coordinates, use the polyvander2d() function from NumPy's polynomial module. This function creates a 2D Vandermonde matrix from arrays of point coordinates with specified maximum degrees for each dimension.
Syntax
numpy.polynomial.polynomial.polyvander2d(x, y, deg)
Parameters
x, y: Arrays of point coordinates with the same shape. Complex values are supported.
deg: List of maximum degrees in the form [x_deg, y_deg].
Example
Let's create a Pseudo-Vandermonde matrix using complex coordinate arrays ?
import numpy as np
from numpy.polynomial.polynomial import polyvander2d
# Create arrays of complex point coordinates
x = np.array([-2.+2.j, -1.+2.j])
y = np.array([1.+2.j, 2.+2.j])
print("X coordinates:", x)
print("Y coordinates:", y)
print("Data type:", x.dtype)
print("Shape:", x.shape)
# Generate Pseudo-Vandermonde matrix with degrees [2, 3]
x_deg, y_deg = 2, 3
result = polyvander2d(x, y, [x_deg, y_deg])
print("\nPseudo-Vandermonde matrix:")
print(result)
X coordinates: [-2.+2.j -1.+2.j] Y coordinates: [1.+2.j 2.+2.j] Data type: complex128 Shape: (2,) Pseudo-Vandermonde matrix: [[ 1. +0.j 1. +2.j -3. +4.j -11. -2.j -2. +2.j -6. -2.j -2.-14.j 26.-18.j 0. -8.j 16. -8.j 32.+24.j -16.+88.j] [ 1. +0.j 2. +2.j 0. +8.j -16.+16.j -1. +2.j -6. +2.j -16. -8.j -16.-48.j -3. -4.j 2.-14.j 32.-24.j 112.+16.j]]
How It Works
The matrix contains all polynomial combinations up to the specified degrees:
- Each row corresponds to a point (x[i], y[i])
- Columns represent terms like x^i * y^j where i ? x_deg and j ? y_deg
- For degrees [2,3], we get (2+1) × (3+1) = 12 columns
- Complex arithmetic is handled automatically
Matrix Structure
For degrees [2,3], the columns represent these polynomial terms:
# Columns: 1, y, y², y³, x, xy, xy², xy³, x², x²y, x²y², x²y³
Conclusion
The polyvander2d() function efficiently generates Pseudo-Vandermonde matrices for complex coordinates. This is useful for polynomial fitting and interpolation in 2D with complex data points.
