From 941db6fa26a1e13144cad6cc2046aa1063f60f04 Mon Sep 17 00:00:00 2001 From: changqi <84911039+comeonsunny@users.noreply.github.com> Date: Sat, 21 May 2022 09:24:28 +0800 Subject: [PATCH] use the vectorization to accelerate the calculation % ====================== YOUR CODE HERE ====================== % Instructions: Compute the cost of a particular choice of theta % You should set J to the cost. sum = 0; temp_cost = X * theta - y; for i = 1:m sum = sum + temp_cost(i)^2; end J = (1/(2*m))*sum; --- ex1/computeCost.m | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ex1/computeCost.m b/ex1/computeCost.m index 4570dbb..170e3d1 100644 --- a/ex1/computeCost.m +++ b/ex1/computeCost.m @@ -19,7 +19,16 @@ % Instructions: Compute the cost of a particular choice of theta % You should set J to the cost. +% ====================== YOUR CODE HERE ====================== +% Instructions: Compute the cost of a particular choice of theta +% You should set J to the cost. +% sum = 0; +% temp_cost = X * theta - y; +% for i = 1:m +% sum = sum + temp_cost(i)^2; +% end +% J = (1/(2*m))*sum;