以下是我进入NumPy世界的第一步。
事实上,目标在2-D函数下绘制为3-D网格:N = \frac{n}{2\sigma\sqrt{\pi}}\exp^{-\frac{n^{2}x^{2}}{4\sigma^{2}}}
这可以作为Matlab中的一块蛋糕来完成,下面的片段:
^{pr2}$
但血腥的结果是丑陋的,足以驱使我尝试Python能力来生成科学的绘图。在
我搜索了一些东西,发现在Pyhton中达到上述标记的主要步骤可能是通过以下代码片段获得的:from matplotlib.patches import Polygon
import numpy as np
from scipy.integrate import quad
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
sigma = 1
def integrand(x,n):
return (n/(2*sigma*np.sqrt(np.pi)))*np.exp(-(n**2*x**2)/(4*sigma**2))
t = np.linespace(0, 20, 0.01)
n = np.linespace(1, 100, 1)
lower_bound = -100000000000000000000 #-inf
upper_bound = t
tt, nn = np.meshgrid(t,n)
real_integral = quad(integrand(tt,nn), lower_bound, upper_bound)
Axes3D.plot_trisurf(real_integral, tt,nn)
编辑:随着对格雷格建议的更多调查,以上代码是最新的片段。在
以下是生成的异常:
RuntimeError: infinity comparisons don't work for you
它似乎是指quad调用。。。在
你能帮我解决这个积分绘图问题吗?!。。。在
最佳