Cody

# Problem 2237. Mmm! Multi-dimensional Matrix Multiplication

Solution 1163220

Submitted on 14 Apr 2017
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
A = 1; B = 2; C = mtimesm(A,B); C_correct = 2; assert(isequal(C,C_correct))

2   Pass
A = rand(2,3); B = rand(3,4); C = mtimesm(A,B); C_correct = A*B; assert(isequal(C,C_correct))

3   Pass
A = rand(2,3); B = 2; C = mtimesm(A,B); C_correct = 2*A; assert(isequal(C,C_correct))

4   Fail
A = rand(2,3,2); B = rand(3,4,2); C = mtimesm(A,B); C_correct = cat(3,A(:,:,1)*B(:,:,1),A(:,:,2)*B(:,:,2)); assert(isequal(C,C_correct))

Error using * Arguments must be 2-D, or at least one argument must be scalar. Use TIMES (.*) for elementwise multiplication. Error in mtimesm (line 2) C = A*B; Error in TestPoint4 (line 3) C = mtimesm(A,B);

5   Fail
A = rand(2,3,3); B = rand(3,4); C = mtimesm(A,B); C_correct = cat(3,A(:,:,1)*B,A(:,:,2)*B,A(:,:,3)*B); assert(isequal(C,C_correct))

Error using * Arguments must be 2-D, or at least one argument must be scalar. Use TIMES (.*) for elementwise multiplication. Error in mtimesm (line 2) C = A*B; Error in TestPoint5 (line 3) C = mtimesm(A,B);

6   Fail
A = rand(4,3,1,2); B = rand(3,2,2); C = mtimesm(A,B); C_correct(:,:,1,1) = A(:,:,1,1)*B(:,:,1); C_correct(:,:,1,2) = A(:,:,1,2)*B(:,:,1); C_correct(:,:,2,1) = A(:,:,1,1)*B(:,:,2); C_correct(:,:,2,2) = A(:,:,1,2)*B(:,:,2); assert(isequal(C,C_correct))

Error using * Arguments must be 2-D, or at least one argument must be scalar. Use TIMES (.*) for elementwise multiplication. Error in mtimesm (line 2) C = A*B; Error in TestPoint6 (line 3) C = mtimesm(A,B);

7   Fail
A = rand(4,3,1,2); B = rand(3,2,1,1,2); C = mtimesm(A,B); C_correct(:,:,1,1,1) = A(:,:,1,1)*B(:,:,1,1,1); C_correct(:,:,1,1,2) = A(:,:,1,1)*B(:,:,1,1,2); C_correct(:,:,1,2,1) = A(:,:,1,2)*B(:,:,1,1,1); C_correct(:,:,1,2,2) = A(:,:,1,2)*B(:,:,1,1,2); assert(isequal(C,C_correct))

Error using * Arguments must be 2-D, or at least one argument must be scalar. Use TIMES (.*) for elementwise multiplication. Error in mtimesm (line 2) C = A*B; Error in TestPoint7 (line 3) C = mtimesm(A,B);