"Cristiano Strieder" <cstrieder@gmail.com> wrote in message <i7oraf$qvh$1@fred.mathworks.com>...
> Hi,
>
> what is the numerical error when using the function [FX,FY]=gradient(F)?
        
For points not on the edge of the matrix, with xintervals all equal, and likewise for the yintervals, the gradient function gives
FX(i,j) = (F(i,j+1)F(i,j1))/(2*dx)
FY(i,j) = (F(i+1,j)F(i1,j))/(2*dy)
This is a second order type of approximation. The mean value theorem of calculus states that the error between these approximations and the actual partial derivative values are, for FX, equal to dx^2/6 times the third partial derivative with respect to x of F at some point between F(i,j+1) and F(i,j1) and analogously for FY. That means for a smooth function with reasonablybehaved third derivatives, the error is proportional to the square of the the size of the steps in each direction.
However, for unequal intervals no attempt is made to alter the basic formula:
FX(i,j) = (F(i,j+1)F(i,j1))/(X(j+1)X(j1))
FY(i,j) = (F(i+1,j)F(i1,j))/(Y(j+1)Y(j1))
and this now only constitutes only a first order approximation and the error is directly proportional to the size of the steps but in a way that depends on the way the intervals vary in size. The more variation the more the possible error. Also for points on the edge a different formula is used and this also gives only first order accuracy.
Roger Stafford
