batch gradient descent using optimize()