Generate a Vandermonde matrix of the Legendre polynomial with complex array of points in Python

To generate a pseudo Vandermonde matrix of the Legendre polynomial with complex points, use the polynomial.legvander() method in NumPy. This method returns a matrix where each row represents the evaluation of Legendre polynomials at a given point, with columns corresponding to different polynomial degrees.

The returned matrix has shape x.shape + (deg + 1,), where the last index represents the degree of the corresponding Legendre polynomial. The data type matches the input array after conversion to float64 or complex128.

Syntax

numpy.polynomial.legendre.legvander(x, deg)

Parameters

  • x ? Array of points. Scalar values are converted to 1-D arrays
  • deg ? Degree of the resulting matrix (non-negative integer)

Example

Here's how to generate a Vandermonde matrix using complex array points ?

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

# Create a complex array
x = np.array([-2.+2.j, -1.+2.j, 0.+2.j, 1.+2.j, 2.+2.j])

# Display the array
print("Our Array...")
print(x)

# Check array properties
print("\nDimensions:", x.ndim)
print("Datatype:", x.dtype)
print("Shape:", x.shape)

# Generate Vandermonde matrix with degree 2
result = L.legvander(x, 2)
print("\nVandermonde Matrix:")
print(result)
Our Array...
[-2.+2.j -1.+2.j  0.+2.j  1.+2.j  2.+2.j]

Dimensions: 1
Datatype: complex128
Shape: (5,)

Vandermonde Matrix:
[[ 1. +0.j -2. +2.j -0.5-12.j]
 [ 1. +0.j -1. +2.j -5. -6.j]
 [ 1. +0.j  0. +2.j -6.5 +0.j]
 [ 1. +0.j  1. +2.j -5. +6.j]
 [ 1. +0.j  2. +2.j -0.5+12.j]]

How It Works

The Vandermonde matrix contains evaluations of Legendre polynomials at each point:

  • Column 0: L?(x) = 1 (constant polynomial)
  • Column 1: L?(x) = x (linear polynomial)
  • Column 2: L?(x) = ½(3x² ? 1) (quadratic polynomial)

Each row corresponds to a point in the input array, showing how that point evaluates under different Legendre polynomial degrees.

Conclusion

The legvander() method efficiently generates Vandermonde matrices for Legendre polynomials with complex arrays. This is particularly useful in numerical analysis and polynomial fitting applications involving complex numbers.

Updated on: 2026-03-26T21:04:45+05:30

239 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements