#include <iostream>
#include <o2scl/constants.h>
#include <o2scl/test_mgr.h>
#include <o2scl/cheb_approx.h>
#include <o2scl/deriv_cern.h>
#include <o2scl/inte_qag_gsl.h>
using namespace std;
double func(double x) {
return sin(1.0/(x+0.08));
}
double dfunc(double x) {
return -cos(1.0/(x+0.08))/pow(x+0.08,2.0);
}
int main(void) {
cout.setf(ios::scientific);
double res, err;
double x0=0.55;
cout << "f(0.55)" << endl;
cout << "Exact : " << func(x0) << endl;
cout << "Approx (n=100): " << res << endl;
cout << " Est. Error : " << err << endl;
cout << " Act. Error : " << fabs(res-func(x0)) << endl;
cout << "Approx (n=50) : " << res << endl;
cout << " Est. Error : " << err << endl;
cout << " Act. Error : " << fabs(res-func(x0)) << endl;
cout << "Approx (n=25) : " << res << endl;
cout << " Est. Error : " << err << endl;
cout << " Act. Error : " << fabs(res-func(x0)) << endl;
cout << endl;
cout <<
"Using operator=(): " << gc2.
eval(x0) <<
" " << func(x0) << endl;
cout << endl;
cout << "f'(0.55)" << endl;
cout << "Exact : " << dfunc(x0) << endl;
cout << "Approx (n=100): " << res << endl;
cout << " Est. Error : " << err << endl;
cout << " Act. Error : " << fabs(res-dfunc(x0)) << endl;
cout << "Direct deriv : " << res << endl;
cout << " Est. Error : " << err << endl;
cout << " Act. Error : " << fabs(res-dfunc(x0)) << endl;
cout << endl;
t.
test_abs(res,dfunc(x0),1.0e-12,
"deriv with deriv_cern");
t.
test_abs(gc_deriv.
eval(x0),dfunc(x0),5.0e-3,
"deriv with cheb");
cout << "int(f,0,0.55)" << endl;
cout << "Approx (n=100): " << res << endl;
cout << " Est. Error : " << err << endl;
cout << "Direct integ : " << res << endl;
cout << " Est. Error : " << err << endl;
cout <<
"Rel. Error : " << fabs(res-gc_integ.
eval(x0)) << endl;
cout << endl;
write_file(gc);
return 0;
}