diff --git a/ex5/linearRegCostFunction.m b/ex5/linearRegCostFunction.m index 1d70418..e90732b 100644 --- a/ex5/linearRegCostFunction.m +++ b/ex5/linearRegCostFunction.m @@ -22,6 +22,8 @@ grad = zeros(size(theta)); J = 1/(2*m) * sum(((X*theta)-y).^2) ... + lambda/(2*m) * sum(theta(2:end).^2); +grad = 1/m * X' * ((X*theta)-y) + (lambda/m) * [0; theta(2:end)]; + % ========================================================================= grad = grad(:);