我想使用monte-carlo方法集成下面给出的功能:

f(x,y,z) = (x**2 * y * z) + (y**2 * z**2 * x) + (x**3 * y**3 *z)


限制:

0 <= x < 4,

0 <= y < 2*(x**2),

0 <= z < 1.


这是我到目前为止尝试过的。

from skmonaco import mcquad

def g(t):
   """
   The integrand.
   """
   x = t[0]
   y = t[1]
   z = t[2]

   f = (x**2 * y * z) + (y**2 * z**2 * x) + (x**3 * y**3 *z)

   return f

mcquad(g,npoints=100000,xl=[0., 0., 0.],xu=[4., 10., 1.],nprocs=4)


如果我在两个常数之间设置y的极限,我将得到正确的答案。例如:0

最佳答案

当(x,y,z)在域内时,令h(x,y,z)等于f(x,y,z),否则为0。

在更大的区域积分

0 <= x < 4,
0 <= y < 32,
0 <= z < 1


给我们相同的结果。

那就是我们可以运行以下代码:

from skmonaco import mcquad

def g(t):
   """
   The integrand.
   """
   x, y, z = t
   if y < 2 * (x**2):
       return (x**2 * y * z) + (y**2 * z**2 * x) + (x**3 * y**3 *z)
   return 0

print(mcquad(g,npoints=100000,xl=[0., 0., 0.],xu=[4., 32, 1.],nprocs=4))

关于python - 蒙特卡洛积分与相关参数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48776933/

10-11 15:22