% In this file some test will be run for checking the routine BiDiag

% Initialize some variables
n=10;
diffmn=3; % the difference between dimensions m and n in the last examples
I=sqrt(-1);

 disp('1. Arbitrary square matrix with only B as output  ---------------')
 A=rand(n,n);
 B=BiDiag(A);
 disp('Is B bidiagonal, norm of tril(B,-1) and norm of triu(B,2)')
 norm(tril(B,-1))
 norm(triu(B,2))
 pause
 clc
 
 
 disp('2. Arbitrary square matrix full output  ---------------')
 A=rand(n,n);
 [U,B,V]=BiDiag(A);
 disp('Is B bidiagonal, norm of tril(B,-1) and norm of triu(B,2)')
 norm(tril(B,-1))
 norm(triu(B,2))
 disp('Is UAV^* = B, norm of this difference.')
 norm(U'*A*V-B)
 pause
 clc
 


disp('3. Arbitrary rectangular matrix full output n>m  -----------')
A=rand(n+diffmn,n);
[U,B,V]=BiDiag(A);
disp('Is B bidiagonal, norm of tril(B,-1) and norm of triu(B,2)')
norm(tril(B,-1))
norm(triu(B,2))
disp('Is UAV^* = B, norm of this difference.')
norm(U'*A*V-B)
pause
clc



disp('4. Arbitrary rectangular matrix full output n<m  -----------')
A=rand(n,n+diffmn);
[U,B,V]=BiDiag(A);
disp('Is B bidiagonal, norm of tril(B,-1) and norm of triu(B,2)')
norm(tril(B,-1))
norm(triu(B,2))
disp('Is UAV^* = B, norm of this difference.')
norm(U'*A*V-B)
