You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

20 lines
649 B
R

#####################################
############# trapz #################
#####################################
trapz <- function(x, y) {
## Description:
## Performs a trapezoidal integration (approximate numerical integration
## of the area under the curve defined by the x and y coordinate pairs.
## See Wikipedia for more info on trapezoidal integration.
## Usage:
## trapz(x, y)
## Arguments:
## x: vector (of length n)
## y: vector (of length n)
## Return value:
## vector of length (n - 1)
#
idx <- 2:length(x)
return (as.double((x[idx] - x[idx - 1]) * (y[idx] + y[idx - 1])) / 2)
}