% Compare program execution speed for vector addition

len= 1000;
a= rand(1,len);
b= rand(1,len);

% c = a + b using loop
tic;
  for i = 1:len
      c(i)= a(i) + b(i);
  end
  disp([num2str(toc) ' seconds using loop']);
  
% c = a + b using loop with preallocated vector
tic;
  d= zeros(1,len);
  for i= 1:len
      d(i)= a(i) + b(i);
  end
  disp([num2str(toc) ' seconds using loop with preallocated vector']);
  
% c = a + b using vectorized code
tic;
  e= a + b;
  disp([num2str(toc) ' seconds using vectorized code']);
