Romberg integration of a callable function or method.
Returns the integral of function (a function of one variable) over the interval (a, b).
If show is 1, the triangular array of the intermediate results will be printed. If vec_func is True (default is False), then function is assumed to support vector arguments.
Parameters : | function : callable
a : float
b : float
|
---|---|
Returns : | results : float
|
Other Parameters: | |
args : tuple, optional
tol, rtol : float, optional
show : bool, optional
divmax : int, optional
vec_func : bool, optional
|
See also
dblquad, tplquad, romb, simps, trapz
References
[R19] | ‘Romberg’s method’ http://en.wikipedia.org/wiki/Romberg%27s_method |
Examples
Integrate a gaussian from 0 to 1 and compare to the error function.
>>> from scipy.special import erf
>>> gaussian = lambda x: 1/np.sqrt(np.pi) * np.exp(-x**2)
>>> result = romberg(gaussian, 0, 1, show=True)
Romberg integration of <function vfunc at 0x101eceaa0> from [0, 1]
Steps StepSize Results
1 1.000000 0.385872
2 0.500000 0.412631 0.421551
4 0.250000 0.419184 0.421368 0.421356
8 0.125000 0.420810 0.421352 0.421350 0.421350
16 0.062500 0.421215 0.421350 0.421350 0.421350 0.421350
32 0.031250 0.421317 0.421350 0.421350 0.421350 0.421350 0.421350
The final result is 0.421350396475 after 33 function evaluations.
>>> print 2*result,erf(1)
0.84270079295 0.84270079295