normalEqn.m 676 B

1234567891011121314151617181920212223
  1. function [theta] = normalEqn(X, y)
  2. %NORMALEQN Computes the closed-form solution to linear regression
  3. % NORMALEQN(X,y) computes the closed-form solution to linear
  4. % regression using the normal equations.
  5. theta = zeros(size(X, 2), 1);
  6. % ====================== YOUR CODE HERE ======================
  7. % Instructions: Complete the code to compute the closed form solution
  8. % to linear regression and put the result in theta.
  9. %
  10. % ---------------------- Sample Solution ----------------------
  11. theta = (X' * X) ^ -1 * X' * y;
  12. % -------------------------------------------------------------
  13. % ============================================================
  14. end