Generate a Vandermonde matrix of the Chebyshev polynomial in Python
Last Updated :
16 Feb, 2023
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.
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 - " , gfg)
print ( "Dimension of Array:-" , gfg.ndim)
print ( "Datatype of Array:-" , gfg.dtype)
print ( "Shape of Array:-" , gfg.shape)
gfg_matrix = chebyshev.chebvander(gfg, 2 )
print ( '\n' , gfg_matrix)
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 - " , gfg)
print ( "Dimension of Array:-" ,gfg.ndim)
print ( "Datatype of Array:-" ,gfg.dtype)
print ( "Shape of Array:-" ,gfg.shape)
gfg_matrix = chebyshev.chebvander(gfg, 5 )
print ( '\n' ,gfg_matrix)
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)
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...