From ba377e29bad0fbdd330f8651fb3cfa0ddf6cd131 Mon Sep 17 00:00:00 2001 From: neingeist Date: Thu, 2 Oct 2014 22:48:53 +0200 Subject: [PATCH] Linear regressing using the normal equation --- ex1/normalEqn.m | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/ex1/normalEqn.m b/ex1/normalEqn.m index d32cd8e..53d88e3 100644 --- a/ex1/normalEqn.m +++ b/ex1/normalEqn.m @@ -1,6 +1,6 @@ function [theta] = normalEqn(X, y) -%NORMALEQN Computes the closed-form solution to linear regression -% NORMALEQN(X,y) computes the closed-form solution to linear +%NORMALEQN Computes the closed-form solution to linear regression +% NORMALEQN(X,y) computes the closed-form solution to linear % regression using the normal equations. theta = zeros(size(X, 2), 1); @@ -10,12 +10,7 @@ theta = zeros(size(X, 2), 1); % to linear regression and put the result in theta. % -% ---------------------- Sample Solution ---------------------- - - - - -% ------------------------------------------------------------- +theta = pinv(X' * X) * X' * y; % ============================================================