% efficiency: comarison of three programs; 
% each program computes a vector x(i)=1/i for i=1:N 
clear all
N=10^7;
% 1-st method
tic;
for i=1:N
    x(i)=1/i; % the size of x grows inside the loop
end
time=toc; fprintf('time1=%6.4f\n',time)
% 2-nd method
clear x;
tic;
x=zeros(1,N); % preallocation for x array
for i=1:N
    x(i)=1/i;
end
time=toc; fprintf('time2=%6.4f\n',time)
% 3-nd method
clear x;
tic;
i=1:N;x=1./i;  % no loops, "vectorization"
time=toc; fprintf('time3=%6.4f\n',time)