In Problem 44260, multivariate polynomials were defined as a sum of monomial terms using|exponents|, a matrix of integers, and|coefficients|, 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.
Extract leading non-zero digit
919 Solvers
422 Solvers
108 Solvers
Multiples of a Number in a Given Range
108 Solvers
200 Solvers