r - 计算R中函数乘积的双重积分的问题
问题描述
我正在尝试使用 R 包“pracma”中的函数“integral2”计算双积分。我在计算时遇到问题
integral2(function(x,y){ X(x)*R(x,y)*X(y) }, 0, 10, 0, 10)
在哪里
X <- function(t) {
-0.4*sqrt(2)*sin(pi*1*t)+0.016*sqrt(2)*sin(pi*2*t)-0.01*sqrt(2)*sin(pi*3*t)
}
和
R <- function(x,y){(1/2*(x^2-x+1/6))*(1/2*(y^2-y+1/6))-
(1/24*((abs(x-y)^4)-2*(abs(x-y)^3)+(abs(x-y)^2)-1/30))}.
我对 r 中的双积分的结果是
integral2(function(x,y){ X(x)*R(x,y)*X(y) }, 0, 10, 0, 10)$Q = 80.77929,
但如果我在 Maple 中计算相同的积分,结果是 87.911。
解决方案
以下将起作用。
X <- function(t){-0.4*sqrt(2)*sin(pi*1*t)+0.016*sqrt(2)*sin(pi*2*t)-
0.01*sqrt(2)*sin(pi*3*t)}
R <- function(x,y){(1/2*(x^2-x+1/6))*(1/2*(y^2-y+1/6))-
(1/24*((abs(x-y)^4)-2*(abs(x-y)^3)+(abs(x-y)^2)-1/30))}
f <- function(x, y){X(x)*R(x, y)*X(y)}
integral2b <- function(f, lower, upper){
integrate( function(y) {
sapply(y, function(y) {
integrate(function(x) f(x,y), lower[1], upper[1])$value
})
}, lower[2], upper[2])
}
integral2b(f, c(0, 0), c(10, 10))
#84.94517 with absolute error < 0.0081
请参阅R-Help,此答案改编自该线程。
推荐阅读
- java - Crieria Builder setMaxResults 排序问题
- c++ - 类对象初始化
- python - 在 python 列表中向后或向前循环以查找匹配项
- windows-7 - 文件夹的“修改日期”不正确(Windows 7)
- python - 如何在python中将输出保存为浮点数
- python - 如果在 DAG 上设置了未来日期,则在气流 1.10.1 中无法手动运行
- javascript - 如何构建 React 复选框树
- python - 如何加入这些列表的元素?
- asp.net - 小型医院的云托管?
- javascript - 在 ReactJS 中 onClick 时添加道具