Menu

P2 Write Matlab Function Inputs M N P Three Positi Ve Integers Matrix Size M X N Matrix B Q43824798

ने P2. Write a MATLAB function with inputs • m, n, and p, three positi ve integers, • a matrix A of size m x n, • a matrix Bने P2. Write a MATLAB function with inputs • m, n, and p, three positi ve integers, • a matrix A of size m x n, • a matrix B of size n x p. and which outputs the product matrix A x B (note that the size of this matrix should be mx p). Your code should check that the sizes are right and then do the multiplication using three nested “for” loops. a) How many floating point operations (additions and multiplications) does the code use? Find a formula in terms of m, n, and p. b) Run the code with m = 100, n = 100, p = 100, and inputs A =rand (m, n) and B =rand (n, p). Modify the func tion by introducing a new output variable, flop, which initializes to 0 outside of the nested for loops (just like we did with inner.-product in class) and is incremented inside the innermost of the for loops by the mumber of operations done to update the product computation. Out put the product as well as flop. Repeat the experiment for m = 200, n = 100, p= 100; m = 100, n = 200, p 10%3B 100, n = 100; p = 200; andn= m = p = 200. Do the ratios of the new flop outputs to the old one you got for m = n = p = 100 to confirm the floating point operation formula you found in part a). m%3D Show transcribed image text ने P2. Write a MATLAB function with inputs • m, n, and p, three positi ve integers, • a matrix A of size m x n, • a matrix B of size n x p. and which outputs the product matrix A x B (note that the size of this matrix should be mx p). Your code should check that the sizes are right and then do the multiplication using three nested “for” loops. a) How many floating point operations (additions and multiplications) does the code use? Find a formula in terms of m, n, and p. b) Run the code with m = 100, n = 100, p = 100, and inputs A =rand (m, n) and B =rand (n, p). Modify the func tion by introducing a new output variable, flop, which initializes to 0 outside of the nested for loops (just like we did with inner.-product in class) and is incremented inside the innermost of the for loops by the mumber of operations done to update the product computation. Out put the product as well as flop. Repeat the experiment for m = 200, n = 100, p= 100; m = 100, n = 200, p 10%3B 100, n = 100; p = 200; andn= m = p = 200. Do the ratios of the new flop outputs to the old one you got for m = n = p = 100 to confirm the floating point operation formula you found in part a). m%3D

Expert Answer


Answer to ने P2. Write a MATLAB function with inputs • m, n, and p, three positi ve integers, • a matrix A of size m x n, …

OR