Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Matrix Multiplication By now, you should understand the rules for matrix multipl

ID: 3031865 • Letter: M

Question

Matrix Multiplication By now, you should understand the rules for matrix multiplication in linear algebra and how MATLAB makes this easy. To fully appreciate how MATLAB does this, you will "manually" write code to replicate what MATLAB's matrix multiplication operator (*) does "behind the scenes." Using the matrices A and B shown below, write a nested for loop in MATLAB to "manually" multiply them according to the rules of linear algebra. Your result should agree with the product AB shown below. A = [1 2 3 4] B = [2 3 4 5] AB = [10 18 22 29]

Explanation / Answer

A=[1 2 ;3 4]

B=[2 3; 4 5];
[rowsA, colsA] = size(A);
[rowsB, colsB] = size(B);
theMatrixProduct = zeros(rowsA, colsB);

for row = 1 : rowsA
   row % Print progress to command window.
   for col = 1 : colsB
       theSum = 0;
       for k = 1 : colsA
           theSum = theSum + A(row, k) * B(k, col);
       end
       theMatrixProduct(row, col) = theSum;
   end
end