n=2.^(4:9);                                          % matrix sizes
T1=zeros(1,length(n)); T2=zeros(1,length(n));        % for storing times
for j=1:10                                           % do 10 experiments
  for i=1:length(n)                                  % to average times
    A=rand(n(i));
    t0=clock; B=lu(A); t1(i)=etime(clock,t0);        % compute LU
    t0=clock; E=eig(A); t2(i)=etime(clock,t0);       % compute eigenvalues
  end
  T1=T1+t1; T2=T2+t2;                                % sum times
end
loglog(n,T1/10,'--o',n,T2/10,'--*',n,n.^3/10000000,'-');
legend('Solving Ax=b','Computing eigenvalues of A','O(n^3)',...
       'location','NorthEast');
xlabel('matrix size n');
ylabel('time in seconds');                           
set(gca,'fontsize',20);                              % bigger font size
