% plots 3d log log plots
clc;
clf;
close all;

% For dense nxm matrices 

% when n is fixed and m is varied
r1=10*ones(1,length(esval1(1,:)));
r2=15*ones(1,length(esval1(1,:)));
r3=20*ones(1,length(esval1(1,:)));
n=100:100:1500;

% timings
h=figure(1);
hold on
plot3(r1,n,t1(1,:),'bv-','MarkerFaceColor','b','LineWidth',2);
plot3(r1,n,t2(1,:),'g^-','MarkerFaceColor','g','LineWidth',2);
plot3(r1,n,t3(1,:),'ks-','MarkerFaceColor','k','LineWidth',2);
plot3(r2,n,t1(2,:),'bv-','MarkerFaceColor','b','LineWidth',2);
plot3(r2,n,t2(2,:),'g^-','MarkerFaceColor','g','LineWidth',2);
plot3(r2,n,t3(2,:),'ks-','MarkerFaceColor','k','LineWidth',2);
plot3(r3,n,t1(3,:),'bv-','MarkerFaceColor','b','LineWidth',2);
plot3(r3,n,t2(3,:),'g^-','MarkerFaceColor','g','LineWidth',2);
plot3(r3,n,t3(3,:),'ks-','MarkerFaceColor','k','LineWidth',2);
Set all three axes to be log scale
set(gca,'YScale', 'log', 'ZScale', 'log')
xlabel('r (%)');
ylabel('n');
zlabel('Timings (s)');
title('Comparison of timings');
legend('Built-in function', 'Indirect Method','Direct Method');
view(45,30);
grid 
axis tight
print(h,'-dpng');

% accuracies
h=figure(2);
hold on
plot3(r1,n,e1(1,:),'bv-','MarkerFaceColor','b','LineWidth',2);
plot3(r1,n,e2(1,:),'g^-','MarkerFaceColor','g','LineWidth',2);
plot3(r1,n,e3(1,:),'ks-','MarkerFaceColor','k','LineWidth',2);
plot3(r2,n,e1(2,:),'bv-','MarkerFaceColor','b','LineWidth',2);
plot3(r2,n,e2(2,:),'g^-','MarkerFaceColor','g','LineWidth',2);
plot3(r2,n,e3(2,:),'ks-','MarkerFaceColor','k','LineWidth',2);
plot3(r3,n,e1(3,:),'bv-','MarkerFaceColor','b','LineWidth',2);
plot3(r3,n,e2(3,:),'g^-','MarkerFaceColor','g','LineWidth',2);
plot3(r3,n,e3(3,:),'ks-','MarkerFaceColor','k','LineWidth',2);
Set all three axes to be log scale
set(gca, 'YScale', 'log', 'ZScale', 'log')
xlabel('r (%)');
ylabel('n');
zlabel('Accuracies (||U\SigmaV^{T}-A||_\infty)');
title('Comparison of accuracies');
legend('Built-in function', 'Indirect Method','Direct Method');
view(45,30);
grid 
axis tight
print(h,'-dpng');

% Orthogonality checks u*u'-eye
h=figure(3);
hold on
plot3(r1,n,orth1(1,:),'bv-','MarkerFaceColor','b','LineWidth',2);
plot3(r1,n,orth3(1,:),'g^-','MarkerFaceColor','g','LineWidth',2);
plot3(r1,n,orth5(1,:),'ks-','MarkerFaceColor','k','LineWidth',2);
plot3(r2,n,orth1(2,:),'bv-','MarkerFaceColor','b','LineWidth',2);
plot3(r2,n,orth3(2,:),'g^-','MarkerFaceColor','g','LineWidth',2);
plot3(r2,n,orth5(2,:),'ks-','MarkerFaceColor','k','LineWidth',2);
plot3(r3,n,orth1(3,:),'bv-','MarkerFaceColor','b','LineWidth',2);
plot3(r3,n,orth3(3,:),'g^-','MarkerFaceColor','g','LineWidth',2);
plot3(r3,n,orth5(3,:),'ks-','MarkerFaceColor','k','LineWidth',2);
Set all three axes to be log scale
set(gca, 'YScale', 'log', 'ZScale', 'log')
xlabel('r (%)');
ylabel('n');
zlabel('Orthogonality checks (||UU^{T}-Id||_\infty)');
title('Comparison of Orthogonality checks');
legend('Built-in function', 'Indirect Method','Direct Method');
view(45,30);
grid 
axis tight
print(h,'-dpng');

% Orthogonality checks u'*u-eye
h=figure(4);
hold on
plot3(r1,n,orth1_1(1,:),'bv-','MarkerFaceColor','b','LineWidth',2);
plot3(r1,n,orth3_1(1,:),'g^-','MarkerFaceColor','g','LineWidth',2);
plot3(r1,n,orth5_1(1,:),'ks-','MarkerFaceColor','k','LineWidth',2);
plot3(r2,n,orth1_1(2,:),'bv-','MarkerFaceColor','b','LineWidth',2);
plot3(r2,n,orth3_1(2,:),'g^-','MarkerFaceColor','g','LineWidth',2);
plot3(r2,n,orth5_1(2,:),'ks-','MarkerFaceColor','k','LineWidth',2);
plot3(r3,n,orth1_1(3,:),'bv-','MarkerFaceColor','b','LineWidth',2);
plot3(r3,n,orth3_1(3,:),'g^-','MarkerFaceColor','g','LineWidth',2);
plot3(r3,n,orth5_1(3,:),'ks-','MarkerFaceColor','k','LineWidth',2);
Set all three axes to be log scale
set(gca, 'YScale', 'log', 'ZScale', 'log')
xlabel('r (%)');
ylabel('n');
zlabel('Orthogonality checks (||U^{T}U-Id||_\infty)');
title('Comparison of Orthogonality checks');
legend('Built-in function', 'Indirect Method','Direct Method');
view(45,30);
grid 
axis tight
print(h,'-dpng');

% Orthogonality checks v*v'-eye
h=figure(5);
hold on
plot3(r1,n,orth2(1,:),'bv-','MarkerFaceColor','b','LineWidth',2);
plot3(r1,n,orth4(1,:),'g^-','MarkerFaceColor','g','LineWidth',2);
plot3(r1,n,orth6(1,:),'ks-','MarkerFaceColor','k','LineWidth',2);
plot3(r2,n,orth2(2,:),'bv-','MarkerFaceColor','b','LineWidth',2);
plot3(r2,n,orth4(2,:),'g^-','MarkerFaceColor','g','LineWidth',2);
plot3(r2,n,orth5(2,:),'ks-','MarkerFaceColor','k','LineWidth',2);
plot3(r3,n,orth2(3,:),'bv-','MarkerFaceColor','b','LineWidth',2);
plot3(r3,n,orth4(3,:),'g^-','MarkerFaceColor','g','LineWidth',2);
plot3(r3,n,orth6(3,:),'ks-','MarkerFaceColor','k','LineWidth',2);
Set all three axes to be log scale
set(gca, 'YScale', 'log', 'ZScale', 'log')
xlabel('r (%)');
ylabel('n');
zlabel('Orthogonality checks (||VV^{T}-Id||_1)');
title('Comparison of Orthogonality checks');
legend('Built-in function', 'Indirect Method','Direct Method');
view(45,30);
grid 
axis tight
print(h,'-dpng');

% Orthogonality checks v'*v-eye
h=figure(6);
hold on
plot3(r1,n,orth2_1(1,:),'bv-','MarkerFaceColor','b','LineWidth',2);
plot3(r1,n,orth4_1(1,:),'g^-','MarkerFaceColor','g','LineWidth',2);
plot3(r1,n,orth6_1(1,:),'ks-','MarkerFaceColor','k','LineWidth',2);
plot3(r2,n,orth2_1(2,:),'bv-','MarkerFaceColor','b','LineWidth',2);
plot3(r2,n,orth4_1(2,:),'g^-','MarkerFaceColor','g','LineWidth',2);
plot3(r2,n,orth5_1(2,:),'ks-','MarkerFaceColor','k','LineWidth',2);
plot3(r3,n,orth2_1(3,:),'bv-','MarkerFaceColor','b','LineWidth',2);
plot3(r3,n,orth4_1(3,:),'g^-','MarkerFaceColor','g','LineWidth',2);
plot3(r3,n,orth6_1(3,:),'ks-','MarkerFaceColor','k','LineWidth',2);
Set all three axes to be log scale
set(gca, 'YScale', 'log', 'ZScale', 'log')
xlabel('r (%)');
ylabel('n');
zlabel('Orthogonality checks (||V^{T}V-Id||_1)');
title('Comparison of Orthogonality checks');
legend('Built-in function', 'Indirect Method','Direct Method');
view(45,30);
grid 
axis tight
print(h,'-dpng');

% errors in singular values 
h=figure(7);
hold on
plot3(r1,n,esval1(1,:),'bv-','MarkerFaceColor','b','LineWidth',2);
plot3(r1,n,esval2(1,:),'g^-','MarkerFaceColor','g','LineWidth',2);
plot3(r2,n,esval1(2,:),'bv-','MarkerFaceColor','b','LineWidth',2);
plot3(r2,n,esval2(2,:),'g^-','MarkerFaceColor','g','LineWidth',2);
plot3(r3,n,esval1(3,:),'bv-','MarkerFaceColor','b','LineWidth',2);
plot3(r3,n,esval2(3,:),'g^-','MarkerFaceColor','g','LineWidth',2);
% Set all three axes to be log scale
set(gca,  'YScale', 'log', 'ZScale', 'log')
xlabel('r (%)');
ylabel('n');
zlabel('Errors in singular values (||Computed-Actual||_\infty)');
title('Comparison of errors in singular values');
legend('Indirect Method','Direct Method');
view(45,30);
grid 
% axis tight
print(h,'-dpng');