SourceXtractorPlusPlus
0.16
Please provide a description of the project.
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_ */
x
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > x
Definition:
MoffatModelFittingTask.cpp:94
SourceXtractor::NumericalDerivative
Definition:
NumericalDerivative.h:31
SourceXtractor::NumericalDerivative::centralDifference
static double centralDifference(std::function< double(double)> f, double x)
Definition:
NumericalDerivative.h:34
std::function
e
constexpr double e
SourceXtractor
Definition:
Aperture.h:30
Generated by
1.9.1