%% illustrates vector/matrix operations b = [ 1 ; 2] C = [3 1; 1 3] b' * C * b % C being PSD means that all products like above are non-negative %% time trials b = normrnd(0,1,500,1); tic % for reps = 1:1000, total = 0; for i = 1:length(b), total = total + b(i); end %end toc %% now vectorized form one = ones(1,length(b)); tic sumb = one*b; toc tic sumb = sum(b); toc