title: My gradient descent for linear regression won't converge
body: <p>I've been stuck for hours trying to figure it out why my code for Gradient Descent on Linear Regression won't converge.
  tried with really small alphas and really huge iterations, still won't work.</p>
  
  <pre><code>function [theta, J_history] = gradientDescent(X, y, theta, alpha, num_iters)
  %GRADIENTDESCENT Performs gradient descent
  % t to learn theta
  %   theta = GRADIENTDESCENT(X, y, theta, alpha, num_iters) updates theta by 
  %   taking num_iters gradient steps with learning rate alpha
  
  % Initialize some useful values
  m = length(y) % number of training examples
  
  ST0=0;
  ST1=0;
  
  for iter = 1:num_iters
     for i=1:m
         ST0=ST0+((theta(1)+theta(2)*X(i))-y(i));
         ST1=ST1+(((theta(1)+theta(2)*X(i))-y(i)))*X(i,2);
     end
  
    ST0=ST0/m;
    ST0=ST0*alpha;
    ST1=ST1/m;
    ST1=ST1*alpha;  
    theta(1)=theta(1)-ST0;
    theta(2)=theta(2)-ST1;
      J= computeCost(X, y, theta);
  
      J_history(iter) = J;
  
  
  end
  
  end
  </code></pre>