def MonteCarlo_Integral(f,a,b,n):
'''
基于蒙特卡罗方法计算定积分。...F:定积分曲线方程。
a、b:区间[a,b]。...f=lambda x:x**2
#利用蒙特卡罗方法计算定积分
MonteCarlo_Integral(f,0,2,N)
#利用SciPy内置模块直接计算定积分...integrate.quad(f,0,2))
x=np.linspace(-1.0,1.5,20)#产生等差数列作为坐标轴标记
y=f(x)
plt.plot(x,y,'r-',label='函数...')
plt.legend()
plt.show()
0.0
(2.666666666666667, 2.960594732333751e-14)
算法:蒙特卡罗方法计算定积分是采用随机点模拟方法来近似计算定积分的值