在Python中生成Laguerre多项式和x、y、z复数数组的伪Vandermonde矩阵
要使用Python NumPy中的laguerre.lagvander3d()生成带有x、y、z样本点的Laguerre多项式的伪Vandermonde矩阵。参数x、y、z返回一个数组点,数据类型根据元素是否为复数来转换为float64或complex128。如果x是标量,它会被转换为1-D数组。参数deg是形式为[x_deg, y_deg, z_deg]的最大度数的列表。
步骤
首先,导入所需的库−
import numpy as np
from numpy.polynomial import laguerre as L
使用numpy.array()方法创建具有相同形状的点坐标数组-“-
x = np.array([-2.+2.j, -1.+2.j])
y = np.array([0.+2.j, 1.+2.j])
z = np.array([2.+2.j, 3. + 3.j])
显示数组 –
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 Numpy中的laguerre.lagvander3d()函数,可生成拉盖尔多项式的伪Vandermonde矩阵,其中使用了x,y,z样本点。
x_deg, y_deg, z_deg = 2, 3, 4
print("\nResult...\n",L.lagvander3d(x,y,z, [x_deg, y_deg, z_deg]))
示例
import numpy as np
from numpy.polynomial import laguerre as L
# Create arrays of point coordinates, all of the same shape using the numpy.array() method
x = np.array([-2.+2.j, -1.+2.j])
y = np.array([0.+2.j, 1.+2.j])
z = np.array([2.+2.j, 3. + 3.j])
# 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 Laguerre polynomial with x, y, z sample points, use the laguerre.lagvander3d() in Python Numpy
x_deg, y_deg, z_deg = 2, 3, 4
print("\nResult...\n",L.lagvander3d(x,y,z, [x_deg, y_deg, z_deg]))
输出
Array1...
[-2.+2.j -1.+2.j]
Array2...
[0.+2.j 1.+2.j]
Array3...
[2.+2.j 3.+3.j]
Array1 datatype...
complex128
Array2 datatype...
complex128
Array3 datatype...
complex128
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. +0.j -1. -2.j
-3. +0.j -2.33333333 +3.33333333j
1. +5.33333333j 1. -2.j
-5. +0.j -3. +6.j
4.33333333 +8.j 11.66666667 +3.33333333j
-1. -4.j -7. +6.j
3. +12.j 15.66666667 +6.j
20.33333333 -9.33333333j -5. -4.66666667j
-4.33333333 +14.66666667j 15. +14.j
27.22222222 -5.77777778j 19.88888889 -31.33333333j
3. -2.j -7. -4.j
-9. +6.j -0.33333333 +14.66666667j
13.66666667 +14.j -1. -8.j
-15. +10.j 3. +24.j
29. +15.33333333j 41.66666667 -13.33333333j
-11. -10.j -9. +32.j
33. +30.j 59. -13.33333333j
42.33333333 -68.66666667j -24.33333333 -4.j
16.33333333 +52.66666667j 73. +12.j
70.11111111 -71.77777778j -3. -133.77777778j
5. -8.j -21. -2.j
-15. +24.j 15. +35.33333333j
47.66666667 +18.66666667j -11. -18.j
-25. +40.j 33. +54.j
85.66666667 +5.33333333j 85. -76.66666667j
-37. -12.j 13. +86.j
111. +36.j 126.33333333 -95.33333333j
27. -209.33333333j -62.33333333 +16.66666667j
95.66666667 +108.j 187. -50.j
89.88888889 -246.66666667j -151.22222222 -315.77777778j]
[ 1. +0.j -2. -3.j
-5. +3.j 1. +9.j
11.5 +6.j 0. -2.j
-6. +4.j 6. +10.j
18. -2.j 12. -23.j
-2.5 -2.j -1. +11.5j
18.5 +2.5j 15.5 -24.5j
-16.75 -38.j -4.66666667 +0.33333333j
10.33333333 +13.33333333j 22.33333333 -15.66666667j
-7.66666667 -41.66666667j -55.66666667 -24.16666667j
2. -2.j -10. -2.j
-4. +16.j 20. +16.j
35. -11.j -4. -4.j
-4. +20.j 32. +8.j
32. -40.j -22. -70.j
-9. +1.j 21. +25.j
42. -32.j -18. -80.j
-109.5 -42.5j -8.66666667 +10.j
47.33333333 +6.j 13.33333333 -76.j
-98.66666667 -68.j -159.66666667 +63.j
1.5 -6.j -21. +7.5j
10.5 +34.5j 55.5 +7.5j
53.25 -60.j -12. -3.j
15. +42.j 69. -21.j
15. -111.j -120. -106.5j
-15.75 +12.j 67.5 +23.25j
42.75 -107.25j -123.75 -129.75j
-253.125 +43.5j -5. +28.5j
95.5 -42.j -60.5 -157.5j
-261.5 -16.5j -228.5 +297.75j ]]