Multivariate polynomials - convert monomial form to array - MATLAB Cody - MATLAB Central

Problem 44260. Multivariate polynomials - convert monomial form to array

Difficulty:Rate

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:

  1. Defining a polynomial is an indexing headache, with a high probability of errors.
  2. 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 Stats

39.29% Correct | 60.71% Incorrect
Last Solution submitted on Jul 26, 2023

Problem Comments

Solution Comments

Show comments
Why should you share code?
In a discussion on LInkedin about my recent blog post, Do these...
1
3

Problem Recent Solvers10

Suggested Problems

More from this Author9

Community Treasure Hunt

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

Start Hunting!