function [k,x,err,X,F] = fixedpoint(g,x0,tol,max1)
% Input - g is the iteration function 
%       - x0 is the initial guess for the fixed-point
%       - tol is the tolerance
%       - max1 is the maximum number of iterations 
% Output - k is the number of iterations that were carried out
%	 - x is the approximation to the fixed-point
%	 - err is the error in the approximation
%	 - X'contains the sequence {x}
%	 - F'contains the sequence {f(x)}


%format long;
disp('iteration         x        g(x)')
X(1)= x0;
F(1)=feval(g,X(1));
D=[1,x0,F(1)];
disp(D); 

for k=2:max1
	X(k)=feval(g,X(k-1));
	x=X(k);
    F(k)=feval(g,X(k));
    D=[k,x,F(k)];
    disp(D); 
	err=abs(X(k)-X(k-1));
	relerr=err/(abs(X(k))+eps);
	if (err<tol) | (relerr<tol),break;end
end

if k == max1
	disp('maximum number of iterations exceeded')
end
X=X';
F=F';

