Problem 44260. Multivariate polynomials - convert monomial form to array
In Problem 44259 I asked you to multiply two multidimensional polynomials that were represented by an array that is a generalization of the way MATLAB handles one-variable polynomials. However, that representation has at least two problems:
- Defining a polynomial is an indexing headache, with a high probability of errors.
- Polynomials often have a small number of terms, so if they are higher order there will be a lot of wasted storage.
Here, we will represent a polynomial as a sum of monomials. For example, the polynomial p(x,y) = 2*x^5*y + 3*x*y^5 is the sum of two monomials in x and y. We will represent this by exponents, a matrix of integers with each row representing the exponents of one monomial (including zeros); and a column vector coefficients for the coefficient of each monomial. For p(x,y), these are
exponents = [5 1; 1 5]; coefficients = [2; 3];
Let's hedge our bets, though, and create a function that converts this form to the array form. Your task is to create a function
function c = coeffArray(exponents,coefficients)
that inputs the exponents and coefficients and returns an array as defined in Problem 44259.
Solution CommentsShow comments
Problem Recent Solvers10