Logo ROOT   6.18/05
Reference Guide
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
42namespace ROOT {
43namespace Math {
44
45
46
47double 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
58double 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
69double 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
81double GSLDerivator::EvalCentral(const IGenFunction & f, double x, double h) {
82 // Central evaluation using given function
84 double result, error = 0;
85 gslfw.SetFunction(f);
86 gsl_deriv_central( gslfw.GetFunc(), x, h, &result, &error);
87 return result;
88}
89
90double GSLDerivator::EvalForward(const IGenFunction & f, double x, double h) {
91 // Forward evaluation using given function
93 double result, error = 0;
94 gslfw.SetFunction(f);
95 gsl_deriv_forward( gslfw.GetFunc(), x, h, &result, &error);
96 return result;
97}
98
99double 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
109double GSLDerivator::Result() const { return fResult; }
110
111double GSLDerivator::Error() const { return fError; }
112
113int 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
#define f(i)
Definition: RSha256.hxx:104
#define h(i)
Definition: RSha256.hxx:106
void SetFunction(const IGenFunction &f)
Set the function for calculating the derivatives.
double Result() const
return the result of the last derivative calculation
double EvalForward(double x, double h)
Computes the numerical derivative at a point x using an adaptive forward difference algorithm with a ...
double EvalCentral(double x, double h)
Computes the numerical derivative at a point x using an adaptive central difference algorithm with a ...
GSLFunctionWrapper fFunction
Definition: GSLDerivator.h:165
double Error() const
return the estimate of the absolute error of the last derivative calculation
int Status() const
return the error status of the last integral calculation
double EvalBackward(double x, double h)
Computes the numerical derivative at a point x using an adaptive backward difference algorithm with a...
Wrapper class to the gsl_function C structure.
void SetFunction(const FuncType &f)
fill the GSL C struct from a generic C++ callable object implementing operator()
void SetFuncPointer(GSLFuncPointer f)
set in the GSL C struct the pointer to the function evaluation
void SetParams(void *p)
set in the GSL C struct the extra-object pointer
bool IsValid()
check if function is valid (has been set)
Interface (abstract class) for generic functions objects of one-dimension Provides a method to evalua...
Definition: IFunction.h:135
Double_t x[n]
Definition: legend1.C:17
Namespace for new Math classes and functions.
double(* GSLFuncPointer)(double, void *)
Function pointer corresponding to gsl_function signature.
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21