Generate a pseudo Vandermonde matrix of Chebyshev polynomial and x, y, z floating array of points in Python


To generate a pseudo Vandermonde matrix of the Chebyshev polynomial and x, y, z sample points, use the chebyshev.chebvander() in Python Numpy. The method returns the pseudo-Vandermonde matrix of degrees deg and sample points (x, y, z). 

The parameter, x, y, z are the arrays of point coordinates, all of the same shape. The dtypes will be converted to either float64 or complex128 depending on whether any of the elements are complex. Scalars are converted to 1-D arrays. The parameter, deg is the list of maximum degrees of the form [x_deg, y_deg, z_deg].

Steps

At first, import the required library −

import numpy as np
from numpy.polynomial import chebyshev as C

Create arrays of point coordinates, all of the same shape using the numpy.array() method −

x = np.array([1.5, 2.3])
y = np.array([3.7, 4.4])
z = np.array([5.3, 6.6])

Display the arrays −

print("Array1...\n",x)
print("\nArray2...\n",y)
print("\nArray3...\n",z)

Display the datatype −

print("\nArray1 datatype...\n",x.dtype)
print("\nArray2 datatype...\n",y.dtype)
print("\nArray3 datatype...\n",z.dtype)

Check the Dimensions of both the arrays −

print("\nDimensions of Array1...\n",x.ndim)
print("\nDimensions of Array2...\n",y.ndim)
print("\nDimensions of Array3...\n",z.ndim)

Check the Shape of both the arrays −

print("\nShape of Array1...\n",x.shape)
print("\nShape of Array2...\n",y.shape)
print("\nShape of Array3...\n",z.shape)

To generate a pseudo Vandermonde matrix of the Chebyshev polynomial and x, y, z sample points, use the chebyshev.chebvander() −

x_deg, y_deg, z_deg = 2, 3, 4
print("\nResult...\n",C.chebvander3d(x,y, z, [x_deg, y_deg, z_deg]))

Example

import numpy as np
from numpy.polynomial import chebyshev as C

# Create arrays of point coordinates, all of the same shape using the numpy.array() method
x = np.array([1.5, 2.3])
y = np.array([3.7, 4.4])
z = np.array([5.3, 6.6])

# Display the arrays
print("Array1...\n",x)
print("\nArray2...\n",y)
print("\nArray3...\n",z)

# Display the datatype
print("\nArray1 datatype...\n",x.dtype)
print("\nArray2 datatype...\n",y.dtype)
print("\nArray3 datatype...\n",z.dtype)

# Check the Dimensions of both the arrays
print("\nDimensions of Array1...\n",x.ndim)
print("\nDimensions of Array2...\n",y.ndim)
print("\nDimensions of Array3...\n",z.ndim)

# Check the Shape of both the arrays
print("\nShape of Array1...\n",x.shape)
print("\nShape of Array2...\n",y.shape)
print("\nShape of Array3...\n",z.shape)

# To generate a pseudo Vandermonde matrix of the Chebyshev polynomial and x, y, z sample points, use the chebyshev.chebvander() in Python Numpy
x_deg, y_deg, z_deg = 2, 3, 4
print("\nResult...\n",C.chebvander3d(x,y, z, [x_deg, y_deg, z_deg]))

Output

Array1...
[1.5 2.3]

Array2...
[3.7 4.4]

Array3...
[5.3 6.6]

Array1 datatype...
float64

Array2 datatype...
float64

Array3 datatype...
float64

Dimensions of Array1...
1

Dimensions of Array2...
1

Dimensions of Array3...
1

Shape of Array1...
(2,)

Shape of Array2...
(2,)

Shape of Array3...
(2,)

Result...
[[1.00000000e+00 5.30000000e+00 5.51800000e+01 5.79608000e+02
6.08866480e+03 3.70000000e+00 1.96100000e+01 2.04166000e+02
2.14454960e+03 2.25280598e+04 2.63800000e+01 1.39814000e+02
1.45564840e+03 1.52900590e+04 1.60618977e+05 1.91512000e+02
1.01501360e+03 1.05676322e+04 1.11001887e+05 1.16605237e+06
1.50000000e+00 7.95000000e+00 8.27700000e+01 8.69412000e+02
9.13299720e+03 5.55000000e+00 2.94150000e+01 3.06249000e+02
3.21682440e+03 3.37920896e+04 3.95700000e+01 2.09721000e+02
2.18347260e+03 2.29350886e+04 2.40928466e+05 2.87268000e+02
1.52252040e+03 1.58514482e+04 1.66502831e+05 1.74907856e+06
3.50000000e+00 1.85500000e+01 1.93130000e+02 2.02862800e+03
2.13103268e+04 1.29500000e+01 6.86350000e+01 7.14581000e+02
7.50592360e+03 7.88482092e+04 9.23300000e+01 4.89349000e+02
5.09476940e+03 5.35152066e+04 5.62166421e+05 6.70292000e+02
3.55254760e+03 3.69867126e+04 3.88506606e+05 4.08118331e+06]
[1.00000000e+00 6.60000000e+00 8.61200000e+01 1.13018400e+03
1.48323088e+04 4.40000000e+00 2.90400000e+01 3.78928000e+02
4.97280960e+03 6.52621587e+04 3.77200000e+01 2.48952000e+02
3.24844640e+03 4.26305405e+04 5.59474688e+05 3.27536000e+02
2.16173760e+03 2.82074003e+04 3.70175947e+05 4.85811510e+06
2.30000000e+00 1.51800000e+01 1.98076000e+02 2.59942320e+03
3.41143102e+04 1.01200000e+01 6.67920000e+01 8.71534400e+02
1.14374621e+04 1.50102965e+05 8.67560000e+01 5.72589600e+02
7.47142672e+03 9.80502431e+04 1.28679178e+06 7.53332800e+02
4.97199648e+03 6.48770207e+04 8.51404677e+05 1.11736647e+07
9.58000000e+00 6.32280000e+01 8.25029600e+02 1.08271627e+04
1.42093518e+05 4.21520000e+01 2.78203200e+02 3.63013024e+03
4.76395160e+04 6.25211481e+05 3.61357600e+02 2.38496016e+03
3.11201165e+04 4.08400578e+05 5.35976751e+06 3.13779488e+03
2.07094462e+04 2.70226895e+05 3.54628557e+06 4.65407426e+07]]

Updated on: 28-Feb-2022

71 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements