function [mu,xx]= wiedef94(A,x0,mu0,xmu0,Nmax,TOL);
%%function [mu,x]= wiedef94(A,x0,mu0,xmu0,Nmax,TOL);
%%  To approximate the second most dominant eigenvalue and associated
%% eigenvector of the nxn matrix A given an approximation to the dominant
%% eigenvalue and an approximation to the corresponding eigenvector
%% INPUTS
%%   A - the nxn matrix
%%   x0 - an initial starting vector of dimension n-1
%%   mu0 - an approximation to the dominant eigenvalue
%%   xmu0 - an approximation to the eigenvector for mu0
%%   Nmax - maximum number of iterations
%%   TOL  - tolerence
%% OUTPUTS
%%    mu - an approximation to an eigenvalue
%%    x - the approximation to the corresponding eigenvector

n=length(xmu0);
I=find(abs(xmu0)==norm(xmu0,inf));i=I(1);
if i~=1
   for k=1:i-1;
       B(k,1:i-1)=A(k,1:i-1)-(xmu0(k)/xmu0(i))*A(i,1:i-1);
   end;
end;
if (i~=1&i~=n)
   for k=i:n-1;
      for j=1:i-1;
         B(k,j)=A(k+1,j)-(xmu0(k+1)/xmu0(i))*A(i,j);
         B(j,k)=A(j,k+1)-(xmu0(j)/xmu0(i))*A(i,k+1);
      end;
   end;
end;
if i~=n
   for k=i:n-1;
      B(k,i:n-1)=A(k+1,i+1:n)-(xmu0(k+1)/xmu0(i))*A(i,i+1:n);
   end;
end;
[mu,x]=powmet91(B,x0,Nmax,TOL);
if i==1;
   w=[0;x]; 
elseif i==n;
   w=[x;0];
else
   w=[x(1:i-1);0;x(i:n-1)];
end;
xx=(mu-mu0)*w+((A(i,:)*w)/xmu0(i))*xmu0;
