First implementation of gradient descent.