fmincg function provided as part of Stanford Machine Learning class