File: trapz.R

package info (click to toggle)
r-cran-catools 1.18.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 392 kB
  • sloc: ansic: 684; cpp: 644; makefile: 2
file content (12 lines) | stat: -rwxr-xr-x 602 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
#===========================================================================#
# 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)
}