QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
kronrodintegral.hpp
Go to the documentation of this file.
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2007 François du Vignaud
5 Copyright (C) 2003 Niels Elken Sønderby
6
7 This file is part of QuantLib, a free-software/open-source library
8 for financial quantitative analysts and developers - http://quantlib.org/
9
10 QuantLib is free software: you can redistribute it and/or modify it
11 under the terms of the QuantLib license. You should have received a
12 copy of the license along with this program; if not, please email
13 <quantlib-dev@lists.sf.net>. The license is also available online at
14 <http://quantlib.org/license.shtml>.
15
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the license for more details.
19*/
20
21/*! \file kronrodintegral.hpp
22 \brief Integral of a 1-dimensional function using the Gauss-Kronrod method
23*/
24
25#ifndef quantlib_kronrod_integral_hpp
26#define quantlib_kronrod_integral_hpp
27
28#include <ql/errors.hpp>
29#include <ql/types.hpp>
30#include <ql/utilities/null.hpp>
32#include <ql/functional.hpp>
33
34namespace QuantLib {
35
36 //! Integral of a 1-dimensional function using the Gauss-Kronrod methods
37 /*! This class provide a non-adaptive integration procedure which
38 uses fixed Gauss-Kronrod abscissae to sample the integrand at
39 a maximum of 87 points. It is provided for fast integration
40 of smooth functions.
41
42 This function applies the Gauss-Kronrod 10-point, 21-point, 43-point
43 and 87-point integration rules in succession until an estimate of the
44 integral of f over (a, b) is achieved within the desired absolute and
45 relative error limits, epsabs and epsrel. The function returns the
46 final approximation, result, an estimate of the absolute error,
47 abserr and the number of function evaluations used, neval. The
48 Gauss-Kronrod rules are designed in such a way that each rule uses
49 all the results of its predecessors, in order to minimize the total
50 number of function evaluations.
51 */
53 public:
58 Real relativeAccuracy() const;
59 protected:
60 Real integrate(const ext::function<Real(Real)>& f, Real a, Real b) const override;
61
62 private:
64 };
65
66 //! Integral of a 1-dimensional function using the Gauss-Kronrod methods
67 /*! This class provide an adaptive integration procedure using 15
68 points Gauss-Kronrod integration rule. This is more robust in
69 that it allows to integrate less smooth functions (though
70 singular functions should be integrated using dedicated
71 algorithms) but less efficient beacuse it does not reuse
72 precedently computed points during computation steps.
73
74 References:
75
76 Gauss-Kronrod Integration
77 <http://mathcssun1.emporia.edu/~oneilcat/ExperimentApplet3/ExperimentApplet3.html>
78
79 NMS - Numerical Analysis Library
80 <http://www.math.iastate.edu/burkardt/f_src/nms/nms.html>
81
82 \test the correctness of the result is tested by checking it
83 against known good values.
84 */
86 public:
87 explicit GaussKronrodAdaptive(Real tolerance,
88 Size maxFunctionEvaluations = Null<Size>());
89 protected:
90 Real integrate(const ext::function<Real(Real)>& f, Real a, Real b) const override;
91
92 private:
93 Real integrateRecursively(const ext::function<Real (Real)>& f,
94 Real a,
95 Real b,
96 Real tolerance) const;
97 };
98}
99
100#endif
Integral of a 1-dimensional function using the Gauss-Kronrod methods.
Real integrate(const ext::function< Real(Real)> &f, Real a, Real b) const override
Real integrateRecursively(const ext::function< Real(Real)> &f, Real a, Real b, Real tolerance) const
Integral of a 1-dimensional function using the Gauss-Kronrod methods.
Real integrate(const ext::function< Real(Real)> &f, Real a, Real b) const override
Real absoluteAccuracy() const
Definition: integral.cpp:43
Size maxEvaluations() const
Definition: integral.cpp:47
template class providing a null value for a given type.
Definition: null.hpp:76
Classes and functions for error handling.
ext::function< Real(Real)> b
Maps function, bind and cref to either the boost or std implementation.
QL_REAL Real
real number
Definition: types.hpp:50
std::size_t Size
size of a container
Definition: types.hpp:58
Integrators base class definition.
Definition: any.hpp:35
null values
Custom types.