Cody

Problem 2237. Mmm! Multi-dimensional Matrix Multiplication

Solution 415174

Submitted on 8 Mar 2014
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   Fail
%% case 1 A = 1; B = 2; C = mtimesm(A,B); C_correct = 2; assert(isequal(C,C_correct))

Error: Error: File: mtimesm.m Line: 2 Column: 2 An array for multiple LHS assignment cannot contain expressions.

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

Error: Error: File: mtimesm.m Line: 2 Column: 2 An array for multiple LHS assignment cannot contain expressions.

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

Error: Error: File: mtimesm.m Line: 2 Column: 2 An array for multiple LHS assignment cannot contain expressions.

4   Fail
%% case 4 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: Error: File: mtimesm.m Line: 2 Column: 2 An array for multiple LHS assignment cannot contain expressions.

5   Fail
%% case 5 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: Error: File: mtimesm.m Line: 2 Column: 2 An array for multiple LHS assignment cannot contain expressions.

6   Fail
%% case 6 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: Error: File: mtimesm.m Line: 2 Column: 2 An array for multiple LHS assignment cannot contain expressions.

7   Fail
%% case 7 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: Error: File: mtimesm.m Line: 2 Column: 2 An array for multiple LHS assignment cannot contain expressions.

Suggested Problems

More from this Author31

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!