00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include "GSLDerivator.h"
00033
00034 #include "GSLFunctionWrapper.h"
00035
00036 #include "gsl/gsl_deriv.h"
00037
00038
00039
00040 #include <iostream>
00041
00042 namespace ROOT {
00043 namespace Math {
00044
00045
00046
00047 double GSLDerivator::EvalCentral( double x, double h) {
00048
00049 if ( !fFunction.IsValid() ) {
00050 std::cerr << "GSLDerivator: Error : The function has not been specified" << std::endl;
00051 fStatus = -1;
00052 return 0;
00053 }
00054 fStatus = gsl_deriv_central( fFunction.GetFunc(), x, h, &fResult, &fError);
00055 return fResult;
00056 }
00057
00058 double GSLDerivator::EvalForward( double x, double h) {
00059
00060 if ( !fFunction.IsValid() ) {
00061 std::cerr << "GSLDerivator: Error : The function has not been specified" << std::endl;
00062 fStatus = -1;
00063 return 0;
00064 }
00065 fStatus = gsl_deriv_forward( fFunction.GetFunc(), x, h, &fResult, &fError);
00066 return fResult;
00067 }
00068
00069 double GSLDerivator::EvalBackward( double x, double h) {
00070
00071 if ( !fFunction.IsValid() ) {
00072 std::cerr << "GSLDerivator: Error : The function has not been specified" << std::endl;
00073 fStatus = -1;
00074 return 0;
00075 }
00076 fStatus = gsl_deriv_backward( fFunction.GetFunc(), x, h, &fResult, &fError);
00077 return fResult;
00078 }
00079
00080
00081 double GSLDerivator::EvalCentral(const IGenFunction & f, double x, double h) {
00082
00083 GSLFunctionWrapper gslfw;
00084 double result, error = 0;
00085 gslfw.SetFunction(f);
00086 gsl_deriv_central( gslfw.GetFunc(), x, h, &result, &error);
00087 return result;
00088 }
00089
00090 double GSLDerivator::EvalForward(const IGenFunction & f, double x, double h) {
00091
00092 GSLFunctionWrapper gslfw;
00093 double result, error = 0;
00094 gslfw.SetFunction(f);
00095 gsl_deriv_forward( gslfw.GetFunc(), x, h, &result, &error);
00096 return result;
00097 }
00098
00099 double GSLDerivator::EvalBackward(const IGenFunction & f, double x, double h) {
00100
00101 GSLFunctionWrapper gslfw;
00102 double result, error = 0;
00103 gslfw.SetFunction(f);
00104 gsl_deriv_backward( gslfw.GetFunc(), x, h, &result, &error);
00105 return result;
00106 }
00107
00108
00109 double GSLDerivator::Result() const { return fResult; }
00110
00111 double GSLDerivator::Error() const { return fError; }
00112
00113 int GSLDerivator::Status() const { return fStatus; }
00114
00115
00116
00117 void GSLDerivator::SetFunction( GSLFuncPointer fp, void * p) {
00118 fFunction.SetFuncPointer( fp );
00119 fFunction.SetParams ( p );
00120 }
00121
00122
00123 void GSLDerivator::SetFunction(const IGenFunction &f) {
00124 fFunction.SetFunction(f);
00125 }
00126
00127 }
00128 }