%----------------------------------------------------------------------------
%
%  Nonlinear Seidel Iteration
%  
%---------------------------------------------------------------------------
   function [P,iter,err] = seidel(G,P,del,max)
       N=length(P);
       for k=1:max
           X=P;
           for j=1:N
               A=feval(G,X);      % X=G(X)
               X(j)=A(j);         % improvement of fixed-point iteration
           end
       
           err=abs(norm(X-P));
           relerr=err/(norm(X)+del);
           P=X;
           iter = k;
           if (err<del) | (relerr<del)
               break
           end
       end

%--------------------------------------------------------------------------
%
%     find (x,y) s.t y=x^2-2x+0.5 & x^2+4y^2=4
%     <=> X=G(X) : x^2-4x-y+0.5 = -2x & x^2+4y^2-11y-4=-11y
%     <=>          x=(x^2-4x-y+0.5)/-2 & y=(x^2+4y^2-11y-4)/11y
%
%     matlab : 
%     >> [P,iter,err] = seidel('G',P,0.00001,100)
%
%-------------------------------------------------------------------------

      function Y = G(X)

          x = X(1);
          y = X(2);
          Y=[(-x^2+4*x+y-0.5)/2; (-x^2-4*y^2+11*y+4)/11];

%-------------------------------------------------------------------------
