romberg(sin, 0, pi, tol = 1e-12) # 2.000000000000001 , rel.error 0
romberg(exp, 0, 1, tol = 1e-12) # 1.718281828458432 , rel error 3.6e-13
# 1.718281828459045 , i.e. exp(1) - 1
f <- function(x, p) sin(x) * cos(p*x)
romberg(f, 0, pi, tol = 1e-10, p = 2) # 2/3
# value: -0.6666667, iter: 6, rel.error: 6.57967e-11
Run the code above in your browser using DataLab