Cody

Problem 44262. Multivariate polynomials - overload multiplication

Solution 2877776

Submitted on 25 Aug 2020 by Rafael S.T. Vieira
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))

ex = 0 0 0 co = 307152

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]))

ex = 3 0 0 2 0 0 1 1 0 0 1 0 co = -1 2 1 -2

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]))

ex = 2 0 1 2 0 0 0 1 1 0 1 0 co = -1 2 1 -2

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]'))

ex = 5 0 0 3 2 0 3 0 2 3 0 0 2 0 1 0 2 1 0 0 3 0 0 1 co = -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))

ex = 915 1802 0 984 1669 0 1190 1078 0 1259 945 0 853 1122 0 1128 398 0 co = 574911 438795 267714 204330 592224 275776 ex = 915 1802 0 984 1669 0 1190 1078 0 1259 945 0 853 1122 0 1128 398 0 co = 574911 438795 267714 204330 592224 275776

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!