快速计算R中的双积分 [英] calculating double integrals in R quickly

查看:12
本文介绍了快速计算R中的双积分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找比

integrate(function(y) { 
   sapply(y, function(y) {
     integrate(function(x) myfun(x,y), llim, ulim)$value
   })
 }, llim, ulim)

例如

myfun <- function(x,y) cos(x+y)
llim <- -0.5
ulim <- 0.5

我找到了一个 旧论文引用了一个名为 quad2d 的 FORTRAN 程序除了matlab的一些帮助页面之外,我找不到其他任何东西.所以我正在寻找一个可以快速进行双积分的 C 或 FORTRAN 库(即没有 sapply 循环),并且可以从 R 调用.所有想法都非常感谢,只要它们都与 GPL 兼容.

I found an old paper that referred to a FORTRAN program called quad2d, but I couldn't find anything else but some help pages for matlab for the rest. So I'm looking for a C or FORTRAN library that can do double integrals quick (i.e. without the sapply loop), and that can be called from R. All ideas are very much appreciated, as long as they're all GPL compatible.

如果解决方案涉及从 R 已附带的库中调用其他函数,我也很乐意听取他们的意见.

If the solution involves calling other functions from the libraries that are already shipped with R, I'd love to hear from them as well.

推荐答案

cubature 包使用自适应算法进行 2D(和 ND)集成.对于大多数被积函数来说,它应该优于更简单的方法.

The cubature package does 2D (and N-D) integration using an adaptive algorithm. It should outperform simpler approaches for most integrands.

这篇关于快速计算R中的双积分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆