#include <iostream>
#include <cmath>
int main()
{
std::cout << "- 1D integration" << std::endl;
std::cout << "True value: " << 2 * ( log(2) - 1 ) << std::endl;
const double res1 = fGL.integrate(0, 2, 1e-5);
const double res2 = fGL.integrate(0, 2, 1e-3);
std::cout << "Gauss-Legendre: " << res1 << " " << res2 << " " << res1 / res2 << std::endl;
const double res6 = fGK.integrate(0, 2, 1e-5);
const double res7 = fGK.integrate(0, 2, 1e-3);
std::cout << "Gauss-Kronrod: " << res6 << " " << res7 << " " << res6 / res7 << std::endl;
const double res4 = fGK.integrate(0, 2, 1e-5);
const double res5 = fGK.integrate(0, 2, {-1, 0.1, 0.5, 0.7, 1.1, 3.4}, 1e-5);
std::cout << "W/o and w/ fixed points: " << res4 << " " << res5 << " " << res4 / res5 << std::endl;
int k = 10000;
std::cout << "Integrating " << k << " times with Gauss-Legendre... ";
for (int i = 0; i < k; i++)
fGL.integrate(0, 2, 1e-12);
std::cout << "Integrating " << k << " times with Gauss-Kronrod... ";
for (int i = 0; i < k; i++)
fGK.integrate(0, 2, 1e-12);
std::cout << "\n- 2D integration" << std::endl;
std::cout << "True value: " << 4 * pow(log(2) - 1, 2) << std::endl;
const double res2d1 = f2dGL.integrate(0, 2, 0, 2, 1e-7);
const double res2d2 = f2dGL.integrate(0, 2, 0, 2, 1e-3);
std::cout << "Gauss-Legendre: " << res2d1 << " " << res2d2 << " " << res2d1 / res2d2 << std::endl;
const double res2d3 = f2dGK.integrate(0, 2, 0, 2, 1e-7);
const double res2d4 = f2dGK.integrate(0, 2, 0, 2, 1e-3);
std::cout << "Gauss-Kronrod: " << res2d3 << " " << res2d4 << " " << res2d3 / res2d4 << std::endl;
{
return fin.integrate(0, 2, 1e-7);
}
};
const double res2d5 = fnest1.integrate(0, 2, 1e-7);
{
return fin.integrate(0, 2, 1e-3);
}
};
const double res2d6 = fnest2.integrate(0, 2, 1e-3);
std::cout << "Nested: " << res2d5 << " " << res2d6 << " " << res2d5 / res2d6 << std::endl;
k = 100;
std::cout << "Integrating " << k << " times with Gauss-Legendre... ";
for (int i = 0; i < k; i++)
f2dGL.integrate(0, 2, 0, 2, 1e-7);
std::cout << "Integrating " << k << " times with Gauss-Kronrod... ";
for (int i = 0; i < k; i++)
f2dGK.integrate(0, 2, 0, 2, 1e-7);
std::cout << "Integrating " << k << " times with nested function... ";
for (int i = 0; i < k; i++)
fnest1.integrate(0, 2, 1e-7);
return 0;
}
The Integrator2D class performs two-dimensional numerical integrations using the Guassian quadrature.
Definition integrator2d.h:18
The Integrator class performs unidimensional numerical integrations using the Guassian quadrature.
Definition integrator.h:19
@ GAUSS_LEGENDRE
Definition integrator.h:25
@ GAUSS_KRONROD
Definition integrator.h:25
The Timer class computes the time elapsed between start and stop.
Definition timer.h:20
void stop(bool const &ForceDisplay=false)
This function stops the timer and reports the elapsed time in seconds since the last time the timer w...
Definition timer.h:36
void start()
This function starts the timer.
Definition timer.h:30