I need to write a fixed point iteration algorithm and it's mostly coded but I'm running into this error:
Undefined function or variable 'g'.
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.
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<tol)
break
end
p0 = p;
end
if (k==max1)
disp('The algorithm did not converge')
end
y = p;