clear %% % Test the conclusion of O(n^3) flops experimentally, using the % built-in lu function n = (1000:200:4000)'; t = 0*n; seed = 1; rng(seed); nrep = 6; for i = 1:length(n) m = n(i); A = randn(m, m); tic() % start a timer for j = 1:nrep [L, U] = lu(A); end t(i) = toc()/nrep; % read the timer end %% % 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(n, t, '.-') hold on loglog(n, t(end)*(n/n(end)).^3, '--') xlabel('size of matrix') ylabel('time (sec)') title('Timing of LU factorization') legend('lu', 'O(n^3)', 'location','southeast') grid on