我想计算一个球的一部分的体积(V),这个球是由三个平面(x=0,y=0和z=1.5)与球体相交而成的。我正在使用R语言编程,以下是我的代码。我尝试了两种不同的方法,使用笛卡尔坐标和极坐标。但它们都得出了负数。
## Compute the Volume between 3 planes x=0, y=0 and z=1.5 and a sphere
library("pracma", lib.loc="~/R/win-library/3.1")
f <- function(x, y) (sqrt(4 -x^2 - y^2) - 1.5 ) # here the function(x,y) is subtracted with -1.5 which represents the plane z=1.5
xmin <- 0
xmax <- 2
ymin <- 0
ymax <- function(x) (sqrt(4 - x^2))
I <- integral2(f, xmin, xmax, ymin, ymax)
I$Q # Integral over sector is not so exact
# Exact Volume from AutoCAD V=0.3600
## Volume of the sphere: use polar coordinates
f0 <- function(x, y) (sqrt(4 - x^2 - y^2)-1.5) # for x^2 + y^2 <= 4 the f(x,y) means z changes between zmin=1 and zmax= sqrt(4-x^2-y^2)
fp <- function(t, r) r * f0(r*cos(t), r*sin(t))
quad2d(fp, 0, pi/2, 0, 2, n = 101) # -0.523597
正确答案是 V= 0.3600 。请问有人可以给我提示吗?
谢谢。
sqrt(4-x^2)
--应该是这样的--然后integral2将返回0.251140。您可以尝试通过设置“reltol”参数来提高精度,但我认为使用极坐标会得到更好的结果。 - Hans W.