\[ \int_{0}^{\infty} \frac{1}{(x+1) \sqrt{x}} d x \]
## define the integrated function
integrand <- function(x) {1/((x+1)*sqrt(x))}
## integrate the function from 0 to infinity
integrate(integrand, lower = 0, upper = Inf)
## 3.141593 with absolute error < 2.7e-05
\[ \int_{-1.96}^{1.96} \frac{1}{\sqrt{2 \pi}} e^{-\frac{x^{2}}{2}} d x \]
f <- function(x) {1/sqrt(2*pi)*exp(-x^2/2)}
integrate(f, lower = -1.96, upper = 1.96)
## 0.9500042 with absolute error < 1e-11
\[ \int_{15}^{50} \int_{15}^{y}(x+0.805) d x d y \]
InnerFunc = function(x) { x + 0.805 }
InnerIntegral = function(y) { sapply(y,
function(z) { integrate(InnerFunc, 15, z)$value }) }
integrate(InnerIntegral , 15, 50)
## 16826.4 with absolute error < 1.9e-10
InnerFunc = function(x) { x + 0.805 }
InnerIntegral = Vectorize(function(y) { integrate(InnerFunc, 15, y)$value})
integrate(InnerIntegral , 15, 50)
## 16826.4 with absolute error < 1.9e-10
\[ \int_{0}^{\frac{1}{2}} \int_{0}^{\frac{1}{2}} \int_{0}^{\frac{1}{2}} \frac{2}{3}\left(x_{1}+x_{2}+x_{3}\right) d x_{1} d x_{2} d x_{3} \]
library(cubature) # load the package "cubature"
f <- function(x) { 2/3 * (x[1] + x[2] + x[3]) } # "x" is vector
adaptIntegrate(f, lowerLimit = c(0, 0, 0), upperLimit = c(0.5, 0.5, 0.5))
## $integral
## [1] 0.0625
##
## $error
## [1] 1.387779e-17
##
## $functionEvaluations
## [1] 33
##
## $returnCode
## [1] 0