And what value should have df for start? |
df doesn't need any value at the start. It is being CALCULATED in the return statement
return (dx*Gradient[iy][ix][0] + dy*Gradient[iy][ix][1]);
f is also just a convenient name I adopted for the variable that is being made noisy.
df is not infinitesimal here because (x,y) is a finite distance from (ix,iy). If you want to write that (Delta f) instead, then fine. In full
(Delta f) = (Delta x)(df/dx) + (Delta y)(df/dy)
is the linear approximation to the exact infinitesimal statement
df = dx (df/dx) + dy (df/dy)
(Those derivatives df/dx and df/dy are actually partial derivatives, as in @mbozzi's link, but there is no way of writing that here.)
Gradient[iy][ix][0] stores the partial derivative (df/dx) at grid point [iy][ix]
Gradient[iy][ix][1] stores the partial derivative (df/dy) at grid point [iy][ix]
These are defined outside of the given pseudocode; hence the extern statement.
In multiple dimensions, the vector quantity grad f = (df/dx,df/dy), or in three dimensions (df/dx,df/dy,df/dz), is the mathematical gradient, just like in ordinary differential calculus dy/dx is the gradient or slope of the curve y(x).
If you want a random 2d vector of unit length, choose a random angle A in the range 0 to 2.pi and set the vector as (cos A, sin A).