powered by
Given a vector (or a matrix) representing a curve (or set of curves, columnwise), the area (or set of areas) is calculated using the trapezoidal rule.
trapz(x, y)
vector of samples for the dependent variable.
vector or matrix of samples for the independent variable. In the case of the latter, curves are organized column-wise.
area (areas) under the sampled curve (curves).
# NOT RUN { x <- seq( 0, 1, by = 0.0001 ) y <- exp( x ) # Compare with true area of exp( 1 ) - 1 = 1.718282... areaEstimate <- trapz( x, y ) # }
Run the code above in your browser using DataLab