% script: lu_time_ex.m % time different ways to do lu factorization n = [25 50 100 200]'; repeat = 4; % number of times at each n luscalar_t = []; lurowvect_t = []; lumatlevel_t = []; lubuiltin_t = []; for k = 1:length(n) A = diag(ones(n(k)-1,1),-1)+diag(3*ones(n(k),1),0)+... diag(ones(n(k)-1,1),-1); tic; for j = 1:repeat [L,U] = luscalar(A); end luscalar_t = [luscalar_t toc/repeat] clear L; clear U; tic; for j = 1:repeat [L,U] = lu(A); end lubuiltin_t = [lubuiltin_t toc/repeat] end loglog(n,2e-8*n.^3,n,luscalar_t,n,lubuiltin_t,'o-') xlabel('n'); ylabel('time'); title('Timings for different methods'); legend('n^3','Scalar','Built-in','Location','Northwest'); legend('boxoff');