Solved by taha in post #8 
              
              
                Hi @tom. I found the issue.  Eigen-decomposition requires a symmetric matrix as its input.  But the perturbations by gradcheck() makes the input asymmetric and eigen-decomposition fails.  I wrote my own numerical gradient checking function and the above function worked.