Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Recall that if A is an m n matrix and B is a p q matrix, then the product C = A B is defined

Recall that if A is an mn matrix and B is a pq matrix, then the product C=AB is defined if and only if n=p, in which case C is an mq matrix.
Each row of the matrix AB can be computed as the product of the corresponding row of A times the matrix B :
AB=[vec(a)1Bvec(a)2Bvdotsvec(a)mB]
.vec(c)i=vec(a)iB, where vec(c)i and vec(a)i are the th rows of C and A respectively.
For instance, if A is 34 and B is 45, the product AB is given by the matrix:
C={A(1,:)**B;A(2,:)**B;A(3,:)**B}
Write a function named rowproduct that takes as input two matrices A and B and a random number k, and as output produces the product, C, by rows of the two matrices and the intermediate value, z, of the output matrix at the end of k iterations (the matrix z is used by MATLAB Grader to determine whether your code is correct).
The function should work for any dimension of A and B and it should perform a check to see if the dimensions match and return an empty product matrix if the dimensions do not match.
Specific instructions for writing the function:
Extract the dimension of A using the command size and store the result in the variables m and n.
Extract the dimension of B using the command size and store the result in the variables p and q
Use an if statement to perform a check on the dimensions to determine whether the multiplication is defined
If the multiplication is defined:
initialize C as a matrix of zeros of the appropriate dimension
use a single for loop to evaluate the product C=AB. The loop counter should be the variable i. Each iteration of the for loop should evaluate the ith row of the matrix C as the product of the i th row of the matrix A times the matrix B. Also, inside the for loop, after you compute the ith row of C, insert the following commands:
if isequal (i,k)
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial Accounting

Authors: Jerry J. Weygandt, Paul D. Kimmel, Donald E. Kieso

9th Edition

1118334329, 978-1118334324

Students also viewed these Databases questions