File: trapz.R

package info (click to toggle)
catools 1.8-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 348 kB
  • ctags: 74
  • sloc: ansic: 650; cpp: 639; makefile: 3
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)
}