R/trapz.R

Defines functions trapz

Documented in trapz

#===========================================================================#
# caTools - R library                                                       #
# Copyright (C) 2005 Jarek Tuszynski                                        #
# Distributed under GNU General Public License version 3                    #
#===========================================================================#

trapz = function(x, y) 
{ # computes the integral of y with respect to x using trapezoidal integration. 
  idx = 2:length(x)
  return (as.double( (x[idx] - x[idx-1]) %*% (y[idx] + y[idx-1])) / 2)
}

Try the caTools package in your browser

Any scripts or data that you put into this service are public.

caTools documentation built on Sept. 11, 2024, 6:06 p.m.