title: Undefined function or variable Matlab
body: <p>I need to write a fixed point iteration algorithm and it's mostly coded but I'm running into this error:  </p>
  
  <p>Undefined function or variable 'g'. </p>
  
  <p>I want to define g as g(x) = 1/2*(1+5/x). However, I'm a matlab n00b and unsure how to do this. Any help would be much appreciated, thanks.</p>
  
  <pre><code>  function [y,k] = fixedpoint(g,p0,tol,max1)
            for k=1:max1
            p = g(p0);
            err = abs(p-p0);
            abserr = abs(sqrt(5)-p);
            ratioerr = abserr/(abs(sqrt(5)-p0));
  
            if (err&lt;tol)
               break
            end
            p0 = p;
  
    end
    if (k==max1)
        disp('The algorithm did not converge')
    end
    y = p;
  </code></pre>