![](http://www.gnu-darwin.org/hexley-gd-sm.png)
|
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
This section describes how to compute numerical integration of a function in one
dimension. In Ruby/GSL, all the GSL routines for numerical integration is provided
as methods of GSL_Function objects.
A GSL_Function object which represents the sine function sin(x) can be created as
f = GSL_Function.new { |x| sin(x) }
To compute numerical integration of sin(x) over the range (a, b), one
may invote a method integratexxx, as
f.integratexxx(a, b)
For detailed descriptions of each C function which corresponds to the Ruby instance
method listed below, consult GSL manual.
GSL_Function#integration_qng(a, b, epsabs, epsrel)
-
This method applies the Gauss-Kronrod integration rules in succession until an
estimate of the integral of the reciever function (a GSL_Function object)
over (a,b) is achieved within the desired absolute and relative
error limits, epsabs and epsrel. The method returns an array of
four elements [result, err, neval, status] , those are the final approximation
of the integration, an estimate of the absolute error, the number of function
evaluation, and the status which is returned by the GSL integration_qng()
function.
ex.) Integrate sin(x) over x = 0 -- 2 with accuracies
epsabs = 0, epsrel = 1.0e-7.
require 'gsl'
f = GSL_Function.new { |x| sin(x) }
ans = f.integration_qng(0, 2, 0, 1.0e-7)
p ans[0] <- result
GSL_Function#integration_qag(a, b, epsabs, epsrel, limit, key)
-
This method applies an integration rule adaptively until an estimate of the
integral of the reciever function over (a,b) is achieved within the desired
absolute and relative error limits, epsabs and epsrel. The method
returns an array with four elements [result, err, neval, status] .
The integration rule is determined by the value of key, which should be chosen
from the following symbolic names,
GSL_INTEG_GAUSS15 (key = 1)
GSL_INTEG_GAUSS21 (key = 2)
GSL_INTEG_GAUSS31 (key = 3)
GSL_INTEG_GAUSS41 (key = 4)
GSL_INTEG_GAUSS51 (key = 5)
GSL_INTEG_GAUSS61 (key = 6)
corresponding to the 15, 21, 31, 41, 51 and 61 point Gauss-Kronrod rules. The
higher-order rules give better accuracy for smooth functions, while lower-order
rules save time when the function contains local difficulties, such as
discontinuities.
ex.) from GSL manual p.160
f = GSL_Function.new { |x|
log(x)/sqrt(x)
}
p f.integration_qags(0, 1, 0, 1e-7, 1000)
GSL_Function#integration_qags(a, b, epsabs, epsrel, limit)
GSL_Function#integration_qagp(ary, epsabs, epsrel, limit)
GSL_Function#integration_qagi(epsabs, epsrel, limit)
GSL_Function#integration_qagiu(a, epsabs, epsrel, limit)
GSL_Function#integration_qagil(b, epsabs, epsrel, limit)
GSL_Function#integration_qagwc(a, b, c, epsabs, epsrel, limit)
GSL_Function#integration_qaws(a, b, t, epsabs, epsrel, limit)
|