Commit d93a02e8 authored by Davis King's avatar Davis King

Minor cleanup

parent 8b6cd008
// The contents of this file are in the public domain. See // The contents of this file are in the public domain. See LICENSE_FOR_EXAMPLE_PROGRAMS.txt
// LICENSE_FOR_EXAMPLE_PROGRAMS.txt
/* /*
This example demonstrates the usage of the numerical quadrature function This example demonstrates the usage of the numerical quadrature function
integrate_function_adapt_simpson. This function takes as input a single variable integrate_function_adapt_simp(). This function takes as input a single variable
function, the endpoints of a domain over which the function will be integrated, and a function, the endpoints of a domain over which the function will be integrated, and a
tolerance parameter. It outputs an approximation of the integral of this function tolerance parameter. It outputs an approximation of the integral of this function over
over the specified domain. The algorithm is based on the adaptive Simpson method outlined in: the specified domain. The algorithm is based on the adaptive Simpson method outlined in:
Numerical Integration method based on the adaptive Simpson method in Numerical Integration method based on the adaptive Simpson method in
Gander, W. and W. Gautschi, "Adaptive Quadrature – Revisited," Gander, W. and W. Gautschi, "Adaptive Quadrature – Revisited,"
BIT, Vol. 40, 2000, pp. 84-101 BIT, Vol. 40, 2000, pp. 84-101
*/ */
...@@ -24,40 +22,39 @@ ...@@ -24,40 +22,39 @@
using namespace std; using namespace std;
using namespace dlib; using namespace dlib;
// Here we define a class that consists of the set of functions that we // Here we the set of functions that we wish to integrate and comment in the domain of
// wish to integrate and comment in the domain of integration. // integration.
// x in [0,1] // x in [0,1]
static double gg1(double x) double gg1(double x)
{ {
return pow(e,x); return pow(e,x);
} }
// x in [0,1] // x in [0,1]
static double gg2(double x) double gg2(double x)
{ {
return x*x; return x*x;
} }
// x in [0, pi] // x in [0, pi]
static double gg3(double x) double gg3(double x)
{ {
return 1/(x*x + cos(x)*cos(x)); return 1/(x*x + cos(x)*cos(x));
} }
// x in [-pi, pi] // x in [-pi, pi]
static double gg4(double x) double gg4(double x)
{ {
return sin(x); return sin(x);
} }
// x in [0,2] // x in [0,2]
static double gg5(double x) double gg5(double x)
{ {
return 1/(1 + x*x); return 1/(1 + x*x);
} }
// Examples
int main() int main()
{ {
// We first define a tolerance parameter. Roughly speaking, a lower tolerance will // We first define a tolerance parameter. Roughly speaking, a lower tolerance will
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment