% Runtime measurements for solution of \emph{dense} linear system of
% equations in MATLAB
N = 2000; % maximum size of matrix
A = gallery('minij',N); % initialize a regular dense matrix: $a_{i,j} = \min\{i,j\}$
v = rand(N,1); % initialize random right hand side vector

res = []; % matrix for collecting the results
for i=10:10:N
    B = A(1:i,1:i); % extract submatrix
    w = v(1:i);     % extract subvector 
    t = realmax;
    for j=1:3, tic; z = B\w; t = min(toc,t); end
    res = [res; i, t],
end

figure; plot(res(:,1),res(:,2),'r+',...
    res(:,1),res(:,1).^3/(res(end,1)^3)*res(end,2),'k-');
xlabel('{\bf matrix size}','fontsize',14);
ylabel('{\bf time [s]}','fontsize',14);
title('Runtime for solving dense linear system');
legend('runtime [s]','O(n^3)','location','best');

print -depsc2 '../../LANMFigures/lsesolvetiming.eps';
