% % We'll test the conclusion of $O(n^3)$ flops experimentally % clear clf format compact nn = (400:40:880)'; l = length(nn); tt = zeros(l, 1); nrep = 1; for i = 1:l n = nn(i); A = randn(n, n); tic() % start a timer for j = 1:nrep % repeat nrep times for more precise timing lufact(A); end tt(i) = toc()/nrep end %% % We plot the performance on a log-log graph and compare it to O(n^3). % The result could vary significantly from machine to machine. loglog(nn, tt, 'ro-') hold on loglog(nn, tt(end)*(nn/nn(end)).^3, 'k--') axis tight xlabel('size of matrix') ylabel('time (sec)') title('Timing of LU factorization') legend('lu','O(n^3)','location','southeast') grid on hold off