Loading [MathJax]/extensions/tex2jax.js
Logo ROOT   6.14/05
Reference Guide
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
GSLDerivator.cxx
Go to the documentation of this file.
1 // @(#)root/mathmore:$Id$
2 // Authors: L. Moneta, A. Zsenei 08/2005
3 
4  /**********************************************************************
5  * *
6  * Copyright (c) 2004 ROOT Foundation, CERN/PH-SFT *
7  * *
8  * This library is free software; you can redistribute it and/or *
9  * modify it under the terms of the GNU General Public License *
10  * as published by the Free Software Foundation; either version 2 *
11  * of the License, or (at your option) any later version. *
12  * *
13  * This library is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16  * General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this library (see file COPYING); if not, write *
20  * to the Free Software Foundation, Inc., 59 Temple Place, Suite *
21  * 330, Boston, MA 02111-1307 USA, or contact the author. *
22  * *
23  **********************************************************************/
24 
25 // Implementation file for class GSLDerivator
26 //
27 // Created by: moneta at Sat Nov 13 14:46:00 2004
28 //
29 // Last update: Sat Nov 13 14:46:00 2004
30 //
31 
32 #include "GSLDerivator.h"
33 
34 #include "GSLFunctionWrapper.h"
35 // for GSL greater then 1.5
36 #include "gsl/gsl_deriv.h"
37 // for OLD GSL versions
38 //#include "gsl/gsl_diff.h"
39 
40 #include <iostream>
41 
42 namespace ROOT {
43 namespace Math {
44 
45 
46 
47 double GSLDerivator::EvalCentral( double x, double h) {
48  // Central evaluation using previously set function
49  if ( !fFunction.IsValid() ) {
50  std::cerr << "GSLDerivator: Error : The function has not been specified" << std::endl;
51  fStatus = -1;
52  return 0;
53  }
54  fStatus = gsl_deriv_central( fFunction.GetFunc(), x, h, &fResult, &fError);
55  return fResult;
56 }
57 
58 double GSLDerivator::EvalForward( double x, double h) {
59  // Forward evaluation using previously set function
60  if ( !fFunction.IsValid() ) {
61  std::cerr << "GSLDerivator: Error : The function has not been specified" << std::endl;
62  fStatus = -1;
63  return 0;
64  }
65  fStatus = gsl_deriv_forward( fFunction.GetFunc(), x, h, &fResult, &fError);
66  return fResult;
67 }
68 
69 double GSLDerivator::EvalBackward( double x, double h) {
70  // Backward evaluation using previously set function
71  if ( !fFunction.IsValid() ) {
72  std::cerr << "GSLDerivator: Error : The function has not been specified" << std::endl;
73  fStatus = -1;
74  return 0;
75  }
76  fStatus = gsl_deriv_backward( fFunction.GetFunc(), x, h, &fResult, &fError);
77  return fResult;
78 }
79 
80 // static methods not requiring the function
81 double GSLDerivator::EvalCentral(const IGenFunction & f, double x, double h) {
82  // Central evaluation using given function
83  GSLFunctionWrapper gslfw;
84  double result, error = 0;
85  gslfw.SetFunction(f);
86  gsl_deriv_central( gslfw.GetFunc(), x, h, &result, &error);
87  return result;
88 }
89 
90 double GSLDerivator::EvalForward(const IGenFunction & f, double x, double h) {
91  // Forward evaluation using given function
92  GSLFunctionWrapper gslfw;
93  double result, error = 0;
94  gslfw.SetFunction(f);
95  gsl_deriv_forward( gslfw.GetFunc(), x, h, &result, &error);
96  return result;
97 }
98 
99 double GSLDerivator::EvalBackward(const IGenFunction & f, double x, double h) {
100  // Backward evaluation using given function
101  GSLFunctionWrapper gslfw;
102  double result, error = 0;
103  gslfw.SetFunction(f);
104  gsl_deriv_backward( gslfw.GetFunc(), x, h, &result, &error);
105  return result;
106 }
107 
108 
109 double GSLDerivator::Result() const { return fResult; }
110 
111 double GSLDerivator::Error() const { return fError; }
112 
113 int GSLDerivator::Status() const { return fStatus; }
114 
115 // fill GSLFunctionWrapper with the pointer to the function
116 
119  fFunction.SetParams ( p );
120 }
121 
122 
125 }
126 
127 } // namespace Math
128 } // namespace ROOT
double Result() const
return the result of the last derivative calculation
Interface (abstract class) for generic functions objects of one-dimension Provides a method to evalua...
Definition: IFunction.h:135
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
double EvalForward(double x, double h)
Computes the numerical derivative at a point x using an adaptive forward difference algorithm with a ...
#define f(i)
Definition: RSha256.hxx:104
void SetFunction(const FuncType &f)
fill the GSL C struct from a generic C++ callable object implementing operator()
void SetFunction(const IGenFunction &f)
Set the function for calculating the derivatives.
double EvalBackward(double x, double h)
Computes the numerical derivative at a point x using an adaptive backward difference algorithm with a...
Double_t x[n]
Definition: legend1.C:17
double Error() const
return the estimate of the absolute error of the last derivative calculation
double(* GSLFuncPointer)(double, void *)
Function pointer corresponding to gsl_function signature.
int Status() const
return the error status of the last integral calculation
bool IsValid()
check if function is valid (has been set)
#define h(i)
Definition: RSha256.hxx:106
GSLFunctionWrapper fFunction
Definition: GSLDerivator.h:165
void SetFuncPointer(GSLFuncPointer f)
set in the GSL C struct the pointer to the function evaluation
Namespace for new Math classes and functions.
Wrapper class to the gsl_function C structure.
double EvalCentral(double x, double h)
Computes the numerical derivative at a point x using an adaptive central difference algorithm with a ...
void SetParams(void *p)
set in the GSL C struct the extra-object pointer