% Script File: h3p1.m 
% Solving Eigenvalues by shifted-QR factorization
%
% A = 11 ?12  8 ?4    C = 3  -3   2 -1   X = 4  1  0  0
%     25 ?25 16 ?8       12 -12  10 -5      -1  3  0  0
%      7  ?6  2  0        15 -15 14 -7       0  0  5  -1
%     -9   9 ?8  6         6  -6  6 -3       0  0  1   5
%
fin=fopen('dataQR4.txt');
% fin=fopen('datah2A.txt','r');
header1=fgetl(fin);
n=fscanf(fin,'%d',1)
% header2=fgetl(fin);
Nrun=40;
Y=fscanf(fin,'%f',[n n]);
Y=Y';
SaveY=Y; A=Y; I=eye(n,n);
for k=1:Nrun
    s=A(n,n);
    A=A-s*I;
    [Q,R]=qr(A);
    A=R*Q+s*I;
end
A
[U D]=eig(Y);
Dvalue=(diag(D))';
Eigenvalue=shiftedQR(Y);
Ds=sort(Dvalue); Es=sort(Eigenvalue);
Ds, Es
% [norm(Ds-Es,1), norm(Ds-Es,2), norm(Ds-Es,inf)]
%% dataQR4.txt---------------------------------------------------------------------
% A 4 by 4 matrix for computing eigenvalues by QR decomposition
% 4
%  4  1  0  0
% -1  3  0  0
%  0  1  5 -1
%  0  0  1  5
%%-------------------------------------------------------------
