3

Possible Duplicate:
calculating double integrals in R quickly

Question from Braun and Murdoch, Monte Carlo Simulation:

doubleintegral: integral(from 0 to 1) integral(from 0 to 1) fct'n: cos(x-y) I-constants: dxdy

For an integral with only "dx" say, I use something like:

integrand <- function(x)
 {
    exp(x)
 }
integrate(integrand, lower = 1, upper = pi) $value

Could anybody please give me a tip, how to write a double integral in the R-Code?

Community
  • 1
  • 1
Andreas
  • 43
  • 4
  • 2
    Again, this is a simulation exercice and you are therefore not supposed to use 'integrate()'. Page 102 of your book shows the method you are supposed to apply. Good work ;-) – Marco Aug 09 '12 at 14:20
  • ocram, Thanks the simulation works pretty well. But the solutions by B&M for Ex. 1 p. 103 provide next to the sim. also integrate function as stated above. Could I turn the question around: How do I solve a double integral by using the fct'n "integrate" or similar? Ref. is made to p. 104, Ex. 2. –  Aug 09 '12 at 17:30
  • You don't need to write a program to do this integral. Use a pencil and paper. It is a very easy calculus problem. (Are the endpoints supposed to be 0 and 1 or 0 and Pi?) – UncleO Aug 09 '12 at 20:42
  • UncleO, I did integration via pencil and paper for the last 20 years or so, during my "first" actuarial career. The double integrals in actuarial science are on my level not that difficult, so far......! But even a senior like me is curious to learn something new. And I like "R". Anyway, in the above the upper limit is "pi", again from the B&M textbook, and it is only an exercise. If the question regarding double integral is to simple I will withdraw it. So far this blog is the only mean for me to solve my small problems. So, is there a chance to give me an idea? Anyway, thanks for reading. – Andreas Aug 10 '12 at 16:15
  • @AndreasRybicki, this might help http://stackoverflow.com/questions/8913603/calculating-double-integrals-in-r-quickly – Julius Vainora Aug 10 '12 at 16:23

0 Answers0