%% Hilber matrix clear; clc; %% Dimension festlegen und Speicher preallokieren n = 5000; H = zeros(n); %% doppelte FOR-Schleife tic; for i = 1:n for j = 1:n H(i,j) = 1/(i+j-1); end end time(1) = toc; disp('###############'); disp(['doppelte FOR-Schleife ',num2str(time(1)),' sec.']); disp(H(n,n)); %% doppelte FOR-Schleife mit Ausnutzung der Symmetrie tic; for i = 1:n H(i,i) = 1/(2*i-1); for j = i+1:n H(i,j) = 1/(i+j-1); H(j,i) = H(i,j); end end time(2) = toc; disp('###############'); disp(['doppelte FOR-Schleife mit Ausnutzung der Symmetrie ',num2str(time(2)),' sec.']); disp(H(n,n)); %% äußere FOR-Schleife plus Vektoroperationen statt innerem FOR tic; j_vec = 1:n; for i = 1:n H(i,:) = 1./(i-1 + j_vec); end time(3) = toc; disp('###############'); disp(['äußere FOR-Schleife plus Vektoroperationen statt innerem FOR ',num2str(time(3)),' sec.']); disp(H(n,n)); %% oder einfach (in diesem Spezialfall) mit der Matlab-Fkt. tic; H = hilb(n); time(4) = toc; disp('###############'); disp(['via Matlab-Fkt. ',num2str(time(4)),' sec.']); disp(H(n,n));