% script: lutime.m % time different ways to do lu factorization n = [25 50 100 200 300 400 600 800 1000]'; repeat = 4; % number of times at each n asym = 1.5; % one if symmetric luscalar_t = []; lurowvect_t = []; lumatlevel_t = []; lubuiltin_t = []; qr_t = []; feature accel off; for k = 1:length(n) v = ones(n(k),1); A = diag(ones(n(k)-1,1),-1)+diag(3*ones(n(k),1),0)+... diag(asym*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] = lurowvect(A); end lurowvect_t = [lurowvect_t toc/repeat] clear L; clear U; tic; for j = 1:repeat [L,U] = lumatlevel(A); end lumatlevel_t = [lumatlevel_t toc/repeat] clear L; clear U; tic; for j = 1:repeat [L,U] = lu(A); end lubuiltin_t = [lubuiltin_t toc/repeat] clear L; clear U; tic; for j = 1:repeat [Q,R] = qr(A); end qr_t = [qr_t toc/repeat] end loglog(n,2e-8*n.^3,n,luscalar_t,'--',n,lurowvect_t,'-.',... n,lumatlevel_t,'s-',n,lubuiltin_t,'o-',n,qr_t,'*-',n,1e-9*n.^3,'-') xlabel('n'); ylabel('time'); title('Timings for different methods'); legend('n^3','Scalar','Row Vector','Matrix Level','Built-in','QR',... 'Location','Northwest'); legend('boxoff'); feature accel on;