title: Newton algorithm - couln't calculate Hessian
body: <p>I'm trying to write an implementation of Newton algorithm in Matlab.</p>
  
  <p>When I call up my function using formula:</p>
  
  <pre><code>result = NewtonMethod(x(1).^2 - 2.1*x(1).^4 + (x(1).^6)/3 + x(1)*x(2) - 4*x(2).^2 + 4*x(2).^4, [0 0], 0.1, 10)
  </code></pre>
  
  <p>I've got an error message:</p>
  
  <pre><code>??? Undefined function or method 'hessian' for input arguments of type 'double'.
  
  Error in ==&gt; NewtonMethod at 13
      H = hessian(f, x0);
  </code></pre>
  
  <p>I've got no idea what is wrong. Maybe someone more familiar with Matlab can help me.</p>
  
  <p>Below it's my code:</p>
  
  <pre><code>function xnext = NewtonMethod(f, x0, eps, maxSteps)
  
  % x0        -   starting point (2 – dimensional  vector)
  % H         -   matrix of second derivatives (Hessian)
  % eps       -   required  tolerance of calculations
  % maxSteps  -   length of step
  
  x = x0;
  
  for n=1:maxSteps
  
      % determine the hessian H at the starting point x0,
      H = hessian(f, x0);
  
      % determine the gradient of the goal function gradf at the point x,
      gradF = gradient(f, x);
  
      % determine next point
      xnext = x - inv(H) * x * gradF;
  
      if abs(xnext - x) &lt; eps
          return                  %found
      else
          x = xnext;              %update
      end
  end
  </code></pre>
  
  <p>It's my first contact with Matlab.</p>
  
  <p>Update:</p>
  
  <p>Now I've got an error:</p>
  
  <pre><code>??? Error using ==&gt; mupadmex
  Error in MuPAD command: Index exceeds matrix dimensions.
  
  Error in ==&gt; sym.sym&gt;sym.subsref at 1381
              B = mupadmex('symobj::subsref',A.s,inds{:});
  </code></pre>
  
  <p>I typed:</p>
  
  <pre><code>syms x
  result = NewtonMethod(x(1).^2 - 2.1*x(1).^4 + (x(1).^6)/3 + x(1)*x(2) - 4*x(2).^2 + 4*x(2).^4, [0 0], 0.1, 10)
  </code></pre>