integrate.xy.RdGiven \((x_i, f_i)\) where \(f_i = f(x_i)\), compute a cheap approximation of \(\int_a^b f(x) dx\).
integrate.xy(x, fx, a, b, use.spline=TRUE, xtol=2e-08)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.
the approximate integral.
integrate for numerical integration of
functions.
x <- 1:4
integrate.xy(x, exp(x))
#> [1] 52.40261
print(exp(4) - exp(1), digits = 10) # the true integral
#> [1] 51.8798682
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")
}
#> 10 51.8822763
#> 20 51.8799518
#> 50 51.8799052
#> 100 51.8799054
#> 200 51.8799054