Updated almost 14 years ago by Knödlseder Jürgen
A one-dimensional function can be integrated using the
GIntegral class. To compute proceed as follows:
You need first to define the kernel function by deriving a class from the base class
GFunction. In the following example, we define the function , where
is a parameter of the function:
class function : public GFunction {
public:
function(double a) : m_a(a) {}
double eval(double x) { return m_a*x; }
protected:
double m_a; //!< A parameter needed by the function
};
eval(x) method that will be used to evaluate The numerical integral is then computed using the Romberg integration method provided by the GIntegral class. The following example illustrates how to proceed:
function f(47.0); GIntegral integral(&f); integral.eps(1.0e-8); double xmin = 1.0; double xmax = 2.0; result = integral.romb(xmin, xmax);