%function pf = fixedpoint(g,p0,Tol,Max_it)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% function pf = bisection(a,b,f,Tol, Max_it)
%
% Fixed Point Iteration
% finds fixed point of function handle g, i.e. g(pf) = pf.
% g: function handle
% p0: initial guess
% Tol: abs(p-p0)< Tol is stopping critera
% Max_it: max # of iterations
% pf: fixed point
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
g = @(x) x - (exp(x)-2*x-1)/(exp(x)-2);
Max_it = 100;
TOL = 1e-12;
p0 = 0.5;
i = 1; %initialize counter
while i < Max_it
p = g(p0);
disp(['current iteration = ' num2str(i,'%03i') ' %%% current fixed pt = ' num2str(p,25)])
if abs(p-p0)