Cody

# Problem 44261. Multivariate polynomials - sort monomials

Solution 2866790

Submitted on 22 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('sortMonomials.m'); assert(~contains(filetext,'regexp'))

2   Pass
unsortedCoeffs = [-10 7 -10 -7 6 6 3 1 -7 2]'; unsortedExponents = [5 4 2; 2 5 3; 2 1 5; 1 5 4; 1 4 3; 1 3 3; 1 2 1; 0 4 1; 0 2 1; 0 0 5]; [sortedCoeffs,sortedExponents] = sortMonomials(unsortedCoeffs,unsortedExponents); sortOrder = [1 2 4 3 5 6 8 10 7 9]; assert(isequal(sortedCoeffs,unsortedCoeffs(sortOrder))) assert(isequal(sortedExponents,unsortedExponents(sortOrder,:)))

3   Pass
x = randi(1000); y = randi(1000); [coeffs,exponents] = sortMonomials(x,y); assert(isequal([x y],[coeffs exponents]))

4   Pass
unsortedCoeffs = randi(1000,[4 1]); ough = ['hguot '; 'hguoc '; 'hguolp'; 'hguod ']; unsortedExponents = ough - repmat(randi(100),size(ough)); unsortedExponents = [unsortedExponents -sum(unsortedExponents,2)]; [sortedCoeffs,~] = sortMonomials(unsortedCoeffs,unsortedExponents); [~,ia] = sort(ough(:,5)); assert(isequal(sortedCoeffs,flipud(unsortedCoeffs(ia))))

5   Pass
z = [1 3 5+randi(10)]; v1 = perms(z); v2 = perms(z+[1 0 0]); v = [v2; v1]; unsortedCoeffs = randi(1000,[size(v,1) 1]); unsortedExponents = v(randperm(size(v,1)),:); [sortedCoeffs,sortedExponents] = sortMonomials(unsortedCoeffs,unsortedExponents); assert(isequal(sortedExponents,v))

### Community Treasure Hunt

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

Start Hunting!