假设我有
g = function (x) matrix(exp(-(x[1,]^2 + x[2,]^2)/2) / (2*pi))
和
h = function (x) {(exp(-(x[1]^2 + x[2]^2)/2) / (2 * pi))}
f = function (x) matrix(h(as.vector(x)))
f
和g
是否具有相同的功能?
> f(matrix(c(1,2),ncol=1))
[,1]
[1,] 0.01306423
> g(matrix(c(1,2),ncol=1))
[,1]
[1,] 0.01306423
似乎如此,但是我使用hcubature
> hcubature(g, lowerLimit=c(0,0), upperLimit=c(3,3), vectorInterface=TRUE)
$integral
[1] 0.2486516
$error
[1] 1.855633e-06
$functionEvaluations
[1] 6
$returnCode
[1] 0
和
> hcubature(f, lowerLimit=c(0,0), upperLimit=c(3,3), vectorInterface=TRUE)
$integral
[1] -4.500035e-18
$error
[1] 2.641648e-17
$functionEvaluations
[1] 55
$returnCode
[1] 0
PS我也担心返回码为0。