implementing the calculation of field of gradient