%% FIXED_POINT  
% locate the fixed point of an arbitrary function
% using general fixed_point iteration

%%
f=@(x) exp(-x);

x0=0;  % initial approximation to location of fixed point
TOL=10^(-10); % absolute error convergence tolerance
Nmax=100; % maximum number of iterations to be performed
flag=0;

%% Main code
old = x0;
for i = 1 : Nmax
    new = feval(f,old);
	fprintf('\t\t %3d \t %.10f \n', i, new)
	
	if ( abs(new-old) < TOL ) 
	   flag=1;
	   break
	else
	   old = new;
	end
	
end

%%
if flag == 0 
    disp('Maximum number of iterations exceeded') 
end

%%
fprintf('\n The approximate fixed point is %f', new)