MATLAB has a few functions for creating and manipulating single-variable polynomials, but outside of the Symbolic Math Toolbox there is nothing for multivariate polynomials such as y-x^2 or x^2+y^2+z^2-1. Generalizing the approach for one variable, we can define an array of coefficients with one dimension for each variable. We will index them in decreasing order, for example if p(x) = A + B x^3, then the coefficients are
c = [B 0 0 A].
Note this is same order as used by the builtin functions. A couple more examples: if p(x,y) = x - y^2, then
c = [0 -1; 0 0; 1 0].
If p(x,y,z) = z-2, then c has dimensions [1 1 2] with c(:,:,1) = 1 and c(:,:,2) = -2.
The challenge is to create a function polyMult that takes two arrays of coefficients for polynomials p1 and p2 and returns the coefficients for p1*p2. See the tests for examples.
Solution Stats
Problem Comments
Solution Comments
Show commentsProblem Recent Solvers23
Suggested Problems
-
Remove any row in which a NaN appears
8790 Solvers
-
Count from 0 to N^M in base N.
241 Solvers
-
1538 Solvers
-
Create a Multiplication table matrix...
696 Solvers
-
155 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!
Can you explain why is the same matrix c = [0 -1; 0 0 ; 1 0] used to represent two different polynomials p(x,y) = x-y^2 (as in problem definition above) and p(x,y) = y - x^2 as in test example 3 on the solution page?