title: MATLAB code not working (gradient descent algorithm)
body: <p>I am trying gradient descent, I wrote following however not getting any answer,</p>
  
  <pre><code>n=0;            %initialize iteration counter 
  eps=1;          %initialize error 
  a=0.8;         %set iteration parameter 
  x=[1;1];        %set starting value
  f=6*x(1)^2+8*x(2)^2-3*x(1)*x(2);
  %Computation loop 
  while eps&gt;1e-12||n&lt;100 
     gradf=[12*x(1)-3*x(2); 16*x(2)-3*x(1)];  %gradf(x) 
     eps=(norm(gradf)/(1+abs(f)));                                %error 
     y=x-a*gradf;                                                 %iterate 
     x=y;                                                         %update x 
     n=n+1;                                                       %counter+1 
  end 
  n;x;eps;        %display end values
  </code></pre>
  
  <p>When I add this file to path and type x it shows NaN, NaN. what is wrong?</p>