我在画Marcum函数,它是高斯函数在边界上的积分。
这是函数:
<a href="https://www.codecogs.com/eqnedit.php?latex=Q(y)=\int_{y}^{\infty}\frac{1}{2\pi}\exp(-\frac{x^2}{2})~dx" target="_blank"><img src="https://latex.codecogs.com/gif.latex?Q(y)=\int_{y}^{\infty}\frac{1}{2\pi}\exp(-\frac{x^2}{2})~dx" title="Q(y)=\int_{y}^{\infty}\frac{1}{2\pi}\exp(-\frac{x^2}{2})~dx" /></a>
y是用户必须输入的浮点值。我编写了代码来计算这个函数的期望值。不过,我要画的是这样的:
!
https://ibb.co/SRMsfY3
下面是计算Q(y)值的代码:
from scipy.integrate import quad
import scipy, numpy, math
from scipy import integrate
def integrand(x):
Q_y = (1/(math.sqrt(2*math.pi)))*math.exp((-x**2)/2)
return Q_y
y = input('y=')
ans, err = quad(integrand, float(y), math.inf)
print(ans)
我试着用下面的代码绘制它:
x_data=np.arange(-20,20,0.1)
z_data=np.arange(float(y),1000,1)
ans, err = quad(integrand, float(y), math.inf)
print(ans)
for item in x_data:
z_data[i]=integrand(x_data[i])[0]
i+=1
fig = plt.figure(1, figsize=(4,4))
plt.plot(x_data,z_data,color= 'blue',linestyle='--', label=label1)
返回以下错误:
File "C:/Users/m.rafiee/.spyder-py3/temp.py", line 59, in <module>
z_data[i]=integrand(x_data[i])[0]
IndexError: index 400 is out of bounds for axis 0 with size 400
我也不知道如何在绘图中添加如图所示的注释和散列区域。
我非常感谢你事先的帮助。