function priority1 % *************************************************************** % * This program shows the importance of performing arithmetic * % * operations in the right order. * % * y2 and y3 should be identical. * % * y1 should differ and be more accurate. * % *************************************************************** format compact n=1000; A=randn(n); B=randn(n); x=randn(n,1); % tic y1=A*(B*x); t1=toc % tic y2=A*B*x; t2=toc % tic y3=(A*B)*x; t3=toc % check12=norm(y1-y2)/norm(y1) check13=norm(y1-y3)/norm(y1) % tic y4=-(A*x); t4=toc % tic y5=-A*x; t5=toc % tic y6=0-A*x; t6=toc % tic y7=0.0-A*x; t7=toc %