1 /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 
3 /*
4  Copyright (C) 2008 Klaus Spanderen
5 
6  This file is part of QuantLib, a free-software/open-source library
7  for financial quantitative analysts and developers - http://quantlib.org/
8 
9  QuantLib is free software: you can redistribute it and/or modify it
10  under the terms of the QuantLib license.  You should have received a
11  copy of the license along with this program; if not, please email
12  <quantlib-dev@lists.sf.net>. The license is also available online at
13  <http://quantlib.org/license.shtml>.
14 
15  This program is distributed in the hope that it will be useful, but WITHOUT
16  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17  FOR A PARTICULAR PURPOSE.  See the license for more details.
18 */
19 
20 /*! \file gausslobattointegral.hpp
21     \brief integral of a one-dimensional function using the adaptive
22     Gauss-Lobatto integral
23 */
24 
25 #ifndef quantlib_gauss_lobatto_integral_hpp
26 #define quantlib_gauss_lobatto_integral_hpp
27 
28 #include <ql/errors.hpp>
29 #include <ql/utilities/null.hpp>
30 #include <ql/math/integrals/integral.hpp>
31 
32 namespace QuantLib {
33 
34     //! Integral of a one-dimensional function
35     /*! Given a target accuracy \f$ \epsilon \f$, the integral of
36         a function \f$ f \f$ between \f$ a \f$ and \f$ b \f$ is
37         calculated by means of the Gauss-Lobatto formula
38     */
39 
40     /*! References:
41        This algorithm is a C++ implementation of the algorithm outlined in
42 
43        W. Gander and W. Gautschi, Adaptive Quadrature - Revisited.
44        BIT, 40(1):84-101, March 2000. CS technical report:
45        ftp.inf.ethz.ch/pub/publications/tech-reports/3xx/306.ps.gz
46 
47        The original MATLAB version can be downloaded here
48        http://www.inf.ethz.ch/personal/gander/adaptlob.m
49     */
50 
51     class GaussLobattoIntegral : public Integrator {
52       public:
53         GaussLobattoIntegral(Size maxIterations,
54                              Real absAccuracy,
55                              Real relAccuracy = Null<Real>(),
56                              bool useConvergenceEstimate = true);
57 
58       protected:
59         Real integrate (const ext::function<Real (Real)>& f,
60                         Real a, Real b) const;
61 
62         Real adaptivGaussLobattoStep(const ext::function<Real (Real)>& f,
63                                      Real a, Real b, Real fa, Real fb,
64                                      Real is) const;
65         Real calculateAbsTolerance(const ext::function<Real (Real)>& f,
66                                    Real a, Real b) const;
67 
68         Real relAccuracy_;
69         const bool useConvergenceEstimate_;
70         const static Real alpha_, beta_, x1_, x2_, x3_;
71     };
72 }
73 #endif
74