24#pragma push_macro("BOOST_DISABLE_ASSERTS")
25#ifndef BOOST_DISABLE_ASSERTS
26#define BOOST_DISABLE_ASSERTS
28#include <boost/multi_array.hpp>
29#pragma pop_macro("BOOST_DISABLE_ASSERTS")
38 QL_REQUIRE(
n > 1,
"number of steps must be greater than one");
44 "number of steps must be an odd number greater than two");
49 for (
Size i=0; i <
n; ++i)
53 for (
Size i=0; i <
n; ++i)
57 QL_FAIL(
"unknown numerical differentiation scheme");
67 Array calcWeights(
const Array& x,
Size M) {
68 const Size N = x.size();
69 QL_REQUIRE(N > M,
"number of points must be greater "
70 "than the order of the derivative");
72 boost::multi_array<Real, 3>
d(boost::extents[M+1][N][N]);
82 for (
Size m=0; m <= std::min(
n, M); ++m) {
84 - ((m > 0)?
Real(m*
d[m-1][
n-1][
nu]) : 0.0))/c3;
88 for (
Size m=0; m <= M; ++m) {
89 d[m][
n][
n] = c1/c2*( ((m > 0)?
Real(m*
d[m-1][
n-1][
n-1]) : 0.0) -
90 x[
n-1]*
d[m][
n-1][
n-1] );
97 for (
Size i=0; i < N; ++i) {
98 retVal[i] =
d[M][N-1][i];
105 Size orderOfDerivative,
107 : offsets_(
std::move(x_offsets)), w_(calcWeights(offsets_, orderOfDerivative)),
112 Size orderOfDerivative,
116 : offsets_(calcOffsets(stepSize, steps, scheme)), w_(calcWeights(offsets_, orderOfDerivative)),
1-D array used in linear algebra.
NumericalDifferentiation(ext::function< Real(Real)> f, Size orderOfDerivative, Array x_offsets)
ext::function< Real(Real)> f_
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
#define QL_FAIL(message)
throw an error (possibly with file and line information)
QL_INTEGER Integer
integer number
std::size_t Size
size of a container
numerical differentiation of arbitrary order and on irregular grids