26 std::valarray<Scalar> c;
36 static std::map<std::tuple<int, int>, DiffCoeffs> CentralDiffCoeffs = {
37 {{1, 2}, {{-1,1}, {-r(1)/r(2), r(1)/r(2)}} },
38 {{1, 4}, {{-2,-1,1,2}, {r(1)/ r(12), -r(2)/r(3), r(2)/r(3), -r(1)/r(12)}} },
39 {{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)}} },
41 {{2, 2}, {{-1,0,1}, {1, -2, 1} }},
42 {{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)}} },
43 {{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)}} },
45 {{3, 2}, {{-2, -1, 0, 1, 2}, {r(-1)/r(2), r(1), 0, r(-1), r(1)/r(2)}} },
46 {{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)}} },
47 {{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)}} },
49 {{4, 2}, {{-2,-1,0,1,2}, {1,-4,6,-4,1}} },
50 {{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)}} },
51 {{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)}} },
54 auto [k, c] = CentralDiffCoeffs[std::make_tuple(Nderiv, Norder)];
56 throw std::invalid_argument(
"Cannot obtain the necessary finite differentiation coefficients");
59 if (c.size() != k.size()) {
60 throw std::invalid_argument(
"Finite differentiation coefficient arrays not the same size");
63 for (
auto i = 0U; i < k.size(); ++i) {
64 num = num + c[i]*f(x + h*k[i]);
66 auto val = num /
pow(h, Nderiv);