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 float array of points in Python
To generate a Vandermonde matrix of the Chebyshev polynomial, use numpy.polynomial.chebyshev.chebvander(). This function returns a Vandermonde matrix where each column represents a different degree of the Chebyshev polynomial evaluated at the input points.
Syntax
numpy.polynomial.chebyshev.chebvander(x, deg)
Parameters
The function accepts the following 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 is converted to a 1-D array.
- deg: Degree of the resulting matrix. This determines the number of Chebyshev polynomial terms to include.
Return Value
Returns a Vandermonde matrix with shape x.shape + (deg + 1,), where the last index corresponds to the degree of the Chebyshev polynomial. The dtype matches the converted input array.
Example
Let's create a Vandermonde matrix for Chebyshev polynomials up to degree 2:
import numpy as np
from numpy.polynomial import chebyshev as C
# Create an array of points
x = np.array([0, 3.5, -1.4, 2.5])
# 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 of degree 2
result = C.chebvander(x, 2)
print("\nVandermonde Matrix:")
print(result)
Our Array: [ 0. 3.5 -1.4 2.5] Dimensions: 1 Datatype: float64 Shape: (4,) Vandermonde Matrix: [[ 1. 0. -1. ] [ 1. 3.5 23.5 ] [ 1. -1.4 2.92] [ 1. 2.5 11.5 ]]
How It Works
Each row in the matrix corresponds to one input point, and each column represents a Chebyshev polynomial of increasing degree:
- Column 0: T?(x) = 1 (always 1 for all points)
- Column 1: T?(x) = x (the input values themselves)
- Column 2: T?(x) = 2x² - 1 (second-degree Chebyshev polynomial)
Higher Degree Example
Here's an example with degree 3 to show more polynomial terms:
import numpy as np
from numpy.polynomial import chebyshev as C
# Create points and generate degree 3 Vandermonde matrix
x = np.array([0, 1, -1])
result = C.chebvander(x, 3)
print("Points:", x)
print("\nVandermonde Matrix (degree 3):")
print(result)
Points: [ 0 1 -1] Vandermonde Matrix (degree 3): [[ 1. 0. -1. 0.] [ 1. 1. 1. 1.] [ 1. -1. 1. -1.]]
Conclusion
The chebvander() function creates a Vandermonde matrix for Chebyshev polynomials, useful in polynomial fitting and numerical analysis. Each column represents a different degree polynomial evaluated at the input points.
