I have observed something strange happening with the function ND[] from the package NumericalCalculus. In particular, if I define a function G that returns the numerical derivative of a compiled function f, like
f = Compile[{{x, _Real}}, x^2];
<< NumericalCalculus`
G[a_] := Module[{g}, g[x_?NumericQ] := f[x]; ND[g[x], x, a]];
and I try to use this function inside a ParallelTable[] or a Table[], like
ParallelTable[G[x], {x, 0.0, 10.0, 1.0}]
(* output: {1.`,1.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`} *)
Table[G[x], {x, 0.0, 10.0, 1.0}]
(* output {1.`,1.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`,0.`} *)
Map[G[#] &, Table[x, {x, 0.0, 10.0, 1.0}]]
(* output {0.`,2.`,4.`,6.`,8.`,10.`,12.`,14.`,16.`,18.`,20.`} *)
ParallelMap[G[#] &, Table[x, {x, 0.0, 10.0, 1.0}]]
(* output {0.`,2.`,4.`,6.`,8.`,10.`,12.`,14.`,16.`,18.`,20.`} *)
I get wrong results (as compared to the use of Map[] or ParallelMap[] that give the predicted numbers). Can you help me with this? I have Mathematica 14.1
Table[G[a], {a, 0, 10, 1}]
$\endgroup$