I have an algorithm that produces a set of real outputs given real inputs. For practical purposes, let's say I have two inputs and one output, and the algorithm can be represented by the function $\phi: \Re² \rightarrow \Re$.
I need to calculate $\frac{\partial^2 \phi(u_1,u_2)}{\partial u_1\partial u_2} \Bigr|_{\bar{u_1}\bar{u_2}}$ but I don't have an explicit formula for $\phi$. My only option is to run the algorithm to obtain the output given the input values.
My original idea was to run the program with a series of values around $\bar{u_1}$ and $\bar{u_2}$, then calculate $\frac{\partial \phi}{\partial u_1}$ at the different fixed $u_2$ values, and finally taking $\frac{\partial }{\partial u_2}$ to that (i.e. taking three values for $u_1$ and three for $u_2$ this would be running the algorithm for all the combinations $\{\bar{u_1} - \delta, \bar{u_1} , \bar{u_1} + \delta\} \times \{\bar{u_2} - \delta, \bar{u_2} , \bar{u_2} + \delta\}$, computing the derivative of $\phi$ with respect to $u_1$ for each of the three fixed $u_2$ values, and finally taking the derivative of that with respect to $u_2$ .)
However I notice that the calculated derivate depends heavily on the spacing between the values of the inputs $u_1$ and $u_2$ (i.e. $\delta$.) Moreover, I don't see it converging as I make the spacing smaller.
Is this a numerical problem or is it that the function is simply not differentiable? How can I tell?
In the following picture there's the resulting plot for $\delta = 0.01$ (left) and $\delta = 0.02$ (right). The derivative was calculated in $\texttt{R}$ using the $\texttt{splines}$ package.
EDIT: If I plot $\phi$ with 21 values for each independent variable I get,
With $\delta = 0.05$
With $\delta = 0.001$


