Update gd.m

Add error calculation and return of error value. Add further comments. Change variable names.