Cody

Problem 44259. Product of two multivariate polynomials

Solution 1251925

Submitted on 16 Aug 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
filetext = fileread('polyMult.m'); assert(~contains(filetext,'regexp'))

2   Pass
c1 = randi(1000); c2 = randi(1000); assert(isequal(c1*c2,polyMult(c1,c2)))

3   Fail
c1 = [0 -1; 0 0; 1 0]; c2 = [1; -2]; c = [0 -1; 0 2; 1 0; -2 0]; assert(isequal(c,polyMult(c1,c2)))

Matrix dimensions must agree. Error in polyMult (line 2) c1.*c2; Error in Test3 (line 4) assert(isequal(c,polyMult(c1,c2)))

4   Pass
c1 = [0 -1; 0 0; 1 0]; c2 = reshape([1; -2],[1 1 2]); c = reshape([0 0 1 -1 0 0 0 0 -2 2 0 0],[3 2 2]); assert(isequal(c,polyMult(c1,c2)))

5   Fail
c1 = reshape([0 0 0 1 -1 0 0 0],[4 1 2]); c2 = [0 -1; 0 0; 1 0]; c3 = zeros([3 3 3]); c3([9 21 25]) = [1 1 1]; c3(27) = -1; c4 = reshape([1; -2],[1 1 2]); c = zeros(8,4,5); c([56 91 104 118 126 139 149 153]) = -2*ones(1,8); c([30 53 78 88 92 101 115 123]) = -1*ones(1,8); c([24 59 72 86 94 107 117 121]) = 1*ones(1,8); c([62 85 110 120 124 133 147 155]) = 2*ones(1,8); assert(isequal(c,polyMult(c1,polyMult(c2,polyMult(c3,c4)))))

Array dimensions must match for binary array op. Error in polyMult (line 2) c1.*c2; Error in Test5 (line 12) assert(isequal(c,polyMult(c1,polyMult(c2,polyMult(c3,c4)))))

6   Fail
c1 = randi(1000,[2 3 4]); c2 = randi(1000,[4 5 1]); assert(isequal(polyMult(c1,c2),polyMult(c2,c1)))

Array dimensions must match for binary array op. Error in polyMult (line 2) c1.*c2; Error in Test6 (line 3) assert(isequal(polyMult(c1,c2),polyMult(c2,c1)))

Suggested Problems

More from this Author9

Community Treasure Hunt

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

Start Hunting!