Z依赖于X和Y的向量的情节表面
我目前正在研究一个小型Python脚本,该脚本可用于使用径向基函数方法插值点。因此,我想绘制一个Z值由Z值计算的表面,该向量取决于X和Y。
我当前的方法是:
import numpy as np
import matplotlib.pyplot as plt
def phi(x):
return np.exp(- np.power(x, 2))
fig = plt.figure(figsize=(8,7))
ax = fig.add_subplot(projection='3d')
x = np.arange(0, 6, 0.25)
y = np.arange(0, 6, 0.25)
X, Y = np.meshgrid(x, y)
Z = 0.49 * phi(np.linalg.norm(np.array([[1,1], [X,Y]]))) + \
0.79 * phi(np.linalg.norm(np.array([[2,3], [X,Y]]))) + \
0.39 * phi(np.linalg.norm(np.array([[4,2], [X,Y]])))
surf = ax.plot_surface(X, Y, Z, cmap='viridis')
plt.xlim(0, 6)
plt.ylim(0, 6)
plt.show()
我传递给phi()的参数似乎有问题 - 但我不确定它是什么。 那么如何正确计算Z值呢?
注意:我发现了一个类似的问题,但是答案对我没有帮助。
I'm currently working on a small python script which can be used to interpolate points with a radial basis function approach. Therefore I would like to plot a surface where the Z value is calculated by a vector which depends on X and Y.
The formula I need to implement looks like this:
My current approach is the following:
import numpy as np
import matplotlib.pyplot as plt
def phi(x):
return np.exp(- np.power(x, 2))
fig = plt.figure(figsize=(8,7))
ax = fig.add_subplot(projection='3d')
x = np.arange(0, 6, 0.25)
y = np.arange(0, 6, 0.25)
X, Y = np.meshgrid(x, y)
Z = 0.49 * phi(np.linalg.norm(np.array([[1,1], [X,Y]]))) + \
0.79 * phi(np.linalg.norm(np.array([[2,3], [X,Y]]))) + \
0.39 * phi(np.linalg.norm(np.array([[4,2], [X,Y]])))
surf = ax.plot_surface(X, Y, Z, cmap='viridis')
plt.xlim(0, 6)
plt.ylim(0, 6)
plt.show()
Something seems to be wrong with the parameter that I pass to the phi()-function but I'm not sure what it is.
So how can I calculate the Z value correctly?
Note: I found a similar question, but the answer did not help me in my case.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如评论中提到的@mateo瓶,最简单的方法是用毕达哥拉斯公式计算规范。工作代码看起来像这样:
现在结果是具有径向基函数的良好插值。

As @Mateo Vial mentioned in the comments, the simplest approach is to calculate the norm with the pythagorean formula. The working code looks like this:
And now the result is a good interpolation with a radial basis function.

这是重构您拥有的一种方法:
这会产生:
Here's one way to refactor what you have:
This produces: