Using gradient descent for function minimization