23 std::valarray<Scalar> c;
33 static std::map<std::tuple<int, int>, DiffCoeffs> CentralDiffCoeffs = {
34 {{1, 2}, {{-1,1}, {-r(1)/r(2), r(1)/r(2)}} },
35 {{1, 4}, {{-2,-1,1,2}, {r(1)/ r(12), -r(2)/r(3), r(2)/r(3), -r(1)/r(12)}} },
36 {{1, 6}, {{-3,-2,-1,1,2,3}, {-r(1)/r(60), r(3)/r(20), -r(3)/r(4), r(3)/r(4), -r(3)/r(20), r(1)/r(60)}} },
38 {{2, 2}, {{-1,0,1}, {1, -2, 1} }},
39 {{2, 4}, {{-2,-1,0,1,2}, {r(-1)/r(12), r(4)/r(3), r(-5)/r(2), r(4)/r(3), r(-1)/r(12)}} },
40 {{2, 6}, {{-3,-2,-1,0,1,2,3}, {r(1)/r(90), r(-3)/r(20), r(3)/r(2), r(-49)/r(18), r(3)/r(2), r(-3)/r(20), r(1)/r(90)}} },
42 {{3, 2}, {{-2, -1, 0, 1, 2}, {r(-1)/r(2), r(1), 0, r(-1), r(1)/r(2)}} },
43 {{3, 4}, {{-3,-2,-1,0,1,2,3}, {r(1)/r(8), r(-1), r(13)/r(8), 0, r(-13)/r(8), r(1), r(-1)/r(8)}} },
44 {{3, 6}, {{-4,-3,-2,-1,0,1,2,3,4}, {r(-7)/r(240), r(3)/r(10), r(-169)/r(120), r(61)/r(30), 0, r(-61)/r(30), r(169)/r(120), r(-3)/r(10), r(7)/r(240)}} },
46 {{4, 2}, {{-2,-1,0,1,2}, {1,-4,6,-4,1}} },
47 {{4, 4}, {{-3,-2,-1,0,1,2,3}, {-r(1)/r(6), r(2), -r(13)/r(2), r(28)/r(3.0), -r(13)/r(2), r(2), -r(1)/r(6)}} },
48 {{4, 6}, {{-4,-3,-2,-1,0,1,2,3,4}, {r(7)/r(240), -r(2)/r(5), r(169)/r(60), -r(122)/r(15), r(91)/r(8), -r(122)/r(15), r(169)/r(60), -r(2)/r(5), r(7)/r(240)}} },
51 auto [k, c] = CentralDiffCoeffs[std::make_tuple(Nderiv, Norder)];
53 throw std::invalid_argument(
"Cannot obtain the necessary finite differentiation coefficients");
56 if (c.size() != k.size()) {
57 throw std::invalid_argument(
"Finite differentiation coefficient arrays not the same size");
60 for (
auto i = 0U; i < k.size(); ++i) {
61 num = num + c[i]*f(x + h*k[i]);
63 auto val = num /
pow(h, Nderiv);