1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
#include "Function.hxx" //it already include BaseFunction.hxx
#include "MiddlePoint.hxx" //it already include Integrator.hxx
#include<iostream>
#include<iomanip>
#include<assert.h>
#include<cmath>
int main () {
//assert
Sine sine_test ( 1., 0, 0, 1. ) ;
MiddlePoint Test ( &sine_test ) ;
//m_h class member is fine...
assert ( std::fabs( Test.Integral_Eval ( 0, 1 , 10 ) - 0.45988929071851814 ) < 1.e-7 ) ;
assert ( std::fabs( Test.Integral_Eval ( 1, 2 , 30 ) - 0.9564934239032155 ) < 1.e-7 ) ;
//m_h class member is wrong!! WHY?!
std::cout << Test.Integral_Eval ( M_PI, 0 , 10 ) << std::endl << Test.getH() << std::endl;
//assert ( std::fabs( Test.Integral_Eval ( M_PI, 0 , 10 ) + 2.0082484079079745 ) < 1.e-7 ) ;
std::cout << Test.Integral_Eval ( 0, M_PI , 100 ) << std::endl << Test.getH() << std::endl;
//assert ( std::fabs( Test.Integral_Eval ( 0, M_PI , 100 ) + 2.000082249070986 ) < 1.e-7 ) ;
//1
std::cout << "evaluation of the integral of sin(x) between 0, pi\n" ;
double a {} ;
double b { M_PI } ;
Sine sine ( 1., 0, 0, 1. ) ; //sin(x)
BaseFunction* f = &sine ;
MiddlePoint M ( a, b, 10 ) ;
double integral = M.Integral_Eval ( f ) ;
std::cout << std::fixed ;
std::cout << std::setprecision( 10 ) << integral << std::endl ;
//2
a = 0 ;
b = 1 ;
MiddlePoint A ( a, b, 10 ) ;
integral = A.Integral_Eval ( f ) ;
assert ( std::fabs( integral - 0.45988929071851814 ) < 1.e-7 ) ;
std::cout << "evaluation of the integral of sin(x) between 0, 1\n" ;
std::cout << integral << std::endl ;
//3
a = 1 ;
b = 2 ;
MiddlePoint B ( a, b, 30 ) ;
integral = B.Integral_Eval ( &sine ) ;
assert ( std::fabs( integral - 0.9564934239032155 ) < 1.e-7 ) ;
std::cout << "evaluation of the integral of sin(x) between 0, 1\n" ;
std::cout << integral << std::endl ;
//4
a = M_PI ;
b = 0 ;
MiddlePoint C ( a, b, 10 ) ;
integral = C.Integral_Eval ( f ) ;
std::cout << "evaluation of the integral of sin(x) between pi, 0\n" ;
std::cout << integral << std::endl ;
}
|