% Name: % main function for Exercise 1 clear all close all format compact % Test the two functions matVec and invMatVec R = triu(rand(5))+ eye(5); %generate random 5 x 5 triangular matrix R x = rand(5,1); %generate random 5 x 1 vector x %calculate solution of Rx with matVec %calculate solution of Rx with * %compare the two solutions %calculate solution of R^{-1}x with invMatVec %calculate solution of R^{-1}x with \ %compare the two solutions % Time measurements N= 2.^[1:12]; %take 2^[1:10] for old PC's % Rx b1 = matVec(R,x); timeMV = zeros(size(N,2),1); for k = 1:size(N,2) n = N(k) % create Random n x n upper triangular matrix R % create random n x 1 vector x tic % calculate solution b = Rx timeMV(k) = toc; end % R^{-1}x b1 = invMatVec(R,x); timeIMV = zeros(size(N,2),1); for k = 1:size(N,2) n = N(k) % create Random n x n upper triangular matrix R % create random n x 1 vector x tic % calculate solution b = R^{-1}x timeIMV(k) = toc; end % Create loglog Plot for the times loglog(N,timeMV,'d-') hold on loglog(N,timeIMV,'ro-') legend('MatVec','InvMatVec','location','SouthEast') xlabel('N') ylabel('time [s]') xlim([1,5000])