https://github.com/cran/pracma
Raw File
Tip revision: f2b1a2b0b321bb40a034d89a636072cd71ad25cc authored by HwB on 21 November 2011, 00:00:00 UTC
version 0.8.6
Tip revision: f2b1a2b
trapz.Rd
\name{trapz}
\alias{trapz}
\title{Trapezoidal Integration}
\description{
  Compute the area of a function with values \code{y} at the points
  \code{x}.
}
\usage{
  trapz(x, y)
}
\arguments{
  \item{x}{x-coordinates of points on the x-axis}
  \item{y}{y-coordinates of function values}
}
\details{
  The points \code{(x, 0)} and \code{(x, y)} are taken as vertices of a
  polygon and the area is computed using \code{polyarea}.

  This approach matches exactly the approximation for integrating the
  function using the trapezoidal rule with basepoints \code{x}.
}
\value{
  Approximated integral of the function from \code{min(x)} to \code{max(x)}.
}
\author{
  hwb \email{hwborchers@googlemail.com}
}
\seealso{
  \code{\link{polyarea}}
}
\examples{
  # Calculate the area under the sine curve from 0 to pi:
  x <- seq(0, pi, len=101)
  y <- sin(x)
  trapz(x, y)  #=> 1.999836
}
\keyword{ math }
back to top