# Discrete numerical derivative with respect to d/d(n*x)

How can I generate a stencil for a d/d(n*x) operator?

I am writing a program that needs a method to calculate line derivatives in an image. If we want to calculate the simplest forward derivative approximation with regards to d/dx, we can run the following operation:

diff[x] = -1.0 * image[x] + image[x+1]

If I want a more precise calculation of the derivative, I can increase the size of the stencil, and possibly recalculate as:

diff[x] = -3./2 * image[x] + 2*image[x+1] - 1./2 * image[x+2]

I have been using the finite difference method in obtaining these coefficients (specifically http://en.wikipedia.org/wiki/Finite_difference_coefficients )

Now suppose I want to take the derivative in regards to d/d(3*x), I could simply stretch the original stencil like this:

diff[x] = -1.0 * image[x] + image[x+3]

However, here I am not using the information from image[x+1] and image[x+2] and so the derivative approximation can be greatly improved. How can I generate a stencil that WILL use this information and hence be more accurate?

-
It really helps to format your questions in LaTex / mathjax. Helps readability and helps illicit more responses. There is guidance on the FAQ. Regards – Amzoti Mar 11 '13 at 12:51
Thanks, when I have time, I will improve it. – Boyko Perfanov Mar 11 '13 at 13:07

Let's give the name $f$ to the function we're trying to differentiate. If I understand correctly, you are trying to estimate $\tfrac{df}{d(3x)}$ using finite differences.
It's not really clear what $\tfrac{df}{d(3x)}$ means. Let's assumee that it means $\tfrac{df}{du}$, where $u = 3x$.
$$\frac{df}{d(3x)} = \frac{df}{du} = \frac{df}{dx}\frac{dx}{du} = \frac13\frac{df}{dx}$$
So, you can use the finite-difference formulae you read about for computing $\tfrac{df}{dx}$