Generate a Vandermonde matrix of given degree with complex array of points in Python

To generate a Vandermonde matrix of given degree with complex array points, use the numpy.polynomial.polynomial.polyvander() function. This method returns a Vandermonde matrix where each column represents successive powers of the input array elements.

The polyvander() function takes an array of points and a degree parameter. The shape of the returned matrix is x.shape + (deg + 1,), where the last index represents the power of x. The dtype will be the same as the converted input array.

Syntax

numpy.polynomial.polynomial.polyvander(x, deg)

Parameters

x: Array of points. The dtype is converted to float64 or complex128 depending on whether any elements are complex. If x is scalar, it's converted to a 1-D array.

deg: Degree of the resulting matrix. This determines the number of columns in the output matrix.

Example

Let's create a Vandermonde matrix using complex array points ?

import numpy as np
from numpy.polynomial.polynomial import polyvander

# 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...\n", x)

# Check the dimensions
print("\nDimensions of our Array...\n", x.ndim)

# Get the datatype
print("\nDatatype of our Array object...\n", x.dtype)

# Get the shape
print("\nShape of our Array object...\n", x.shape)

# Generate Vandermonde matrix of degree 2
print("\nVandermonde Matrix (degree 2)...\n", polyvander(x, 2))
Our Array...
[-2.+2.j -1.+2.j  0.+2.j  1.+2.j  2.+2.j]

Dimensions of our Array...
1

Datatype of our Array object...
complex128

Shape of our Array object...
(5,)

Vandermonde Matrix (degree 2)...
[[ 1.+0.j -2.+2.j  0.-8.j]
 [ 1.+0.j -1.+2.j -3.-4.j]
 [ 1.+0.j  0.+2.j -4.+0.j]
 [ 1.+0.j  1.+2.j -3.+4.j]
 [ 1.+0.j  2.+2.j  0.+8.j]]

Understanding the Matrix Structure

In the Vandermonde matrix, each row corresponds to one input point, and each column represents increasing powers ?

import numpy as np
from numpy.polynomial.polynomial import polyvander

# Example with different degrees
x = np.array([1.+1.j, 2.+1.j])

print("Degree 1:")
print(polyvander(x, 1))

print("\nDegree 3:")
print(polyvander(x, 3))
Degree 1:
[[1.+0.j 1.+1.j]
 [1.+0.j 2.+1.j]]

Degree 3:
[[1.+0.j 1.+1.j 0.+2.j -2.+2.j]
 [1.+0.j 2.+1.j 3.+4.j 2.+11.j]]

How It Works

For a complex number z = a + bj and degree n, the Vandermonde matrix contains columns: [1, z, z², z³, ..., z?]. Each power is computed using complex arithmetic rules.

Conclusion

Use polyvander() to generate Vandermonde matrices with complex arrays. The function automatically handles complex arithmetic and returns a matrix where each column represents successive powers of the input points.

Updated on: 2026-03-26T19:39:21+05:30

239 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements