Problem 44261. Multivariate polynomials  sort monomials
In Problem 44260, multivariate polynomials were defined as a sum of monomial terms usingexponents, a matrix of integers, andcoefficients, a vector (follow the above link for an explanation). It can be useful to order the monomials. But first we need to define the total degree of a monomial as the sum of the exponents. For example, the total degree of 5*x is 1 and the total degree of x^3*y^5*z is 9.
Write a function
function [coeffs,exponents] = sortMonomials(coeffs,exponents)
to sort the monomials. Sort them first by descending total degree, and then for a given total degree, by lexicographical order of the exponents (by the first exponent, then the second, and so on, each in descending order). The coefficients should be sorted so they stay with the correct monomial.
Example: Consider the polynomial p(x,y,z) = 3*x  2 + y^2 +4*z^2, which is represented as:
exponents = [1 0 0; 0 0 0; 0 2 0; 0 0 2], coefficients = [3; 2; 1; 4]
The sorted version is
exponents = [0 2 0; 0 0 2; 1 0 0; 0 0 0], coefficients = [1; 3; 1; 4].
You can assume that a given combination of exponents is never repeated.
Solution Stats
Problem Comments
Solution Comments
Show commentsProblem Recent Solvers9
Suggested Problems

Create a function handle that reverses the input arguments of another function handle
145 Solvers

539 Solvers

Back to basics 12  Input Arguments
586 Solvers

Multiples of a Number in a Given Range
600 Solvers

Saving MATLAB session to a file
176 Solvers
More from this Author9
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!