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 Stats
Problem Comments
-
5 Comments
What is the matrix form for, say, A*x^2+B*x*y+C*y^2+D*x+E*y+F?
Tim, it is
exponents = [2 0; 1 1; 0 2; 1 0; 0 1; 0 0];
coefficients = [A B C D E F]';
What I meant to ask was, what is the correct output from coeffArray for that case?
@Tim The correct output from coeffArray for A*x^2+B*x*y+C*y^2+D*x+E*y+F should be [0 0 A;0 B D;C E F]
Shouldn't the single variable case be a row vector? "a matrix of integers with each row representing the exponents of one monomial" The test suite is representing it as a column. I guess you meant a matrix of integers with each row representing an exponent of one variable or with each row of size n representing the exponents of n variables.
Solution Comments
Show commentsProblem Recent Solvers10
Suggested Problems
-
Test if two numbers have the same digits
243 Solvers
-
ベクトル [1 2 3 4 5 6 7 8 9 10] の作成
556 Solvers
-
44 Solvers
-
91 Solvers
-
Outer product of multiple vectors
69 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!