add gradient descent method. rewrite some calculation in matrix form