对于程序,我需要一种算法来快速计算实体的体积.该形状由一个函数指定,给定点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