Integrate N Function

Share:

Description

Inferface to the integration over function dimensions.

Usage

1
2
3
nint_integrateNFunc(f, funcs, x0, i0, ...)

nint_integrateNFunc_recursive(integrate1)

Arguments

integrate1

function(f, lowerLimit, upperLimit, ...) which performs one dimensional integration.

f

the scalar-valued wrapper function to be integrated.

funcs

the list of function dimensions.

x0

the partially realized point in the space.

i0

the vector of indices of function dimensions in the space.

...

other arguments passed to f.

Details

nint_integrate uses nint_integrateNFunc to handle function dimensions. See examples below on how to deploy different solutions.

The function built by nint_integrateNFunc_recursive directly sums over discrete dimensions and uses integrate1 otherwise. In conjunction with integrateA this is the default.

Value

nint_integrateNFunc returns a single numeric.

nint_integrateNFunc_recursive returns a recursive implementation for nint_integrateNFunc.

See Also

nint_integrate

integrateA

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
dfltNFunc = nint_integrateNFunc

## area of circle
s = nint_space(
    nint_intvDim(-1, 1),
    nint_funcDim(function(x) nint_intvDim(c(-1, 1) * sin(acos(x[1])) ))
)
nint_integrate(function(x) 1, s) # pi
## see nint_integrate's examples for more sophisticated integrals


## prepare for custom recursive implementation
using = TRUE
nfunc = nint_integrateNFunc_recursive(
    function(f, lowerLimit, upperLimit, ...) {
        if (using) { # this function is called many times
            using <<- FALSE
            cat('using integrateA\n')
        }
        integrateA(f, lowerLimit, upperLimit, ..., subdivisions=1)$value
    }
)
unlockBinding('nint_integrateNFunc', environment(nint_integrate))
assign('nint_integrateNFunc', nfunc, envir=environment(nint_integrate))

## integrate with custom recursive implementation
nint_integrate(function(x) 1, s) # pi


## prepare for custom solution
f = function(f, funcs, x0, i0, ...) {
    # add sophisticated code here
    print(list(f=f, funcs=funcs, x0=x0, i0=i0, ...))
    stop('do something')
}
unlockBinding('nint_integrateNFunc', environment(nint_integrate))
assign('nint_integrateNFunc', f, envir=environment(nint_integrate))

## integrate with custom solution
try(nint_integrate(function(x) 1, s))


assign('nint_integrateNFunc', dfltNFunc, envir=environment(nint_integrate))