SourceXtractorPlusPlus
0.11
Please provide a description of the project.
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
SEUtils
SEUtils
NumericalDerivative.h
Go to the documentation of this file.
1
17
/*
18
* NumericalDerivative.h
19
*
20
* Created on: Sep 17, 2019
21
* Author: mschefer
22
*/
23
24
#ifndef _SEUTILS_NUMERICALDERIVATIVE_H_
25
#define _SEUTILS_NUMERICALDERIVATIVE_H_
26
27
#include <functional>
28
29
namespace
SourceXtractor {
30
31
class
NumericalDerivative
{
32
public
:
33
34
static
double
centralDifference
(
std::function
<
double
(
double
)> f,
double
x
) {
35
double
h = 1
e
-6;
36
37
// we need to consider that the rounding of those values could generate bad accuracy
38
// so rather than using 2. * h, we have to use the actual difference
39
// marked "volatile" to avoid possible compiler optimizations ruining this scheme
40
volatile
double
x_plus = x + h;
41
volatile
double
x_minus = x - h;
42
double
h_2 = x_plus - x_minus;
43
44
return
(f(x_plus) - f(x_minus)) / h_2;
45
}
46
47
};
48
49
50
}
// end SourceXtractor
51
52
#endif
/* _SEUTILS_NUMERICALDERIVATIVE_H_ */
SourceXtractor::NumericalDerivative
Definition:
NumericalDerivative.h:31
std::function
x
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > x
Definition:
MoffatModelFittingTask.cpp:93
e
constexpr double e
SourceXtractor::NumericalDerivative::centralDifference
static double centralDifference(std::function< double(double)> f, double x)
Definition:
NumericalDerivative.h:34
Generated by
1.8.5