%A script to determine run time to compute singular values of an m x m
%matrix
%M126 HW1 #6
%1/12/12
%Brad Nelson

gap=1;%gap between samples
ts=zeros(1);%holds time
i=0; %index
for m=100:gap:1000;
   i=i+1; %increments index for t
    tic %begins timer
    A=rand(m,m); %random m x m matrix
    s=svd(A); %finds singular values of matrix
    ts(i)=toc;%stores elapsed time in t
end

m=100:gap:1000;

%produces plot...
figure(1);
loglog(m,ts);
xlabel('m'); ylabel('t');
title('log-log plot of t vs. m for finding svd of random mxm matrix');

%plot indicates that different power law is followed from m=100 to 600 and
%m=600 to 1000

hold on;
tests=(m/1900).^2;
loglog(m,tests,'r');

tests=(m/980).^4;
loglog(m(300:end),tests(300:end),'k');
hold off;
legend('data','t\alpha m^2','t\alpha m^4','Location','NorthWest');

%print -depsc svdtime.eps