title: Gradient Descent and Normal Equation give different theta values for multivariate linear regression.Why?
body: <h1>Vectorized implementation of gradient descent</h1>
  
  <pre><code>for iter = 1:num_iters
  
   theta = theta - (alpha / m) * X' * (X * theta - y);   
   J_history(iter) = computeCostMulti(X, y, theta);
  
  end
  </code></pre>
  
  <h1>Implementation of computeCostMulti()</h1>
  
  <pre><code>function J = computeCostMulti(X, y, theta)
   m = length(y);
   J = 0;
   J = 1 / (2 * m) * (X * theta - y)' * (X * theta - y);
  </code></pre>
  
  <h1>Normal equation implementation</h1>
  
  <pre><code>theta = pinv(X' * X) * X' * y;
  </code></pre>
  
  <p>These two implementations converge to different values of theta for the same values of X and y. The Normal Equation gives the right answer but Gradient descent gives a wrong answer. </p>
  
  <p><strong>Is there anything wrong with the implementation of Gradient Descent?</strong></p>