function [T,hist]=QR_v1(T_input,tol,maxit)

% QR METHOD FOR A SYMMETRIC TRIDIAGONAL MATRIX "T_input".

T=T_input;
n=size(T,1);
hist=sort(diag(T));

for index=1:maxit
    [Q,R]=qr(T);
    T=R*Q;                     % NEW SIMILAR MATRIX.
    hist=[hist sort(diag(T))]; % IT STORES THE DIAGONAL ELEMENTS 
                               % OF THE "index" ITERATION.
                               
    sub_diag_T=abs( diag(T(2:n,1:n-1))); % PREPARING STOPPING CRITERION.
    diag_T_start=abs( diag(T(1:n-1,1:n-1)));
    diag_T_finish=abs( diag(T(2:n,2:n)));
    
    if 0 < max(tol*(diag_T_start+diag_T_finish)-sub_diag_T) % STOPPING CRITERION.
        return
    end
    
end

