### unidimensional integral
i <- integral("sin(x)", bounds = list(x = c(0,pi)))
i$value
### multidimensional integral
f <- function(x,y) x*y
i <- integral(f, bounds = list(x = c(0,1), y = c(0,1)))
i$value
### vector-valued integrals
f <- function(x,y) c(x, y, x*y)
i <- integral(f, bounds = list(x = c(0,1), y = c(0,1)))
i$value
### tensor-valued integrals
f <- function(x,y) array(c(x^2, x*y, x*y, y^2), dim = c(2,2))
i <- integral(f, bounds = list(x = c(0,1), y = c(0,1)))
i$value
### area of a circle
i <- integral(1,
bounds = list(r = c(0,1), theta = c(0,2*pi)),
coordinates = "polar")
i$value
### surface of a sphere
i <- integral(1,
bounds = list(r = 1, theta = c(0,pi), phi = c(0,2*pi)),
coordinates = "spherical")
i$value
### volume of a sphere
i <- integral(1,
bounds = list(r = c(0,1), theta = c(0,pi), phi = c(0,2*pi)),
coordinates = "spherical")
i$value
Run the code above in your browser using DataLab