From 821cfec80bb6a6c20831c09ed977b63d6fbd59d2 Mon Sep 17 00:00:00 2001 From: Yuichiro Someya Date: Sun, 8 May 2016 11:42:21 +0900 Subject: [PATCH] Vectorize correctly. --- mlclass-ex1-005/mlclass-ex1/computeCost.m | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/mlclass-ex1-005/mlclass-ex1/computeCost.m b/mlclass-ex1-005/mlclass-ex1/computeCost.m index c5afbc1..6885c9a 100644 --- a/mlclass-ex1-005/mlclass-ex1/computeCost.m +++ b/mlclass-ex1-005/mlclass-ex1/computeCost.m @@ -19,10 +19,9 @@ %end; % Vectorized implementation -J = sum(((X * theta) - y) .^ 2); - -J = 1 / (2 * m) * J; +Z = (X * theta) - y; +J = (Z' * Z) / (2 * m); % ========================================================================= -end \ No newline at end of file +end