Cody

Solution 1236245

Submitted on 21 Jul 2017 by LY Cao
  • Size: 67
  • This is the leading solution.
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('mPoly.m'); assert(~contains(filetext,'regexp'))

2   Pass
c1 = randi(1000); c2 = randi(1000); e = 0; p1 = mPoly(e,c1); p2 = mPoly(e,c2); p = p1*p2; assert(isequal(c1*c2,p.coefficients)) assert(isequal(e,p.exponents))

3   Pass
e1 = [2 0; 0 1]; c1 = [-1; 1]; e2 = [1 0; 0 0]; c2 = [1; -2]; p1 = mPoly(e1,c1); p2 = mPoly(e2,c2); p = p1*p2; [e,idx] = unique(p.exponents,'rows'); c = p.coefficients(idx); assert(isequal(e,[0 1; 1 1; 2 0; 3 0])) assert(isequal(c,[-2; 1; 2; -1]))

4   Pass
e1 = [0 1 0; 2 0 0]; c1 = [1; -1]; e2 = [0 0 1; 0 0 0]; c2 = [1; -2]; p1 = mPoly(e1,c1); p2 = mPoly(e2,c2); p = p1*p2; [e,idx] = unique(p.exponents,'rows'); c = p.coefficients(idx); assert(isequal(e,[0 1 0; 0 1 1; 2 0 0; 2 0 1])) assert(isequal(c,[-2; 1; 2; -1]))

5   Pass
e1 = [0 0 1; 3 0 0]; c1 = [1; -1]; e2 = [2 0 0; 0 2 0; 0 0 2; 0 0 0]; c2 = [1; 1; 1; -1]; p1 = mPoly(e1,c1); p2 = mPoly(e2,c2); p = p1*p2; [e,idx] = unique(p.exponents,'rows'); c = p.coefficients(idx); assert(isequal(e,[0 0 1; 0 0 3; 0 2 1; 2 0 1; 3 0 0; 3 0 2; 3 2 0; 5 0 0])) assert(isequal(c,[-1 1 1 1 1 -1 -1 -1]'))

6   Pass
c1 = randi(1000,[2 1]); e1 = randi(1000,[2 2]); c2 = randi(1000,[3 1]); e2 = randi(1000,[3 2]); p1 = mPoly(e1,c1); p2 = mPoly(e2,c2); p12 = p1*p2; p21 = p2*p1; [e12,i12] = unique(p12.exponents,'rows'); [e21,i21] = unique(p21.exponents,'rows'); c12 = p12.coefficients(i12); c21 = p21.coefficients(i21); assert(isequal(e12,e21)) assert(isequal(c12,c21))