tic;
       n = 50;                 % partition number for x(-y) direction
      mu = intval('[-12,12]');
%  Const = 0.3;                % initial guess for upper solution
   Const = 1.3;                % initial guess for lower solution
       a = intval('0.01');
    a_fl = 0.01;
  lambda = 150;
       L = 2*n^2;              % number of elements
     dim = (n-1)^2;            % number of nodes
   maxit = 10;                 % maximum iteration number

  disp(['N= ' num2str(n)''])
  disp(['candidate excluding point mu = ' num2str(mid(mu))''])

% ------------ making local node number ------------------------------------- %
  local_node = zeros(L,3);  
  for m=1:dim
    k=2*(m+floor((m-1)/(n-1)));
    local_node(k,2)=m;
    local_node(k+1,2)=m;
    local_node(k+2,3)=m;
    local_node(k+2*n-1,1)=m;
    local_node(k+2*n,1)=m;
    local_node(k+2*n+1,3)=m;
  end 


% ------------ set initial guess of approximate solutions-------------------- %
  uh = zeros(dim,1);  s = 4*atan(1);
  for m=1:dim
    uh(m)=Const*sin(s*x_coodeinates_for_node(m,n))* ...
          sin(s*y_coodeinates_for_node(m,n));
  end

% ------------ generating matrices A1, A2 and A5 ---------------------------- %
    [A1,A2,A5] = generate_matrices_1(n,L,dim,local_node);


% =============================================================================
%   compute approximate solution uh by Newton-Raphson method 
% =============================================================================
   for k=1:maxit     
    u = uh;
    [A7,A8] = generate_matrices_2(n,L,dim,local_node,uh);
     G = A1+A2+a_fl*lambda*A5+3*lambda*A7-2*lambda*(a_fl+1)*A8;
     r = (A1+A2+a_fl*lambda*A5+lambda*A7-lambda*(a_fl+1)*A8)*u;
     uh = u - G\r;
     s = max(abs(uh));
      if s < 10^(-5)
        error('approximate solution is nealy zero!')
      end
      if s > 10^2
        error('approximate solution is not obtained!')
      end
    cri = norm(r,inf)/norm(uh,inf);
    fprintf('step:%d',k);
    fprintf('  relative error:%d\n',cri);
    if cri < n*eps
      disp(['Newton-Raphson iteration converges numerically.'])
      break
    end
  end    % end for loop k 

  xc = zeros(dim,1);
  yc = zeros(dim,1);
  for m=1:dim
  xc(m)=x_coodeinates_for_node(m,n);
  yc(m)=y_coodeinates_for_node(m,n);
  end
  plot3(xc,yc,uh)

  [V,D] = eig(G,A5);
  fprintf('  1st approximate eigenvalue of lambda: %f\n',D(1,1));
  fprintf('  2nd approximate eigenvalue of lambda: %f\n',D(2,2));
  fprintf('  3rd approximate eigenvalue of lambda: %f\n',D(3,3));


% =============================================================================
%   generate matrices by interval arithmetic
% =============================================================================
  [A1,A2,A5] = generate_interval_matrices_1(n,L,dim,local_node);
     [A7,A8] = generate_interval_matrices_2(n,L,dim,local_node,uh);
           G = A1+A2+(a*lambda-mu)*A5+3*lambda*A7-2*lambda*(a+1)*A8;
     clear A7 A8;
    [ch,Y,E] = verchol(A1+A2);  % interval Cholesky decomposition of A1+A2
    [ch,Z,E] = verchol(A5);     % interval Cholesky decomposition of A5
     clear A1 A2 A5;


% -------- obtaining an upper bound of rho ---------
   rho = norm(Y'*(G\Y));
%  X = Y'*(G\Y);            % generate verified Y^T*G^{-1}*Y
%  rho_ap = norm(mid(X))   % compute an approximate matrix norm of X
%  rho = Matrix_Norm(X,rho_ap,dim);
%  d = 0.1;
%  rho = norm1(G,A1+A2,d);
   disp(['rho= ' num2str(sup(rho))''])


% -------- obtaining an upper bound of rho_hat -----
   rho_h = norm(Y'*(G\Z));
%  X = Y'*(G\Z);            % generate verified Y^T*G^{-1}*Z
%  rho_ap = norm(mid(X))   % compute an approximate matrix norm of X
%  rho_h = Matrix_Norm(X,rho_ap,dim);
%  d = 0.1;
%  rho_hat = norm2(G,A1+A2,A5,d);
  disp(['rho_hat= ' num2str(sup(rho_h))''])

  Pi = 4*atan(intval('1'));      % verified pi
   h = intval('1')/n;            % partition number
   C = intval('0.493')*h;        % a priori constant of projection
  Cp = 1/(Pi*sqrt(intval('2'))); % Poincare constant  
  nv = [ 3*lambda*(norm(uh,inf)-(a+1)/3)^2-lambda*(a+1)^2/3+a*lambda-mu, ...
        -lambda*(a+1)^2/3 + a*lambda - mu, a*lambda - mu]
  ni = max(mag(nv))              % infinity norm of c-mu
  t1 = Cp*C*ni
  t2 = Cp*ni
  t3 = C*ni

% -------- checking the criterion for invertibility -----
   kappa = C*( rho*t1*t2 + t3 );
   disp(['kappa= ' num2str(sup(kappa))''])
     if sup(kappa) > 1
       error('The invertibility did not assure.')
     end

% -------- computing excluding radii I -----
  M = [ rho*(1+t1*C*t2*rho/(1-kappa))    rho*t1/(1-kappa);
  	C*t2*rho/(1-kappa)               intval('1')/(1-kappa)];
  m = norm(M);
  disp(['M_tilde= ' num2str(sup(m))''])

  rad = inf(intval('1')/(Cp^2*m));
  disp(['exclude radius I  = ' num2str(rad)''])


% -------- computing excluding radii II -----
  kappa_h = C*t3*(1+rho_h*t2);
  disp(['kappa_hat= ' num2str(sup(kappa_h))''])
    if sup(kappa_h) > 1
      error('kappa hat is greater than 1.')
    end

  m_h = sqrt( intval(rho_h)^2 + C^2*(1+t2*rho_h)^2 )/(1-kappa_h);
  disp(['M= ' num2str(sup(m_h))''])
  rad = inf(intval('1')/(Cp*m_h));
  disp(['exclude radius II = ' num2str(rad)''])
toc


