Skip to content

Double integration using R

2 messages · Robert A'gata, michael.weylandt at gmail.com (R. Michael Weylandt

#
Hi,

I have a function that I need to do double integration:

\int^T_0 \int^t_0 N(\delta / \sigma \sqrt(u)) (1-N(\delta / \sigma
\sqrt(u))) du dt

where N(x) is a standard normal probability of x.

I start off by writing an inner integral into a function. Meaning
\int^t_0 N(\delta,\sigma \sqrt(u)) (1-N(\delta,\sigma \sqrt(u))) du.
Then calling integrate function on this function. This straightforward
way does not seem to work. I am not sure if there is any sample code
to do such integration? Thank you.

Regards,

Robert
There do exist packages for multi-variate integration in R, but sticking to base functions, what you've described should work but the inner integral will need to be vectorized before it's passes to the outer integral: Vectorize() can do this directly, but it won't be particularly fast since it's not true vectorization. Send real code if this doesn't help and we can take a look at it. 

Michael
On Nov 6, 2011, at 12:15 PM, "Robert A'gata" <rhelpacc at gmail.com> wrote: