Thursday, September 4, 2025
HomeLanguagesGenerate a Vandermonde matrix of the Chebyshev polynomial in Python

Generate a Vandermonde matrix of the Chebyshev polynomial in Python

In this article, we will be looking at the approach using various functionalities of the Numpy packages to generate a Vandermonde matrix of the Chebyshev polynomial in Python.

NumPy.chebvander method

To generate a Vandermonde matrix of the Chebyshev polynomial, the user needs to call the np.chebvander() from the NumPy package in Python Numpy. And further, passing an array of integers to the function will return the Vandermonde matrix. The shape of the returned matrix is x.shape + (deg + 1), where the last index is the degree of the corresponding Chebyshev polynomial.

Syntax: np.chebvander(x, deg)

Parameters:

  • x: Array of points. 
  • deg: Degree of the resulting matrix.

Return: Return the matrix having size.

Example 1:

In this example, we have created the array containing 10 data points from series 1 to 10 and with the use of the np.chebvander() function, we will pass the degree to be 2.

Python3




import numpy as np
from numpy.polynomial import chebyshev
 
gfg = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
 
# Print array
print("Array - ", gfg)
 
# Print dimension of the array
print("Dimension of Array:-", gfg.ndim)
 
# Print Datatype array
print("Datatype of Array:-", gfg.dtype)
 
# Print shape array
print("Shape of Array:-", gfg.shape)
 
# Generate a Vandermonde matrix of the
# Chebyshev polynomial of degree 2
gfg_matrix = chebyshev.chebvander(gfg, 2)
print('\n', gfg_matrix)
 
# Print shape martrix
print("\nShape of Martix:-\n", gfg_matrix.shape)


Output:

Array -  [ 1  2  3  4  5  6  7  8  9 10]
Dimension of Array:- 1
Datatype of Array:- int64
Shape of Array:- (10,)

 [[  1.   1.   1.]
 [  1.   2.   7.]
 [  1.   3.  17.]
 [  1.   4.  31.]
 [  1.   5.  49.]
 [  1.   6.  71.]
 [  1.   7.  97.]
 [  1.   8. 127.]
 [  1.   9. 161.]
 [  1.  10. 199.]]

Shape of Matrix:-
 (10, 3)

Example 2:

In this example, we have created the array containing 5 data points and with the use of the np.chebvander() function passing the degree to be 5, and at last, we will check the shape of the generated matrix in the python.

Python3




import numpy as np
from numpy.polynomial import chebyshev
 
gfg = np.array([59,89,45,71,56])
 
# Print array
print("Array - ", gfg)
 
# Print dimension of the array
print("Dimension of Array:-",gfg.ndim)
 
# Print Datatype array
print("Datatype of Array:-",gfg.dtype)
 
# Print shape array
print("Shape of Array:-",gfg.shape)
 
# Generate a Vandermonde matrix of the
# Chebyshev polynomial of degree 5
gfg_matrix=chebyshev.chebvander(gfg, 5)
print('\n',gfg_matrix)
 
# Print shape martrix
print("\nShape of Martix:-\n",gfg_matrix.shape)


Output:

Array –  [59 89 45 71 56]

Dimension of Array:- 1

Datatype of Array:- int64

Shape of Array:- (5,)

 [[1.00000000e+00 5.90000000e+01 6.96100000e+03 8.21339000e+05

  9.69110410e+07 1.14346815e+10]

 [1.00000000e+00 8.90000000e+01 1.58410000e+04 2.81960900e+06

  5.01874561e+08 8.93308522e+10]

 [1.00000000e+00 4.50000000e+01 4.04900000e+03 3.64365000e+05

  3.27888010e+07 2.95062772e+09]

 [1.00000000e+00 7.10000000e+01 1.00810000e+04 1.43143100e+06

  2.03253121e+08 2.88605118e+10]

 [1.00000000e+00 5.60000000e+01 6.27100000e+03 7.02296000e+05

  7.86508810e+07 8.80819638e+09]]

Shape of Martix:-

 (5, 6)

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32263 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6626 POSTS0 COMMENTS
Nicole Veronica
11799 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11857 POSTS0 COMMENTS
Shaida Kate Naidoo
6749 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6696 POSTS0 COMMENTS
Umr Jansen
6716 POSTS0 COMMENTS