37 #define G_ROMBERG1 "GIntegrals::romberg(std::vector<double>, int&)"
38 #define G_ROMBERG2 "GIntegrals::romberg(double&, double&, int&)"
39 #define G_GAUSS_KRONROD "GIntegrals::gauss_kronrod(double&, double&)"
40 #define G_TRAPZD "GIntegrals::trapzd(double&, double&, int&, GVector)"
41 #define G_POLINT "GIntegrals::polint(double*, GVector*, int, int, double, "\
139 if (
this != &integrals) {
214 std::string msg =
"Function kernels not set. Please set function "
215 "kernels before calling the method.";
220 std::sort(bounds.begin(), bounds.end());
229 for (
int i = 0; i < bounds.size()-1; ++i) {
230 result +=
romberg(bounds[i], bounds[i+1], order);
269 std::string msg =
"Function kernels not set. Please set function "
270 "kernels before calling the method.";
287 bool converged =
false;
295 if (order > max_iter) {
296 std::string msg =
"Requested integration order "+
298 "maximum number of iterations "+
300 "integration order or increase the (maximum) "
301 "number of iterations.";
306 double* h =
new double[max_iter+2];
320 #if defined(G_NAN_CHECK)
322 m_message =
"*** ERROR: GIntegrals::romberg"
333 if (m_iter >= order) {
336 result =
polint(&h[m_iter-order], &s[m_iter-order], order, 0.0, &dss);
342 if (m_iter == max_iter) {
351 for (
int i = 0; i < result.size(); ++i) {
368 for (
int i = 0; i < result.size(); ++i) {
369 double abs_result =
std::abs(result[i]);
370 if (abs_result > 0.0) {
384 h[m_iter+1] = 0.25 * h[
m_iter];
396 " exceeds absolute tolerance of "+
399 result.print()+
" is inaccurate.";
401 std::string origin =
"GIntegrals::romberg("+
453 const GVector& previous_result)
457 std::string msg =
"Function kernels not set. Please set function "
458 "kernels before calling the method.";
486 for (
int j = 1; j < n-1; ++j) {
498 ", result="+previous_result.
print()+
499 ". Looks like n is too large.";
506 double tnm = double(it);
507 double del = (b-a)/tnm;
517 ", result="+previous_result.
print()+
518 ". Step is too small to make sense.";
528 double x = a + 0.5 * del;
531 for (
int j = 0; j < it; ++j, x += del) {
543 result += previous_result;
581 result.append(
"=== GIntegrals ===");
599 result.append(
" (fixed: ");
604 result.append(
" (maximum: ");
612 result.append(
"Result accurate.");
622 result.append(
"in standard output");
725 int nsize = ya->
size();
731 double* c =
new double[order];
732 double* d =
new double[order];
737 for (
int i = 1; i < order; ++i) {
746 for (
int index = 0; index < nsize; ++index) {
752 for (
int i = 0; i < order; ++i) {
753 double value = ya[i+1][index];
759 y[index] = ya[ns+1][index];
763 for (
int m = 1; m < order; ++m) {
766 for (
int i = 0; i < order-m; ++i) {
767 double ho = xa[i+1] - x;
768 double hp = xa[i+m+1] - x;
769 double w = c[i+1] - d[i];
770 double den = ho - hp;
774 " encountered. Two values in xa array are"
786 double delta_y = (2*(ns+1) < (order-m)) ? c[ns+1] : d[ns--];
792 (*dy)[index] = delta_y;
const bool & silent(void) const
Get silence flag.
GIntegrals(void)
Void constructor.
void warning(const std::string &origin, const std::string &message)
Emits warning.
virtual ~GIntegrals(void)
Destructor.
GVector abs(const GVector &vector)
Computes absolute of vector elements.
void init_members(void)
Initialise class members.
int m_iter
Number of iterations used.
int m_fix_iter
Fixed number of iterations.
void copy_members(const GIntegrals &integral)
Copy class members.
GIntegrals & operator=(const GIntegrals &integral)
Assignment operator.
const GFunctions * kernels(void) const
Get function kernels.
bool m_isvalid
Integration result valid (true=yes)
void clear(void)
Clear integral.
virtual GVector eval(const double &x)=0
int m_max_iter
Maximum number of iterations.
double m_eps
Requested relative integration precision.
bool m_silent
Suppress integration warnings in console.
bool m_has_relerr
Has relative integration errors.
void clear(void)
Clear vector.
bool is_notanumber(const double &x)
Signal if argument is not a number.
bool is_infinite(const double &x)
Signal if argument is infinite.
Single parameter functions abstract base class definition.
std::string print(const GChatter &chatter=NORMAL) const
Print integral information.
const int & calls(void) const
Get number of function calls.
Integration class for set of functions interface definition.
GFunctions * m_kernels
Pointer to function kernels.
const bool & is_valid(void) const
Signal if integration result is valid.
virtual int size(void) const =0
GIntegrals * clone(void) const
Clone integral.
int m_calls
Number of function calls used.
void free_members(void)
Delete class members.
GVector m_relerr
Absolute integration errors.
std::string m_message
Status message (if result is invalid)
const int & fixed_iter(void) const
Return fixed number of iterations.
const int & iter(void) const
Return number of iterations.
bool m_has_abserr
Has absolute integration errors.
const int & max_iter(void) const
Return maximum number of iterations.
GVector romberg(std::vector< double > bounds, const int &order=5)
Perform Romberg integration.
Exception handler interface definition.
GVector trapzd(const double &a, const double &b, const int &n, const GVector &previous_result)
Perform Trapezoidal integration for a set of functions.
const int & size(void) const
Return size of vector.
std::string print(const GChatter &chatter=NORMAL) const
Print vector information.
GVector polint(const double *xa, const GVector *ya, const int &order, const double &x, GVector *dy)
Perform Polynomial interpolation.
Integration class for set of functions.
std::string parformat(const std::string &s, const int &indent=0)
Convert string in parameter format.
GVector m_abserr
Absolute integration errors.
const double & eps(void) const
Get relative precision.
const std::string & message(void) const
Return integration status message.
Single parameter functions abstract base class.
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.