首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用R语言(积分)用3个平面切割的球体的体积

用R语言(积分)用3个平面切割的球体的体积
EN

Stack Overflow用户
提问于 2015-06-12 09:41:18
回答 2查看 250关注 0票数 4

我想要计算球的一部分的体积(V),这是球与三个球(x=0,y=0和z=1.5)相交的结果。我使用的是R语言,这是我的代码。我尝试了两种不同的方法,使用笛卡尔坐标和极坐标。他们都给出了否定的答案。

代码语言:javascript
复制
##  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。谁能给我个提示吗?

干杯

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-06-12 10:09:48

您的X区域集成涵盖了f(x,y)-1.5为负的区域,也涵盖了正的领域.球面与直线z=1.5的交点是半径sqrt(7/4)的圆(使用毕达哥拉斯),因此适当地调整限制,您可以得到:

代码语言:javascript
复制
library(pracma)
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 <- sqrt(7/4)
ymin <- 0 
ymax <- function(x) (sqrt(7/4 - x^2))
I <- integral2(f, xmin, xmax, ymin, ymax)
I$Q   # Integral over sector is not so exact
# [1] 0.3599741

非常接近你的预期。

票数 5
EN

Stack Overflow用户

发布于 2015-06-15 11:01:36

对于r=2的球面和球壳与x=1、y=1、z=1三平面的交点体积,我已经解决了。

代码语言:javascript
复制
##  Compute the Volume between 3 planes x=1.0, y=1.0 and z=1.0 and a sphere
library(pracma)
f <- function(x, y)  (sqrt(4 -x^2 - y^2) - 1 ) # here the function(x,y) is  subtracted with -1.5 which represents the plane z=1.5 
xmin <- 1
xmax <- sqrt(2)
ymin <- 1 
ymax <- function(x) (sqrt(3 - x^2))
I <- integral2(f, xmin, xmax, ymin, ymax)
I$Q   # 
# [1] 0.01520549
# Exact Volume from AutoCAD: 0.0152
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30799970

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档