A <- rbind(
c(-1, 0, 0), # -x
c( 1, 0, 0), # x
c( 0,-1, 0), # -y
c( 1, 1, 0), # x+y
c( 0, 0,-1), # -z
c( 1, 1, 1) # x+y+z
)
b <- c(
5, 4, # -5 < x < 4 <=> -x < 5 & x < 4
5, 3, # -5 < y < 3-x <=> -y < 5 & x+y < 3
10, 6 # -10 < z < 6-x-y <=> -z < 10 & x+y+z < 6
)
f <- function(x, y, z) {
x*y + 5*cos(z)
}
integrateOverPolyhedron(f, A, b)
Run the code above in your browser using DataLab