The foundamental idea of numerical integration is to estimate the area of the region in the xy-plane bounded by the graph of function f(x). The integral was esimated by dividing x into small intervals, then adds all the small approximations to give a total approximation.
Trapezoidal rule
Numerical integration can be done by trapezoidal rule, simpson’s rule and quadrature rules. R has a built-in function, integrate, which performs adaptive quadrature.
Trapezoidal rule[1] works by approximating the region under the graph f(x) as a trapezoid and calculating its area.
trapezoid <- function(fun, a, b, n=