In my efforts to write a code for a calculation I have encountered a problem of numerically differentiating a non-linear function at different points on a grid. I used the simple forward finite difference method to differentiate the function but the errors were huge in case when I know the analytical solution of the calculation.
So to better understand the problem I numerically differentiated $f(x)=1/x$ since the analytical solution is known to be $f'(x)/=-1/x^2$. So I tried to calculate the error between numerical and analytical derivative of $f(x)$ and plot the error against the step size for various values of $x$. The result is attached as a picture(Both axes are logarithmic!).
It appears from the graph the error is significant event for the smallest value of stepsize when $x$ is small. That makes sense to me now because a straight line approximation would fail as the function becomes more and more non-linear with decreasing $x$.
So my question is, is there a better way of numerically differentiating a non-linear function on the domain of the function other than the finite difference method? The function(s) that I need to numerically differentiate are multivariable functions but the method can be easily extended from univariable functions to multivariable function I suppose.