QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | List of all members
TrapezoidIntegral< IntegrationPolicy > Class Template Reference

Integral of a one-dimensional function. More...

#include <trapezoidintegral.hpp>

+ Inheritance diagram for TrapezoidIntegral< IntegrationPolicy >:
+ Collaboration diagram for TrapezoidIntegral< IntegrationPolicy >:

Public Member Functions

 TrapezoidIntegral (Real accuracy, Size maxIterations)
 
- Public Member Functions inherited from Integrator
 Integrator (Real absoluteAccuracy, Size maxEvaluations)
 
virtual ~Integrator ()=default
 
Real operator() (const ext::function< Real(Real)> &f, Real a, Real b) const
 
void setAbsoluteAccuracy (Real)
 
void setMaxEvaluations (Size)
 
Real absoluteAccuracy () const
 
Size maxEvaluations () const
 
Real absoluteError () const
 
Size numberOfEvaluations () const
 
virtual bool integrationSuccess () const
 

Protected Member Functions

Real integrate (const ext::function< Real(Real)> &f, Real a, Real b) const override
 
- Protected Member Functions inherited from Integrator
void setAbsoluteError (Real error) const
 
void setNumberOfEvaluations (Size evaluations) const
 
void increaseNumberOfEvaluations (Size increase) const
 

Detailed Description

template<class IntegrationPolicy>
class QuantLib::TrapezoidIntegral< IntegrationPolicy >

Integral of a one-dimensional function.

Given a target accuracy \( \epsilon \), the integral of a function \( f \) between \( a \) and \( b \) is calculated by means of the trapezoid formula

\[ \int_{a}^{b} f \mathrm{d}x = \frac{1}{2} f(x_{0}) + f(x_{1}) + f(x_{2}) + \dots + f(x_{N-1}) + \frac{1}{2} f(x_{N}) \]

where \( x_0 = a \), \( x_N = b \), and \( x_i = a+i \Delta x \) with \( \Delta x = (b-a)/N \). The number \( N \) of intervals is repeatedly increased until the target accuracy is reached.

Tests:
the correctness of the result is tested by checking it against known good values.
Examples
MultidimIntegral.cpp.

Definition at line 52 of file trapezoidintegral.hpp.

Constructor & Destructor Documentation

◆ TrapezoidIntegral()

TrapezoidIntegral ( Real  accuracy,
Size  maxIterations 
)

Definition at line 54 of file trapezoidintegral.hpp.

Member Function Documentation

◆ integrate()

Real integrate ( const ext::function< Real(Real)> &  f,
Real  a,
Real  b 
) const
overrideprotectedvirtual

Implements Integrator.

Definition at line 59 of file trapezoidintegral.hpp.

+ Here is the call graph for this function: