2

I'm trying to translate the following double integral in R.

enter image description here

n <- 1
InnerFunc <- function(x, y) {f(y - x)*g(x)}
InnerIntegral <- Vectorize(function(y) {integrate(InnerFunc, -Inf, Inf)$value})
integrate(InnerIntegral, n, Inf)

I tried to find inspiration from another question but I'm getting mixed up in the arguments. Thanks for the help.

r2evans
  • 141,215
  • 6
  • 77
  • 149
Seylus
  • 21
  • 2
  • [pracma](https://cran.r-project.org/web/packages/pracma/index.html) offers the `integral2` function for this sort of thing. – Dan Mar 08 '19 at 18:43
  • You may also get help from this post [Numerical Triple Integration in R](https://stackoverflow.com/q/44551816/4752675) – G5W Mar 08 '19 at 18:52

1 Answers1

0

Thanks G5W for referring me to this post: Numerical Triple Integration in R

I think I am able to answer my own question now.

n <- 1
integrate(Vectorize(function(y) {
integrate(Vectorize(function(x) {f(y - x)*g(x)}), -Inf, Inf)$value }), n, Inf)

I tested the syntax with

f <- function(x) {x^2}
g <- function(x) {sin(x)}

integrate(Vectorize(function(y) {
integrate(Vectorize(function(x) {f(y-x)*g(y)}), 0, 1)$value }), 0, pi)

Which gives 3.394678 as in https://www.wolframalpha.com/input/?i=integrate+(y-x)%5E2+sin+y+dx+dy,+x%3D0+to+1,+y%3D0+to+pi

Seylus
  • 21
  • 2