romberg | R Documentation |
Romberg Integration
romberg(f, a, b, maxit = 25, tol = 1e-12, ...)
f |
function to be integrated. |
a , b |
end points of the interval. |
maxit |
maximum number of iterations. |
tol |
requested tolerance. |
... |
variables to be passed to the function. |
Simple Romberg integration with an explicit Richardson method applied to a series of trapezoidal integrals. This scheme works best with smooth and non-oscillatory functions and needs the least number of function calls among all integration routines.
The function does not need to be vectorized.
List of value, number or iterations, and relative error.
Using a trapezoid formula Romberg integration will use
2*(2^iter-1)+iter
function calls. By remembering function values
this could be reduced to 2^iter+1
calls.
Chapra, S. C., and R. P. Canale (2006). Numerical Methods for Engineers. Fifth Edition, McGraw-Hill, New York.
integrate
, quadgr
romberg(sin, 0, pi, tol = 1e-15) # 2 , rel.error 1e-15
romberg(exp, 0, 1, tol = 1e-15) # 1.718281828459044 , rel error 1e-15
# 1.718281828459045 , i.e. exp(1) - 1
f <- function(x, p) sin(x) * cos(p*x)
romberg(f, 0, pi, p = 2) # 2/3 , abs.err 1.5e-14
# value: -0.6666667, iter: 7, rel.error: 1e-12
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.