Since you say that you have a 2-D array of points, I assume that you have a function of two variables f(x, y) . This means that you do not have a single derivative. Instead, you get a set of private derivatives.
You can approximate partial derivatives using finite difference formulas.
The partial derivative with x to x for f(x, y) is (f(x+h, y) - f(xh, y))/2h .
The partial derivative with respect to y for f(x, y) is (f(x, y+h) - f(x, yh))/2h .
In these formulas, h is the space between the nodes on your grid, if you have a grid with regular spacing. If the horizontal and vertical distances are different, use the horizontal distance for partial with respect to x and the vertical distance for partial with respect to y .
Update . I misunderstood your question. I thought a 2-D array is an array of domain values. If you have a list of x and f(x) , you can approach f'(x) as (f(x+h) - f(xh)) / 2h . This will work everywhere except the first and last, where one of the conditions will be out of range. You can use (f(x + h) - f(x))/h at the left end and (f(x) - f(xh))/h at the right end. At endpoints, the approximation will be less accurate, but this cannot be avoided.
John D. Cook
source share