% Timing of matrix$\times$vector operation for dense matrices
N = 3000; % maximum size of matrix
A = rand(N,N); % initialize random matrix
v = rand(N,1); % initialize random column vector

res = []; % matrix for collecting the results
for i=10:10:N
    B = A(1:i,1:i); % extract submatrix
    w = v(1:i);
    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).^2/(res(end,1)^2)*res(end,2),'k-');
xlabel('{\bf matrix size}','fontsize',14);
ylabel('{\bf time [s]}','fontsize',14);
title('Timing of matrix x vector multiplication');
legend('Laufzeit','O(n^2)','location','best');

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