2 Write your own code to perform matrix multiplication Recal
2. Write your own code to perform matrix multiplication. Recall that to multiply two matrices, the inner dimensions must be the same. [A]mn[B]np = [C]mp Every element in the resulting C matrix is obtained by: Cij= aikbkj You code must be a function file and it must check to see if matrix multiplication can be performed on the provided matrices. Test your code for the following conditions: ALL DONE IN MATLAB
A= 2 -1 7 4 5 3 6 2 5
B= 6 4 2 1 9 -3
A= 2 -1 7 4 5 3 6 2 5
B= 6 4 2 1 9 -3
Solution
A= [2 -1 7; 4 5 3; 6 2 5];
B= [6 4; 2 1; 9 -3];
[nRow1,nCol1]=size(A);
[nRow2,nCol2]=size(B);
if (nCol1 ~= nRow2)
error(\'inner dimensions do not match\');
end
C = zeros(nRow1,nCol2);
for i = 1:nRow1
for j = 1:nCol2
for k = 1:nCol1
C(i,j) = C(i,j) + A(i,k)*B(k,j);
end
end
end
C
73 -14
61 12
85 11
![2. Write your own code to perform matrix multiplication. Recall that to multiply two matrices, the inner dimensions must be the same. [A]mn[B]np = [C]mp Every e 2. Write your own code to perform matrix multiplication. Recall that to multiply two matrices, the inner dimensions must be the same. [A]mn[B]np = [C]mp Every e](/WebImages/37/2-write-your-own-code-to-perform-matrix-multiplication-recal-1110618-1761588797-0.webp)