sfsmisc (version 1.1-17)

integrate.xy: Cheap Numerical Integration through Data points.

Description

Given \((x_i, f_i)\) where \(f_i = f(x_i)\), compute a cheap approximation of \(\int_a^b f(x) dx\).

Usage

integrate.xy(x, fx, a, b, use.spline=TRUE, xtol=2e-08)

Value

the approximate integral.

Arguments

x

abscissa values.

fx

corresponding values of \(f(x)\).

a,b

the boundaries of integration; these default to min(x) and max(x) respectively.

use.spline

logical; if TRUE use an interpolating spline.

xtol

tolerance factor, typically around sqrt(.Machine$double.eps) ......(fixme)....

Author

Martin Maechler, May 1994 (for S).

Details

Note that this is really not good for noisy fx values; probably a smoothing spline should be used in that case.

Also, we are not yet using Romberg in order to improve the trapezoid rule. This would be quite an improvement in equidistant cases.

See Also

integrate for numerical integration of functions.

Examples

Run this code
 x <- 1:4
 integrate.xy(x, exp(x))
 print(exp(4) - exp(1), digits = 10) # the true integral

 for(n in c(10, 20,50,100, 200)) {
   x <- seq(1,4, len = n)
   cat(formatC(n,wid=4), formatC(integrate.xy(x, exp(x)), dig = 9),"\n")
 }

Run the code above in your browser using DataLab