
function [D,Q,er,it]=qreig(A,tol=1e-6*size(A,1),maxit=100)
# a simple implementation of the standard
# QR method for eigenproblem
#the method stops if ||A-diagonal(A)||_1<=tol (default 1e-6*no of rows A) or no of iterations
#exceeds maxit (default 100)
# Input:
# A- symmetric matrix
# tol, maxit (optional) stopping criteria
# Output:
# D - approximation of the diagonal matrix  with eigenvalues on the diagonal
# Q - orthogonal matrix with columns - approximations of eigenvectors
# er - 1st norm of A_k-diagonal of A_k - for A_k a QR method iteration matrix (similar to A)
# it = no of iterations
#
#The simplest call:
#D=qreig(A) #A symmetric
#the call with all parameters 
#  [D,Q,er,it]=qreig(A,1e-12,10)
 Z=eye(size(A));
 it=0; er=norm(A-diag(diag(A)),1);
 while((er>tol)&&(it<=maxit))
  [Q,R]=qr(A);
  A=R*Q;
  er=norm(A-diag(diag(A)),1);
  Z=Z*Q;
  it++;
 endwhile
 if(it>maxit)
    printf("\n\nWarning. Maximal no of iterations (%d)  is exceeded; er=%g \n\n",maxit,er);
  endif
 D=A;
 Q=Z;
endfunction

