| 1 | /*! |
|---|
| 2 | * \file |
|---|
| 3 | * \brief Definition of numerical integration |
|---|
| 4 | * \author Tony Ottosson |
|---|
| 5 | * |
|---|
| 6 | * ------------------------------------------------------------------------- |
|---|
| 7 | * |
|---|
| 8 | * IT++ - C++ library of mathematical, signal processing, speech processing, |
|---|
| 9 | * and communications classes and functions |
|---|
| 10 | * |
|---|
| 11 | * Copyright (C) 1995-2007 (see AUTHORS file for a list of contributors) |
|---|
| 12 | * |
|---|
| 13 | * This program is free software; you can redistribute it and/or modify |
|---|
| 14 | * it under the terms of the GNU General Public License as published by |
|---|
| 15 | * the Free Software Foundation; either version 2 of the License, or |
|---|
| 16 | * (at your option) any later version. |
|---|
| 17 | * |
|---|
| 18 | * This program is distributed in the hope that it will be useful, |
|---|
| 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 21 | * GNU General Public License for more details. |
|---|
| 22 | * |
|---|
| 23 | * You should have received a copy of the GNU General Public License |
|---|
| 24 | * along with this program; if not, write to the Free Software |
|---|
| 25 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
|---|
| 26 | * |
|---|
| 27 | * ------------------------------------------------------------------------- |
|---|
| 28 | */ |
|---|
| 29 | |
|---|
| 30 | #ifndef INTEGRATION_H |
|---|
| 31 | #define INTEGRATION_H |
|---|
| 32 | |
|---|
| 33 | #include <limits> |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | namespace itpp { |
|---|
| 37 | |
|---|
| 38 | /*! |
|---|
| 39 | \addtogroup integration |
|---|
| 40 | \brief Numerical integration routines |
|---|
| 41 | */ |
|---|
| 42 | |
|---|
| 43 | //@{ |
|---|
| 44 | |
|---|
| 45 | /*! |
|---|
| 46 | 1-dimensional numerical Simpson quadrature integration |
|---|
| 47 | |
|---|
| 48 | Calculate the 1-dimensional integral |
|---|
| 49 | \f[ |
|---|
| 50 | \int_a^b f(x) dx |
|---|
| 51 | \f] |
|---|
| 52 | |
|---|
| 53 | Uses an adaptive Simpson quadrature method. See [Gander] for more |
|---|
| 54 | details. The integrand is specified as a function \code double |
|---|
| 55 | f(double) \endcode. |
|---|
| 56 | |
|---|
| 57 | Example: |
|---|
| 58 | \code |
|---|
| 59 | #include "itpp/itbase.h" |
|---|
| 60 | |
|---|
| 61 | double f(const double x) |
|---|
| 62 | { |
|---|
| 63 | return x*log(x); |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | int main() |
|---|
| 67 | { |
|---|
| 68 | double res = quad( f, 1.5, 3.5); |
|---|
| 69 | cout << "res = " << res << endl; |
|---|
| 70 | |
|---|
| 71 | return 0; |
|---|
| 72 | } |
|---|
| 73 | \endcode |
|---|
| 74 | |
|---|
| 75 | References: |
|---|
| 76 | |
|---|
| 77 | [Gander] Gander, W. and W. Gautschi, "Adaptive Quadrature - |
|---|
| 78 | Revisited", BIT, Vol. 40, 2000, pp. 84-101. |
|---|
| 79 | This document is also available at http://www.inf.ethz.ch/personal/gander. |
|---|
| 80 | */ |
|---|
| 81 | double quad(double (*f)(double), double a, double b, |
|---|
| 82 | double tol = std::numeric_limits<double>::epsilon()); |
|---|
| 83 | |
|---|
| 84 | /*! |
|---|
| 85 | 1-dimensional numerical adaptive Lobatto quadrature integration |
|---|
| 86 | |
|---|
| 87 | Calculate the 1-dimensional integral |
|---|
| 88 | \f[ |
|---|
| 89 | \int_a^b f(x) dx |
|---|
| 90 | \f] |
|---|
| 91 | |
|---|
| 92 | Uses an adaptive Lobatto quadrature method. See [Gander] for more |
|---|
| 93 | details. The integrand is specified as a function \code double |
|---|
| 94 | f(double) \endcode. |
|---|
| 95 | |
|---|
| 96 | Example: |
|---|
| 97 | \code |
|---|
| 98 | #include "itpp/itbase.h" |
|---|
| 99 | |
|---|
| 100 | double f(const double x) |
|---|
| 101 | { |
|---|
| 102 | return x*log(x); |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | int main() |
|---|
| 106 | { |
|---|
| 107 | double res = quadl( f, 1.5, 3.5); |
|---|
| 108 | cout << "res = " << res << endl; |
|---|
| 109 | |
|---|
| 110 | return 0; |
|---|
| 111 | } |
|---|
| 112 | \endcode |
|---|
| 113 | |
|---|
| 114 | References: |
|---|
| 115 | |
|---|
| 116 | [Gander] Gander, W. and W. Gautschi, "Adaptive Quadrature - |
|---|
| 117 | Revisited", BIT, Vol. 40, 2000, pp. 84-101. |
|---|
| 118 | This document is also available at http:// www.inf.ethz.ch/personal/gander. |
|---|
| 119 | */ |
|---|
| 120 | double quadl(double (*f)(double), double a, double b, |
|---|
| 121 | double tol = std::numeric_limits<double>::epsilon()); |
|---|
| 122 | |
|---|
| 123 | //@} |
|---|
| 124 | |
|---|
| 125 | } // namespace itpp |
|---|
| 126 | |
|---|
| 127 | #endif // #ifndef INTEGRATION_H |
|---|