在 Python 中生成勒让德多项式和 x、y、z 浮点数组的伪范德蒙矩阵
要生成具有 x、y、z 采样点的 Legendre 多项式的伪 Vandermonde 矩阵,请使用d()Python Numpy 中的 legendre.legvander3 方法。返回度 deg 和样本点 (x, y, z) 的伪 Vandermonde 矩阵。
参数 x, y ,z 是点坐标数组,都具有相同的形状。dtypes 将转换为 float64 或 complex128,具体取决于任何元素是否复杂。标量被转换为一维数组。参数 deg 是 [x_deg, y_deg, z_deg] 形式的最大度数列表。
脚步
首先,导入所需的库 -
import numpy as npfromnumpy.polynomialimport legendre as L
使用以下方法创建点坐标数组,所有形状都相同-numpy.array()
x = np.array([1.5, 2.3])y = np.array([3.7, 4.4])
z = np.array([5.3, 6.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)
d()要生成具有 x、y、z 样本点的勒让德多项式的伪 Vandermonde 矩阵,请使用Python中的 legendre.legvander3方法 -
x_deg, y_deg, z_deg = 2, 3, 4print("\nResult...\n",L.legvander3d(x,y,z, [x_deg, y_deg, z_deg]))
示例
import numpy as np输出结果fromnumpy.polynomialimport legendre as L
#使用 numpy.array() 方法创建所有相同形状的点坐标数组
x = np.array([1.5, 2.3])
y = np.array([3.7, 4.4])
z = np.array([5.3, 6.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)
#要生成具有 x、y、z 样本点的 Legendre 多项式的伪 Vandermonde 矩阵,请使用 Python Numpy 中的 legendre.legvander3d() 方法
x_deg, y_deg, z_deg = 2, 3, 4
print("\nResult...\n",L.legvander3d(x,y,z, [x_deg, y_deg, z_deg]))
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 4.16350000e+01 3.64242500e+02
3.34712294e+03 3.70000000e+00 1.96100000e+01 1.54049500e+02
1.34769725e+03 1.23843549e+04 2.00350000e+01 1.06185500e+02
8.34157225e+02 7.29759849e+03 6.70596081e+04 1.21082500e+02
6.41737250e+02 5.04126989e+03 4.41033925e+04 4.05278013e+05
1.50000000e+00 7.95000000e+00 6.24525000e+01 5.46363750e+02
5.02068441e+03 5.55000000e+00 2.94150000e+01 2.31074250e+02
2.02154588e+03 1.85765323e+04 3.00525000e+01 1.59278250e+02
1.25123584e+03 1.09463977e+04 1.00589412e+05 1.81623750e+02
9.62605875e+02 7.56190483e+03 6.61550888e+04 6.07917020e+05
2.87500000e+00 1.52375000e+01 1.19700625e+02 1.04719719e+03
9.62297845e+03 1.06375000e+01 5.63787500e+01 4.42892313e+02
3.87462959e+03 3.56050202e+04 5.76006250e+01 3.05283313e+02
2.39820202e+03 2.09805957e+04 1.92796373e+05 3.48112188e+02
1.84499459e+03 1.44936509e+04 1.26797253e+05 1.16517429e+06]
[1.00000000e+00 6.60000000e+00 6.48400000e+01 7.08840000e+02
8.13847200e+03 4.40000000e+00 2.90400000e+01 2.85296000e+02
3.11889600e+03 3.58092768e+04 2.85400000e+01 1.88364000e+02
1.85053360e+03 2.02302936e+04 2.32271991e+05 2.06360000e+02
1.36197600e+03 1.33803824e+04 1.46276222e+05 1.67945508e+06
2.30000000e+00 1.51800000e+01 1.49132000e+02 1.63033200e+03
1.87184856e+04 1.01200000e+01 6.67920000e+01 6.56180800e+02
7.17346080e+03 8.23613366e+04 6.56420000e+01 4.33237200e+02
4.25622728e+03 4.65296753e+04 5.34225579e+05 4.74628000e+02
3.13254480e+03 3.07748795e+04 3.36435312e+05 3.86274669e+06
7.43500000e+00 4.90710000e+01 4.82085400e+02 5.27022540e+03
6.05095393e+04 3.27140000e+01 2.15912400e+02 2.12117576e+03
2.31889918e+04 2.66241973e+05 2.12194900e+02 1.40048634e+03
1.37587173e+04 1.50412233e+05 1.72694225e+06 1.53428660e+03
1.01262916e+04 9.94831431e+04 1.08756371e+06 1.24867485e+07]]
以上是 在 Python 中生成勒让德多项式和 x、y、z 浮点数组的伪范德蒙矩阵 的全部内容, 来源链接: utcz.com/z/297354.html