python 数值积分_区域体积的Python数值积分

博主在尝试使用Python的numpy和scipy库进行三维实体的数值积分来计算体积,遇到困难并警告提示达到最大子分区限制。之后博主转向使用蒙特卡罗方法自编程序,虽然能工作但速度较慢。博主寻求更高效、精确的积分算法或库,对精度和速度有较高要求,并表示愿意考虑其他可编译语言。
摘要由CSDN通过智能技术生成

对于程序,我需要一种算法来快速计算实体的体积.该形状由一个函数指定,给定点P(x,y,z),如果P是实体的点,则返回1,如果P不是实体的点,则返回0.

我尝试使用numpy使用以下测试:

import numpy

from scipy.integrate import *

def integrand(x,y,z):

if x**2. + y**2. + z**2. <=1.:

return 1.

else:

return 0.

g=lambda x: -2.

f=lambda x: 2.

q=lambda x,y: -2.

r=lambda x,y: 2.

I=tplquad(integrand,-2.,2.,g,f,q,r)

print I

但它没有给我以下错误:

Warning (from warnings module):

File “C:\Python27\lib\site-packages\scipy\integrate\quadpack.py”, line 321

warnings.warn(msg, IntegrationWarning)

IntegrationWarning: The maximum number of subdivisions (50) has been achieved.

If increasing the limit yields no improvement it is advised to analyze

the integrand in order to determine the difficulties. If the position of a

local dif

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值