% m1_howfast.m - how fast can we solve Ax=b with Matlab "\" command? A = rand(5) b = ones(5,1) x = A\b A*x A*x-b A = randn(500); b = ones(500,1); x = A\b; whos A*x-b ans(end) N = 1000; A = randn(N); b = ones(N,1); tic, A\b; toc N = 2000; A = randn(N); b = ones(N,1); tic, A\b; toc N = 4000; A = randn(N); b = ones(N,1); tic, A\b; toc N = 8000; A = randn(N); b = ones(N,1); tic, A\b; toc format bank for i = 1:12, N = 2^i; A = randn(N); tic, A\ones(N,1); t=toc; disp([N t]), end for i = 1:12, N = 2^i; A = randn(N); tic, A\ones(N,1); t = toc; NN(i) = N; tt(i) = t; end plot(NN,tt) plot(NN,tt,'.-') loglog(NN,tt,'.-') grid on, hold on loglog(NN,1e-11*NN.^3,'--r') ylim([1e-5 1e2]) xlabel('dimension') ylabel('time (secs)') title('speed of Matlab backslash') gtext('N^3','fontsize',24,'color','r')