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 Vandermonde matrix of the Chebyshev polynomial with complex array of points in Python
To generate a Vandermonde matrix of the Chebyshev polynomial with complex points, use the chebyshev.chebvander() function in Python NumPy. This function returns a Vandermonde matrix where each column represents a Chebyshev polynomial of increasing degree evaluated at the given points.
Syntax
numpy.polynomial.chebyshev.chebvander(x, deg)
Parameters
The function accepts the following parameters:
- x: Array of points (can be complex). The dtype is converted to float64 or complex128 depending on whether any elements are complex
-
deg: Degree of the resulting matrix. The returned matrix will have
deg + 1columns
Return Value
Returns a Vandermonde matrix with shape x.shape + (deg + 1,), where the last index corresponds to the degree of the Chebyshev polynomial.
Example
Let's create a Vandermonde matrix using complex array points:
import numpy as np
from numpy.polynomial import chebyshev as C
# Create an array of complex points
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 properties
print("\nDimensions of our Array...\n", x.ndim)
print("\nDatatype of our Array object...\n", x.dtype)
print("\nShape of our Array object...\n", x.shape)
# Generate Vandermonde matrix of degree 2
result = C.chebvander(x, 2)
print("\nVandermonde Matrix...\n", result)
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... [[ 1. +0.j -2. +2.j -1.-16.j] [ 1. +0.j -1. +2.j -7. -8.j] [ 1. +0.j 0. +2.j -9. +0.j] [ 1. +0.j 1. +2.j -7. +8.j] [ 1. +0.j 2. +2.j -1.+16.j]]
How It Works
The Vandermonde matrix contains:
- Column 0: T?(x) = 1 (all ones)
- Column 1: T?(x) = x (the input points)
- Column 2: T?(x) = 2x² - 1 (second-degree Chebyshev polynomial)
Each row represents the evaluation of all Chebyshev polynomials up to the specified degree at each point in the input array.
Conclusion
The chebvander() function efficiently generates Vandermonde matrices for Chebyshev polynomials with complex points. The resulting matrix has dimensions based on the input array shape plus the polynomial degree, making it useful for polynomial fitting and interpolation tasks.
