gradient descent with matrix