在Python中生成Chebyshev多项式和x,y,z样本点的伪Vandermonde矩阵
要生成Chebyshev多项式和x,y,z样本点的伪Vandermonde矩阵,在Python的Numpy中使用chebyshev.chebvander()方法。该方法返回度数为deg且包含样本点(x,y,z)的伪Vandermonde矩阵。
参数x,y,z是具有相同形状的点坐标数组。根据元素是否为复数,其数据类型将转换为float64或complex128。标量将被转换为1-D数组。参数deg是形式为[x_deg,y_deg,z_deg]
的最大度列表。
步骤
首先,导入所需库-
import numpy as np
from numpy.polynomial import chebyshev as C
使用numpy.array()方法创建具有相同形状的点坐标数组:
x = np.array([1, 2])
y = np.array([3, 4])
z = np.array([5, 6])
显示数组 –
print("Array1...\n",x)
print("\nArray2...\n",y)
print("\nArray3...\n",z)
显示数据类型 –
print("\nArray1 datatype...\n",x.dtype)
print("\nArray2 datatype...\n",y.dtype)
print("\nArray3 datatype...\n",z.dtype)
检查两个数组的尺寸 –
print("\nDimensions of Array1...\n",x.ndim)
print("\nDimensions of Array2...\n",y.ndim)
print("\nDimensions of Array3...\n",z.ndim)
检查两个数组的形状 –
print("\nShape of Array1...\n",x.shape)
print("\nShape of Array2...\n",y.shape)
print("\nShape of Array3...\n",z.shape)
使用Python中的chebyshev.chebvander()函数来生成切比雪夫多项式和x、y、z样本点的伪Vandermonde矩阵 –
x_deg, y_deg, z_deg = 2, 3, 4
print("\nResult...\n",C.chebvander3d(x,y, z, [x_deg, y_deg, z_deg]))
示例
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, 2])
y = np.array([3, 4])
z = np.array([5, 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
# The method returns the pseudo-Vandermonde matrix of degrees deg and sample points (x, y, z).
x_deg, y_deg, z_deg = 2, 3, 4
print("\nResult...\n",C.chebvander3d(x,y, z, [x_deg, y_deg, z_deg]))
输出
Array1...
[1 2]
Array2...
[3 4]
Array3...
[5 6]
Array1 datatype...
int64
Array2 datatype...
int64
Array3 datatype...
int64
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.0000000e+00 5.0000000e+00 4.9000000e+01 4.8500000e+02 4.8010000e+03
3.0000000e+00 1.5000000e+01 1.4700000e+02 1.4550000e+03 1.4403000e+04
1.7000000e+01 8.5000000e+01 8.3300000e+02 8.2450000e+03 8.1617000e+04
9.9000000e+01 4.9500000e+02 4.8510000e+03 4.8015000e+04 4.7529900e+05
1.0000000e+00 5.0000000e+00 4.9000000e+01 4.8500000e+02 4.8010000e+03
3.0000000e+00 1.5000000e+01 1.4700000e+02 1.4550000e+03 1.4403000e+04
1.7000000e+01 8.5000000e+01 8.3300000e+02 8.2450000e+03 8.1617000e+04
9.9000000e+01 4.9500000e+02 4.8510000e+03 4.8015000e+04 4.7529900e+05
1.0000000e+00 5.0000000e+00 4.9000000e+01 4.8500000e+02 4.8010000e+03
3.0000000e+00 1.5000000e+01 1.4700000e+02 1.4550000e+03 1.4403000e+04
1.7000000e+01 8.5000000e+01 8.3300000e+02 8.2450000e+03 8.1617000e+04
9.9000000e+01 4.9500000e+02 4.8510000e+03 4.8015000e+04 4.7529900e+05]
[1.0000000e+00 6.0000000e+00 7.1000000e+01 8.4600000e+02 1.0081000e+04
4.0000000e+00 2.4000000e+01 2.8400000e+02 3.3840000e+03 4.0324000e+04
3.1000000e+01 1.8600000e+02 2.2010000e+03 2.6226000e+04 3.1251100e+05
2.4400000e+02 1.4640000e+03 1.7324000e+04 2.0642400e+05 2.4597640e+06
2.0000000e+00 1.2000000e+01 1.4200000e+02 1.6920000e+03 2.0162000e+04
8.0000000e+00 4.8000000e+01 5.6800000e+02 6.7680000e+03 8.0648000e+04
6.2000000e+01 3.7200000e+02 4.4020000e+03 5.2452000e+04 6.2502200e+05
4.8800000e+02 2.9280000e+03 3.4648000e+04 4.1284800e+05 4.9195280e+06
7.0000000e+00 4.2000000e+01 4.9700000e+02 5.9220000e+03 7.0567000e+04
2.8000000e+01 1.6800000e+02 1.9880000e+03 2.3688000e+04 2.8226800e+05
2.1700000e+02 1.3020000e+03 1.5407000e+04 1.8358200e+05 2.1875770e+06
1.7080000e+03 1.0248000e+04 1.2126800e+05 1.4449680e+06 1.7218348e+07]]