>> % Compute 7 factorial. >> 7*6*5*4*3*2*1 ans = 5040 >> % Compute 7 factorial using a "for" loop. >> n = 7; >> nfact = 1; >> for i=1:n, nfact = nfact*i; end; >> nfact nfact = 5040 >> % Compute 7 factorial using a "for" loop, going backwards. >> nfact = 1; >> for i=n:-1:1, nfact = nfact*i; end; >> nfact nfact = 5040 >> % Compute 7 factorial by running commands in the file fact.m. >> fact Enter n: 7 nfact = 5040 >> % Compute 10 factorial by running commands in the file fact.m. >> fact Enter n: 10 nfact = 3628800 >> % Compute 10 factorial using the function factorial (in file factorial.m). >> factorial(10) ans = 3628800 >> % Load a 2 by 2 matrix A with entries 1 and 2 in the first row, >> % 3 and 4 in the second. >> A = [1 2; 3 4] A = 1 2 3 4 >> % Load a 2 by 2 matrix B with entries 5 and 6 in the first row, >> % 7 and 8 in the second. >> B = [5 6; 7 8] B = 5 6 7 8 >> % Compute the product A*B. >> A*B ans = 19 22 43 50 >> % Load two random 10 by 10 matrices A and B. >> A = randn(10,10); B = randn(10,10); >> % Count the number of operations used to compute A*B. >> flops(0) % This zeros the flop count. >> A*B; >> flops ans = 2000 >> % Now load two random 20 by 20 matrices A and B. >> A = randn(20,20); B = randn(20,20); >> % Count the number of operations to compute A*B. >> % Should be 8*2000=16000, since op count is O(n^3). >> flops(0) >> A*B; >> flops ans = 16000 >> % Eureka it worked! Signing off now... >> exit 16000 flops.