
maxit=100; % MAXIMUM NUMBER ITERATIONS.
matrix_type=1; % EXAMPLE.
tol=10^(-10); % QR TOLERANCE.

%------------------
% DEFINITION MATRIX.
%------------------
switch matrix_type
case 1
N=5;
A=-makefish(N); % DEFINE A SYMMETRIC POSITIVE DEFINITE MATRIX.
case 2
    A=[4        3.464101 -1.388729  0.2672636;
       1.732049 7.666669  1.158131 -0.4629126;
       0       -1.247218  2.476188  0.7423077;
       0        0         0.9897417 1.857139];
case 3
    A=companion_matrix(3);
end


%------------------
% BASIC QR.
%------------------
t1=cputime;
[T,hist]=QR_v1(A,tol,maxit);
t2=cputime;
iter=size(hist,2);
eig_exact=sort(eig(A));
eig_qr=hist(:,iter);


%------------------
% STATS QR.
%------------------
n=size(A,1);
ratio_eig=max(sort(abs(eig_exact(1:n-1)))./sort(abs(eig_exact(2:n))));

fprintf('\n \t [RATIO]: %2.2f \n',ratio_eig);

for index=1:size(T,1)
    fprintf('\n \t [EIGENVALUES]: (%5.5f,%5.5f)  [EIGENVALUES QR]:  (%5.5f,%5.5f)',real(eig_exact(index)),...
        imag(eig_exact(index)),real(eig_qr(index)),imag(eig_qr(index)));
end

fprintf('\n \n \t [CPUTIME]: %5.5e [ITERATIONS]: %3.0f \n',t2-t1,length(hist));

%------------------
% BASIC QR SHIFT.
%------------------
t1=cputime;
[D,hist]=QR_v2(A,tol,maxit);
t2=cputime;
iter=size(hist,2);
eig_exact=sort(eig(A));
eig_qr2=sort(D);


%------------------
% STATS SHIFT.
%------------------
for index=1:length(hist(:,1))
    fprintf('\n \t [ITERATIONS]: %5.0f [SUBDIAGONAL ENTRY]: %2.2e',hist(index,1),hist(index,2));
end

fprintf('\n');



for index=1:size(T,1)
    fprintf('\n \t [EIGENVALUES]: (%5.5f,%5.5f)  [EIGENVALUES QR]:  (%5.5f,%5.5f)',real(eig_exact(index)),...
        imag(eig_exact(index)),real(eig_qr2(index)),imag(eig_qr2(index)));
end

fprintf('\n \n \t [CPUTIME]: %5.5e [ITERATIONS]: %3.0f [MAX SUBDIAG TERM SIZE]: %2.2e \n',t2-t1,length(hist),max(hist(:,2)));

