python三重积分_蒙特卡罗方法。三重积分。Python。“+”的操作数父级不受支持...

我尝试用蒙特卡罗方法近似三重积分∫∫∫∫xyzdV,其中S=[0,1]×[0,1]×0,1]。

我有这个代码:from numpy import *

import time

from scipy.integrate import tplquad

numpoints=100000 # number of random sample points

I2d=0.0 # initialize value

I2dsquare=0.0 # initialize to allow for calculation of variance

for n in xrange(numpoints):

x=random.uniform()

y=random.uniform()

z=random.uniform()

func = lambda x,y,z: x*y*z

x1,x2 = 0, 1

y1,y2 = lambda x: 0,lambda x: 1

z1,z2 = lambda x, y: 0,lambda x, y: 1

I2d += tplquad(func, x1,x2,y1,y2,z1,z2)

I2dsquare += (tplquad(func, x1,x2,y1,y2,z1,z2))**2

I2d=I2d/numpoints

I2dsquare=I2dsquare/numpoints

EstimError=4*sqrt( (I2dsquare - I2d**2)/numpoints) # estimated error

I2d=4*I2d

print "Value: %f" %I2d

print "Error estimate: %f" %EstimError

我有个错误:

^{pr2}$

我知道这段代码中有不同的类型,但我不知道如何修复它。例如,如果我试着为二次方程编写这段代码,一切正常,但不幸的是积分不起作用。在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值