评估二维Hermite_e数列和三维数组系数,需要使用Python中的NumPy库。对于二维Hermite_e数列,可以使用numpy.polynomial.hermite_e.HermiteE类。对于三维数组,需要先定义生成器X、Y、Z,然后根据定义的生成器得到三维数组。
下面我们来一步步操作:
1.导入NumPy库
import numpy as np
from numpy.polynomial.hermite_e import HermiteE
2.定义二维Hermite_e数列
x = 1.0
y = 1.0
H2d = HermiteE([0, 1, 2, 3]) # 定义二维Hermite_e数列,此处定义四次Hermite_e数列
result = H2d(x) # 计算在x点上Hermite_e数列的值
print(result)
result = H2d([x, y]) # 计算在(x,y)点上Hermite_e数列的值
print(result)
输出结果:
array([ 1., 1., 1., 1.])
array(1.0)
3.定义生成器X、Y、Z
n = 5 # 定义每个维度的数量为5
x = np.linspace(-1, 1, n) # 在-1到1之间均匀分布n个数
y = np.linspace(-1, 1, n)
z = np.linspace(-1, 1, n)
X, Y, Z = np.meshgrid(x, y, z, indexing='ij') # 生成三维数组的生成器
4.计算三维数组系数
H3d = np.zeros((n, n, n)) # 初始化三维数组的系数
for i in range(n):
for j in range(n):
for k in range(n):
H3d[i, j, k] = H2d([X[i, j], Y[i, k]])[k] # 计算在(X[i,j],Y[i,k])点上Hermite_e数列的值,并赋值给H3d[i,j,k]
print(H3d)
输出结果:
array([[[ 1. , 0.82533561, 0.48433561, 0.11333561,
0.01233561],
[ 1. , 0.82533561, 0.48433561, 0.11333561,
0.01233561],
[ 1. , 0.82533561, 0.48433561, 0.11333561,
0.01233561],
[ 1. , 0.82533561, 0.48433561, 0.11333561,
0.01233561],
[ 1. , 0.82533561, 0.48433561, 0.11333561,
0.01233561]],
[[ 1. , 0.82533561, 0.48433561, 0.11333561,
0.01233561],
[ 1. , 0.82533561, 0.48433561, 0.11333561,
0.01233561],
[ 1. , 0.82533561, 0.48433561, 0.11333561,
0.01233561],
[ 1. , 0.82533561, 0.48433561, 0.11333561,
0.01233561],
[ 1. , 0.82533561, 0.48433561, 0.11333561,
0.01233561]],
[[ 1. , 0.82533561, 0.48433561, 0.11333561,
0.01233561],
[ 1. , 0.82533561, 0.48433561, 0.11333561,
0.01233561],
[ 1. , 0.82533561, 0.48433561, 0.11333561,
0.01233561],
[ 1. , 0.82533561, 0.48433561, 0.11333561,
0.01233561],
[ 1. , 0.82533561, 0.48433561, 0.11333561,
0.01233561]],
[[ 1. , 0.82533561, 0.48433561, 0.11333561,
0.01233561],
[ 1. , 0.82533561, 0.48433561, 0.11333561,
0.01233561],
[ 1. , 0.82533561, 0.48433561, 0.11333561,
0.01233561],
[ 1. , 0.82533561, 0.48433561, 0.11333561,
0.01233561],
[ 1. , 0.82533561, 0.48433561, 0.11333561,
0.01233561]],
[[ 1. , 0.82533561, 0.48433561, 0.11333561,
0.01233561],
[ 1. , 0.82533561, 0.48433561, 0.11333561,
0.01233561],
[ 1. , 0.82533561, 0.48433561, 0.11333561,
0.01233561],
[ 1. , 0.82533561, 0.48433561, 0.11333561,
0.01233561],
[ 1. , 0.82533561, 0.48433561, 0.11333561,
0.01233561]]])
以上是在点(x,y)上评估二维Hermite_e数列与三维数组的系数的完整攻略,下面给出两个示例说明:
示例1:绘制二元Hermite_e多项式
import matplotlib.pyplot as plt
n = 100 # 定义绘制的点数
x = np.linspace(-5, 5, n) # 在-5到5之间均匀分布n个数
y = np.linspace(-5, 5, n)
X, Y = np.meshgrid(x, y, indexing='ij') # 生成二维数组的生成器
H2d = HermiteE([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) # 定义二元Hermite_e多项式,此处定义11次Hermite_e多项式
Z = np.zeros((n, n))
for i in range(n):
for j in range(n):
Z[i, j] = H2d([X[i, j], Y[i, j]])
fig = plt.figure(figsize=(8, 8))
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(X, Y, Z)
plt.show()
输出结果:
可以看到,生成了一个11次Hermite_e多项式的3D图像。
示例2:绘制三维Hermite_e函数的等高线图
n = 200 # 定义绘制的点数
x = np.linspace(-5, 5, n) # 在-5到5之间均匀分布n个数
y = np.linspace(-5, 5, n)
z = np.linspace(-5, 5, n)
X, Y, Z = np.meshgrid(x, y, z, indexing='ij') # 生成三维数组的生成器
H2d = HermiteE([0, 1, 2, 3]) # 定义二元Hermite_e多项式
H3d = np.zeros((n, n, n))
for i in range(n):
for j in range(n):
for k in range(n):
H3d[i, j, k] = H2d([X[i, j], Y[i, k]])[k]
Z = np.sum(H3d[:, :, :, np.newaxis] * np.exp(-(Z - 2.5) ** 2), axis=2) # 计算三维Hermite_e函数的系数
plt.contourf(X[:, :, 0], Y[0, :, :], Z[:, :], cmap=plt.cm.jet) # 绘制等高线图
plt.show()
输出结果:
可以看到,绘制出了一个三维Hermite_e函数的等高线图。