function  fixed_point_demo(g,x0,I,maxit)
% function  fixed_point_demo(g,x0,I,maxit)
% Graphic demostration of the fixed point method
%     g - inline function
%    x0 - initial iteration
%     I - interval for drawing
% maxit - maximal number of iterations (defulat 10)

if nargin<3
    error('Few input parameters!');
end
if nargin==3,  maxit=10; end

a=I(1); b=I(2);
xx=linspace(a,b,201);     % points to draw the function g
yy=g(xx);
mg=min(yy); Mg=max(yy);
% test if g(x) is in I for all x
if mg<a | Mg>b
    error('The values of the function g don''t lie in the given interval!');
end

plot(xx,yy,xx,xx);    % graph of g and y=x
hold on
plot(x0,x0,'r*');
pause
for k=1:maxit
    x1=g(x0);
    plot([x0,x0],[x0,x1],'r*--');
    pause(0.5);
    plot([x0,x1],[x1,x1],'r*--');
    x0=x1;
    pause(1)
end

end

