pracma (version 1.9.9)

romberg: Romberg Integration

Description

Romberg Integration

Usage

romberg(f, a, b, maxit = 25, tol = 1e-12, ...)

Arguments

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.

Value

List of value, number or iterations, and relative error.

Details

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.

References

Chapra, S. C., and R. P. Canale (2006). Numerical Methods for Engineers. Fifth Edition, McGraw-Hill, New York.

See Also

integrate, quadgr

Examples

Run this code
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

Run the code above in your browser using DataLab