19 void Qfn(
const double &x,
double &
f )
21 f = std::cos( x ) * std::exp( -x / 4. );
45 cout <<
"=== Quadrature: integral of cos(x)exp(-x/4) =========\n";
54 const double exact = ( 4. / 17. ) * ( exp( 5.0 ) - cos( 20.0 ) + 4 * sin( 20.0 ) ) * exp( -5.0 );
55 const double tol = 1.e-7;
56 cout <<
" Tolerance used : " << tol <<
"\n";
58 cout <<
" Trapezium summation \n";
65 cout <<
"n = " << n <<
" Integral error = " << abs( result ) <<
"\n";
69 while ( ( abs( result ) > tol ) && !Example::failed );
71 cout <<
" required " << n / 2 <<
" sub-intervals. \n";
73 cout <<
" Sub_Gauss with 1 Guass point \n";
80 cout <<
"n = " << n <<
" Integral error = " << abs( result ) <<
"\n";
84 while ( ( abs( result ) > tol ) && !Example::failed );
86 cout <<
" required " << n / 2 <<
" sub-intervals. \n";
88 cout <<
" Sub_Gauss with 2 Guass points \n";
95 cout <<
"n = " << n <<
" Integral error = " << abs( result ) <<
"\n";
99 while ( ( abs( result ) > tol ) && !Example::failed );
101 cout <<
" required " << n / 2 <<
" sub-intervals. \n";
103 cout <<
" Sub_Gauss with 3 Guass points \n";
110 cout <<
"n = " << n <<
" Integral error = " << abs( result ) <<
"\n";
114 while ( ( abs( result ) > tol ) && !Example::failed );
116 cout <<
" required " << n / 2 <<
" sub-intervals. \n";
118 if ( Example::failed )
120 cout <<
"\033[1;31;48m * FAILED \033[0m\n";
125 cout <<
"\033[1;32;48m * PASSED \033[0m\n";
A specification for quadrature classes.
A shorter bundled include file for ODE_BVP and PDE_IBVP codes.
A quadrature class that takes a function pointer.
double sub_Gauss(const int &n)
Evaluate the integral by applying an n-point Gauss rule on each of N sub-intervals.
void set_subintervals(const unsigned &n)
A set method to define a UNIFORM number of sub intervals.
double trapezium()
Quick trapezium summation again for sanity checking.
void Qfn(const double &x, double &f)
The function that defines the integrand.
void test(unsigned n)
The test will fail if it requires more than a set number of subintervals in the integration to conver...
A collection of OO numerical routines aimed at simple (typical) applied problems in continuum mechani...