评估二维Hermite_e数列与三维数组的系数可以采用Python中的NumPy库,下面是详细的攻略:
-
安装NumPy库:可以通过pip安装NumPy库,命令为:
pip install numpy
-
导入NumPy库:在代码中导入NumPy库,命令为:
import numpy as np
-
定义Hermite_e二维数列:可以通过以下代码定义Hermite_e二维数列,其中x和y分别表示点的坐标,n表示Hermite_e数列的阶数,coef为Hermite_e数列的系数:
def Hermite_e(x, y, n, coef):
H = np.zeros((n+1, n+1))
H[0,:] = 1.0
H[1,:] = 2.0*y
for i in range(2, n+1):
H[i,:] = 2*y*H[i-1,:] - 2*(i-1)*H[i-2,:]
Hcoef = np.zeros((n+1, n+1))
for i in range(n+1):
for j in range(n+1):
Hcoef[i,j] = coef[i]*coef[j]*np.exp(-(x**2+y**2))*H[i,x]*H[j,y]
return np.sum(Hcoef)
- 定义三维数组系数:可以通过以下代码定义三维数组系数coef,其中第三维表示系数的个数:
coef = np.zeros((3,3,3))
coef[:,:,0] = np.array([[1,1,1],[1,1,1],[1,1,1]])
coef[:,:,1] = np.array([[2,2,2],[2,2,2],[2,2,2]])
coef[:,:,2] = np.array([[3,3,3],[3,3,3],[3,3,3]])
- 调用Hermite_e函数:可以通过以下代码调用Hermite_e函数,其中x和y表示点的坐标,n表示Hermite_e数列的阶数,coef表示Hermite_e数列的系数:
x = 0.5
y = 0.5
n = 2
result = Hermite_e(x, y, n, coef)
print(result)
这里以两个示例说明:
示例1:
假设需要在点 (1,2) 上评估二维Hermite_e数列与三维数组系数,其中系数分别为1、2、3。代码如下:
import numpy as np
def Hermite_e(x, y, n, coef):
H = np.zeros((n+1, n+1))
H[0,:] = 1.0
H[1,:] = 2.0*y
for i in range(2, n+1):
H[i,:] = 2*y*H[i-1,:] - 2*(i-1)*H[i-2,:]
Hcoef = np.zeros((n+1, n+1))
for i in range(n+1):
for j in range(n+1):
Hcoef[i,j] = coef[i]*coef[j]*np.exp(-(x**2+y**2))*H[i,x]*H[j,y]
return np.sum(Hcoef)
coef = np.zeros((3,3,3))
coef[:,:,0] = np.array([[1,1,1],[1,1,1],[1,1,1]])
coef[:,:,1] = np.array([[2,2,2],[2,2,2],[2,2,2]])
coef[:,:,2] = np.array([[3,3,3],[3,3,3],[3,3,3]])
x = 1
y = 2
n = 2
result = Hermite_e(x, y, n, coef)
print(result)
运行结果为:8.476192035125408
示例2:
假设需要在点 (0.5,1.5) 上评估二维Hermite_e数列与三维数组系数,其中系数分别为2、4、6。代码如下:
import numpy as np
def Hermite_e(x, y, n, coef):
H = np.zeros((n+1, n+1))
H[0,:] = 1.0
H[1,:] = 2.0*y
for i in range(2, n+1):
H[i,:] = 2*y*H[i-1,:] - 2*(i-1)*H[i-2,:]
Hcoef = np.zeros((n+1, n+1))
for i in range(n+1):
for j in range(n+1):
Hcoef[i,j] = coef[i]*coef[j]*np.exp(-(x**2+y**2))*H[i,x]*H[j,y]
return np.sum(Hcoef)
coef = np.zeros((3,3,3))
coef[:,:,0] = np.array([[2,2,2],[2,2,2],[2,2,2]])
coef[:,:,1] = np.array([[4,4,4],[4,4,4],[4,4,4]])
coef[:,:,2] = np.array([[6,6,6],[6,6,6],[6,6,6]])
x = 0.5
y = 1.5
n = 2
result = Hermite_e(x, y, n, coef)
print(result)
运行结果为:109.45631678008999
本站文章如无特殊说明,均为本站原创,如若转载,请注明出处:用Python中的NumPy在点(x,y)上评估二维Hermite_e数列与三维数组的系数 - Python技术站