Generate a Pseudo Vandermonde matrix of the Chebyshev and Legendre polynomial in Python
In this article, we will generate a Pseudo Vandermonde matrix of the Chebyshev and Legendre polynomial x, y, and z floating array of points in Python.
Example 1
Generating a Pseudo Vandermonde matrix of Legendre..legvander3d() function
We use the legendre.legvander3d() method present in the Numpy module of python to produce a Vandermonde matrix of the Legendre polynomial with x, y, and z as the sample points. The pseudo-Vandermonde matrices of degrees ‘deg’ and sample points (x, y, z) is returned as a result. The x, y, and z parameters are all arrays of point coordinates with a similar shape. Depending on whether any of the elements are complex, the dtypes will be changed to float64 or complex128. If any scalar is present then it will be converted to a one-dimensional array. ‘deg’ parameter is a list of maximum degrees mentioned in the form of [x deg, y deg, z deg].
Syntax : legendre.legvander3d(x, y, z, deg)
Parameter:
- x,y,z = These are the arrays of the same-shaped point coordinates.
- deg = It is the list of maximum degrees of the form [x_deg, y_deg, z_deg].
Return : It returns a Vandermonde matrix.
Python3
# import numpy and legendre libraries import numpy as np from numpy.polynomial import legendre # Create arrays of point coordinates x, y and z x = np.array([ 2.4 , 1.2 ]) y = np.array([ 7.1 , 2.7 ]) z = np.array([ 3.4 , 2.2 ]) # Assign degrees to x, y and z deg_of_x = 3 deg_of_y = 1 deg_of_z = 2 # use chebvander3d() function to generate a # pseudo Vandermonde matrix of the # Chebyshev polynomial and x, y, z sample points print (legendre.legvander3d(x, y, z, [deg_of_x, deg_of_y, deg_of_z])) |
Output :
[[1.00000000e+00 3.40000000e+00 1.68400000e+01 7.10000000e+00
2.41400000e+01 1.19564000e+02 2.40000000e+00 8.16000000e+00
4.04160000e+01 1.70400000e+01 5.79360000e+01 2.86953600e+02
8.14000000e+00 2.76760000e+01 1.37077600e+02 5.77940000e+01
1.96499600e+02 9.73250960e+02 3.09600000e+01 1.05264000e+02
5.21366400e+02 2.19816000e+02 7.47374400e+02 3.70170144e+03]
[1.00000000e+00 2.20000000e+00 6.76000000e+00 2.70000000e+00
5.94000000e+00 1.82520000e+01 1.20000000e+00 2.64000000e+00
8.11200000e+00 3.24000000e+00 7.12800000e+00 2.19024000e+01
1.66000000e+00 3.65200000e+00 1.12216000e+01 4.48200000e+00
9.86040000e+00 3.02983200e+01 2.52000000e+00 5.54400000e+00
1.70352000e+01 6.80400000e+00 1.49688000e+01 4.59950400e+01]]
Example 2:
Generating a Pseudo Vandermonde matrix of the Chebyshev.chebvander() function
We use the chebyshev.chebvander() function present in the Numpy module of python to construct a pseudo Vandermonde matrix of the Chebyshev polynomial and x, y, and z as the sample points. The pseudo-Vandermonde matrix of degrees ‘deg’ and sample points (x, y, z) is returned by this function.
The x, y, and z parameters are all arrays of point coordinates with the same shape. Depending on whether any of the elements are complex, the dtypes will be changed to float64 or complex128. If any scalar is present then it will be converted to a one-dimensional array. Also, the ‘deg’ parameter is a list of maximum degrees with the format [x deg, y deg, z deg].
Syntax : chebyshev.chebvander(x, y, z, [deg_of_x, deg_of_y, deg_of_z])
Parameter:
- x,y,z = These are the arrays of the same-shaped point coordinates.
- deg = It is the list of maximum degrees of the form [x_deg, y_deg, z_deg].
Return : It returns ‘vander3d’ which is an ndarray.
Python3
# import numpy and chebyshev libraries import numpy as np from numpy.polynomial import chebyshev as C # Create arrays of point coordinates x, y and z x = [ 1.2 , 2.1 ] y = [ 2.3 , 3.2 ] z = [ 3.1 , 1.3 ] # Assign degrees to x, y and z deg_of_x = 2 deg_of_y = 1 deg_of_z = 3 # use chebvander3d() function to generate a # pseudo Vandermonde matrix of the # Chebyshev polynomial and x, y, z sample points print (C.chebvander3d(x, y, z, [deg_of_x, deg_of_y, deg_of_z])) |
Output :
[[ 1. 3.1 18.22 109.864 2.3 7.13
41.906 252.6872 1.2 3.72 21.864 131.8368
2.76 8.556 50.2872 303.22464 1.88 5.828
34.2536 206.54432 4.324 13.4044 78.78328 475.051936]
[ 1. 1.3 2.38 4.888 3.2 4.16
7.616 15.6416 2.1 2.73 4.998 10.2648
6.72 8.736 15.9936 32.84736 7.82 10.166
18.6116 38.22416 25.024 32.5312 59.55712 122.317312]]
Please Login to comment...