This example show how to use the hydra::GaussKronrodAdaptiveQuadrature self-adaptive numerical integration algorithm to calculate the integral of a Gaussian.
#ifndef ADAPTIVE_GAUSS_KRONROD_INL_
#define ADAPTIVE_GAUSS_KRONROD_INL_
#include <iostream>
#include <assert.h>
#include <time.h>
#include <string>
#include <chrono>
#include <tclap/CmdLine.h>
{
double max_error = 0;
try {
TCLAP::CmdLine cmd("Command line arguments for vegas", '=');
TCLAP::ValueArg<double> MaxErrorArg("e", "max-error", "Maximum error.", false, 1.0e-3, "double");
cmd.add(MaxErrorArg);
max_error = MaxErrorArg.getValue();
}
catch (TCLAP::ArgException &e)
{
std::cerr << "error: " << e.error() << " for arg " << e.argId() << std::endl;
}
double f =
exp(-m2/(2.0 * s2 ))/(
sqrt(2.0*s2*
PI));
return f;
};
{
auto start = std::chrono::high_resolution_clock::now();
auto result = GKAQ61_d.Integrate(
gaussian);
auto end = std::chrono::high_resolution_clock::now();
std::cout << ">>>l [ Gauss-Kronrod 61 ]"<< std::endl;
std::cout << "Result: " << result.first << " +- " << result.second <<std::endl
<<
" Time (ms): "<<
elapsed.count() <<std::endl;
}
return 0;
}
#endif