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.
Back to basics 25 - Valid variable names
253 Solvers
Create logical matrix with a specific row and column sums
104 Solvers
Given a matrix, return the last eigen value
137 Solvers
Create an n-by-n null matrix and fill with ones certain positions
140 Solvers
Sum the numbers on the main diagonal
375 Solvers