quick fix of gradient.m

some crucial errors fixed