Question

# Recall that if A is an m × n matrix and B is a p ×...

Recall that if A is an m × n matrix and B is a p × q matrix, then the product C = AB is defined if and only if n = p, in which case C is an m × q matrix. (a) Write a function M-file that takes as input two matrices A and B, and as output produces the product by columns of the two matrix. For instance, if A is 3 × 4 and B is 4 × 5, the product is given by the matrix C = [A*B(:,1), A*B(:,2), A*B(:,3), A*B(:,4), A*B(:,5)] The function file should work for any dimension of A and B and it should perform a check to see if the dimensions match (Hint: use a for loop to define each column of C). Call the file columnproduct.m. Test your function on a random 3×5 matrix A and a random 5×2 matrix B . Compare the output with A*B. Repeat with 4 × 6 and 6 × 2 matrices and with 4 × 6 and 2 × 6 matrices. Use the command rand to generate the random matrices for testing. Include in your lab report the function M-file and the output obtained by running it. (b) Write a function M-file that takes as input two matrices A and B, and as output produces the product by rows of the two matrices. For instance, if A is 3 × 4 and B is 4 × 5, the product AB is given by the matrix C = [A(1,:)*B; A(2,:)*B; A(3,:)*B] The function file should work for any dimension of A and B and it should perform a check to see if the dimensions match (Hint: use a for loop to define each row of C). Call the file rowproduct.m. Test your function on a random 3×5 matrix A and a random 5×2 matrix B . Compare the output with A*B. Repeat with 4 × 6 and 6 × 2 matrices and with 4 × 6 and 2 × 6 matrices. Use the command rand to generate the random matrices for testing. Include in your lab report the function M-file and the output obtained by running it.

PLEASE GIVE IT A THUMBS UP, I SERIOUSLY NEED ONE, IF YOU NEED ANY MODIFICATION THEN LET ME KNOW, I WILL DO IT FOR YOU  #### Earn Coins

Coins can be redeemed for fabulous gifts.