format compact

clc  % clear screen

display( '** Simple test' )
A = [ 1,2 ; 3,4 ]
B = [ 2,1 ; 1,3 ]
mult(A,B)

% % uncomment these later parts to explore further
% 
% display( '** Check with MATLAB built-in multiplication' )
% A*B
% 
% display( '** 5x5 matrices of random numbers' )
% A1 = rand(5,5)
% B1 = rand(5,5)
% mult(A1,B1)
% 
% display( '** 100x100 matrices of random numbers' )
% A2 = rand(100,100);
% B2 = rand(100,100);
% tic  % start timer
% C = mult(A2,B2);
% timeTaken100 = toc  % stop timer and store the time taken
% display( ['Time for 100x100: ', num2str(timeTaken100), ' secs'] )
% print the top-left 5x5 block of C
% display( C( 1:5 , 1:5 ) )
% 
% display( '** 200x200 matrices of random numbers' )
% A2 = rand(200,200);
% B2 = rand(200,200);
% tic
% C = mult(A2,B2);
% timeTaken200 = toc;
% % print the top-left 5x5 block of C
% display( C( 1:5 , 1:5 ) )
% display( ['Time for 200x200: ', num2str(timeTaken200), ' secs'] )
% 
% display( '** 1000x1000 matrices of random numbers' )
% A2 = rand(1000,1000);
% B2 = rand(1000,1000);
% tic
% C = mult(A2,B2);
% timeTaken1000 = toc;
% % print the top-left 5x5 block of C
% display( C( 1:5 , 1:5 ) )
% display( ['Time for 1000x1000: ', num2str(timeTaken1000), ' secs'] )% 
% 
% % Now compute the ratio of the times taken for the two different sizes
% % and compare with the (known) complexity
% % (note the prediction does not match exactly because it is valid only
% % as n tends to infinity, but it is a reasonable guide)
% 
% display( ['Ratio of times ', num2str(timeTaken1000/timeTaken200), ...
%     ' large-n prediction ' num2str( (1000/200)^3 ) , ' using O(n^3)' ] )
% 
% % The last part shows that MATLAB is rather efficient at dealing
% % with matrices...
% 
% tic
% C = A2*B2;
% timeTakenML = toc;
% display( ['! MATLAB multiplication time (1000x1000 matrix): ', ...
%       num2str(timeTakenML) ,  'secs' ] )





