manpagez: man pages & more
info ginac
Home | html | info | man
[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.12 Integrals

An object of class integral can be used to hold a symbolic integral. If you want to symbolically represent the integral of x*x from 0 to 1, you would write this as

 
integral(x, 0, 1, x*x)

The first argument is the integration variable. It should be noted that GiNaC is not very good (yet?) at symbolically evaluating integrals. In fact, it can only integrate polynomials. An expression containing integrals can be evaluated symbolically by calling the

 
.eval_integ()

method on it. Numerical evaluation is available by calling the

 
.evalf()

method on an expression containing the integral. This will only evaluate integrals into a number if subsing the integration variable by a number in the fourth argument of an integral and then evalfing the result always results in a number. Of course, also the boundaries of the integration domain must evalf into numbers. It should be noted that trying to evalf a function with discontinuities in the integration domain is not recommended. The accuracy of the numeric evaluation of integrals is determined by the static member variable

 
ex integral::relative_integration_error

of the class integral. The default value of this is 10^-8. The integration works by halving the interval of integration, until numeric stability of the answer indicates that the requested accuracy has been reached. The maximum depth of the halving can be set via the static member variable

 
int integral::max_integration_level

The default value is 15. If this depth is exceeded, evalf will simply return the integral unevaluated. The function that performs the numerical evaluation, is also available as

 
ex adaptivesimpson(const ex & x, const ex & a, const ex & b, const ex & f,
                   const ex & error)

This function will throw an exception if the maximum depth is exceeded. The last parameter of the function is optional and defaults to the relative_integration_error. To make sure that we do not do too much work if an expression contains the same integral multiple times, a lookup table is used.

If you know that an expression holds an integral, you can get the integration variable, the left boundary, right boundary and integrand by respectively calling .op(0), .op(1), .op(2), and .op(3). Differentiating integrals with respect to variables works as expected. Note that it makes no sense to differentiate an integral with respect to the integration variable.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]
© manpagez.com 2000-2024
Individual documents may contain additional copyright information.