Generate a Pseudo Vandermonde matrix of the Legendre polynomial and x, y complex array of points in Python

To generate a pseudo Vandermonde matrix of the Legendre polynomial, use the legendre.legvander2d() method in Python NumPy. This method returns the pseudo-Vandermonde matrix for two-dimensional Legendre polynomial evaluation.

The pseudo Vandermonde matrix is used for polynomial fitting and interpolation. Each row corresponds to a point coordinate, and each column represents a basis function formed by the product of Legendre polynomials of different degrees.

Syntax

numpy.polynomial.legendre.legvander2d(x, y, deg)

Parameters

x, y ? Arrays of point coordinates with the same shape. Complex numbers are supported.

deg ? List of maximum degrees in the form [x_deg, y_deg].

Return Value

Returns a pseudo-Vandermonde matrix with shape x.shape + (deg[0] + 1) * (deg[1] + 1). The dtype matches the input arrays (float64 or complex128).

Example

import numpy as np
from numpy.polynomial import legendre as L

# Create arrays of complex point coordinates
x = np.array([-2.+2.j, -1.+2.j])
y = np.array([1.+2.j, 2.+2.j])

# Display the arrays
print("Array1...")
print(x)
print("\nArray2...")
print(y)

# Display the datatype
print("\nArray1 datatype:", x.dtype)
print("Array2 datatype:", y.dtype)

# Check dimensions and shape
print("\nDimensions of Array1:", x.ndim)
print("Dimensions of Array2:", y.ndim)
print("\nShape of Array1:", x.shape)
print("Shape of Array2:", y.shape)

# Generate pseudo Vandermonde matrix
x_deg, y_deg = 2, 3
result = L.legvander2d(x, y, [x_deg, y_deg])
print("\nPseudo Vandermonde Matrix:")
print(result)
print("\nMatrix shape:", result.shape)
Array1...
[-2.+2.j -1.+2.j]

Array2...
[1.+2.j 2.+2.j]

Array1 datatype: complex128
Array2 datatype: complex128

Dimensions of Array1: 1
Dimensions of Array2: 1

Shape of Array1: (2,)
Shape of Array2: (2,)

Pseudo Vandermonde Matrix:
[[ 1. +0.j  1. +2.j -5. +6.j -29. -8.j  -2. +2.j  -6. -2.j
  -2.-22.j  74.-42.j -0.5-12.j  23.5-13.j  74.5+57.j -81.5+352.j]
 [ 1. +0.j  2. +2.j -0.5+12.j -43.+37.j  -1. +2.j  -6. +2.j
 -23.5-13.j -31.-123.j -5. -6.j   2. -22.j  74.5-57.j 437. +73.j]]

Matrix shape: (2, 12)

How It Works

The function creates a matrix where each element matrix[i, j] represents the evaluation of a 2D Legendre polynomial basis function at point (x[i], y[i]). The basis functions are formed by products of 1D Legendre polynomials: P_m(x) * P_n(y) where m ? x_deg and n ? y_deg.

Conclusion

The legvander2d() method generates pseudo Vandermonde matrices for 2D Legendre polynomial fitting. It handles complex coordinates and returns a matrix suitable for polynomial interpolation and approximation tasks.

---
Updated on: 2026-03-26T21:06:54+05:30

213 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements