clc,format short e
format compact
A=[ 0    -4    -8    -2
   -4    -7    -7    -8
   -9    -5    -4    -5
    0    -5    -9    -6];
n=length(A); x=(1:n)'; b=A*x;
x0=x-5;                              % Starting vector
[X1,res,V,W,T]=BiORES(A,b,x0,4);
[X2,res,R,Rt,P,Pt]=BiCG(A,b, x0,4);
disp('Bi-orthogonality of residuals R''*Rt'); 
R(:,1:4)'*Rt(:,1:4)
disp('Bi-conjugacy of directions: P''*A''*Pt respectively Pt''*A*P')
P'*A'*Pt
format short
disp('Orthogonality of residuals and directions  R''*Pt')
disp('respectively Rt''*P for  i>j' )
R(:,1:4)'*Pt
Rt(:,1:4)'*P
pause
clc,format short e
disp('Tridiagonal matrix by BiCG')
P\A*P
% Pt\A'*Pt
disp('Tridiagonal matrix by Lanczos')
T(1:4,1:4)
disp('are not the same, but similar, the eigenvalues are')
[eig(P\A*P) eig(T(1:4,1:4))]
pause    
clc
disp('BiORES approximations '); X1
disp('BiCG approximations'); X2
disp('Solutions are the same')
disp('right Lanczos vectors V'); V
disp('BiCG residual vectors R'); R
disp('component wise quotient of left Lanczos vectors W ')
disp('and BiCG vectors Rt')
W(:,1:4)./Rt(:,1:4)