used gradient descent to calculate cost and theta values