| 1 |
\name{integrate.xy} |
| 2 |
\alias{integrate.xy} |
| 3 |
\title{Cheap Numerical Integration through Data Points} |
| 4 |
\description{ |
| 5 |
Given \eqn{(x_i, f_i)} where \eqn{f_i = f(x_i)}, compute a cheap |
| 6 |
approximation of \eqn{\int_a^b f(x) dx}{integral(a .. b) f(x) dx}. |
| 7 |
} |
| 8 |
\usage{ |
| 9 |
integrate.xy(x, fx, a, b, use.spline=TRUE, xtol=2e-08) |
| 10 |
} |
| 11 |
\arguments{ |
| 12 |
\item{x}{abscissa values.} |
| 13 |
\item{fx}{corresponding values of \eqn{f(x)}.} |
| 14 |
\item{a,b}{the boundaries of integration; these default to min(x) and |
| 15 |
max(x) respectively.} |
| 16 |
\item{use.spline}{logical; if TRUE use an interpolating spline.} |
| 17 |
\item{xtol}{tolerance factor, typically around |
| 18 |
\code{sqrt(.Machine$double.eps)} ......(fixme)....} |
| 19 |
} |
| 20 |
\details{ |
| 21 |
Note that this is really not good for noisy \code{fx} values; |
| 22 |
probably a smoothing spline should be used in that case. |
| 23 |
|
| 24 |
Also, we are not yet using Romberg in order to improve the trapezoid |
| 25 |
rule. This would be quite an improvement in equidistant cases. |
| 26 |
} |
| 27 |
\value{ |
| 28 |
the approximate integral. |
| 29 |
} |
| 30 |
\author{Martin Maechler, May 1994 (for S).} |
| 31 |
\seealso{\code{\link{integrate}} for numerical integration of |
| 32 |
\emph{functions}.} |
| 33 |
\examples{ |
| 34 |
x <- 1:4 |
| 35 |
integrate.xy(x, exp(x)) |
| 36 |
print(exp(4) - exp(1), digits = 10) # the true integral |
| 37 |
|
| 38 |
for(n in c(10, 20,50,100, 200)) { |
| 39 |
x <- seq(1,4, len = n) |
| 40 |
cat(formatC(n,wid=4), formatC(integrate.xy(x, exp(x)), dig = 9),"\n") |
| 41 |
} |
| 42 |
} |
| 43 |
\keyword{math} |
| 44 |
\keyword{utilities} |