added matlab gradient function