0

I'm sorry. But I'm still confused how I can get my question from those answers. My question is following.

I would like to code this calculation in R:

enter image description here

From my hand, it becomes 141,66666666 π. I know how to take a integral if both integrals are from exact numbers using adaptIntegrate(). But I'm not sure how to do in my case. Could you guys help me? Thank you so much in advance.

Stéphane Laurent
  • 75,186
  • 15
  • 119
  • 225
darmiani
  • 1
  • 2
  • Can you show what you've tried so far – Conor Neilson Apr 02 '20 at 05:28
  • A standard way of proceeding is to estimate integrals using Monte Carlo simulations (if a large number of simulations you can have a rather precise estimates). If you transform your problem into a random variable problem, you can have an estimates for your double integral – linog Apr 02 '20 at 06:01

2 Answers2

1

With pracma::integral2:

library(pracma)

fun <- function(x,y) sqrt(2.5^2 * (1 - x^2/5^2 - y^2/8.5^2))
xmin <- 0; xmax <- 5
ymin <- 0; ymax <- function(x) sqrt(8.5^2 * (1-x^2/5^2))

integral2(fun, xmin, xmax, ymin, ymax)
# $Q
# [1] 55.6333
# 
# $error
# [1] 6.555276e-06

Not the same result as yours.

Stéphane Laurent
  • 75,186
  • 15
  • 119
  • 225
0

You will get a similar result by doubly integrating the function with a 1-dim. integration routine such as integrate in Base R.

f = function(x) {
    integrate(function(y) {sqrt(1 - (x/5)^2 - (y/8.5)^2)},
              0, 8.5*sqrt(1 - (x/5)^2))$value
}

(res = 2.5 * integrate(Vectorize(f), 0, 5)$value)
## [1] 55.63237

Your manual calculation is probably wrong.

Hans W.
  • 1,799
  • 9
  • 16