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 Solvers21
Suggested Problems
-
Smallest distance between a point and a rectangle
279 Solvers
-
Find a subset that divides the vector into equal halves
401 Solvers
-
Set the array elements whose value is 13 to 0
1438 Solvers
-
98 Solvers
-
173 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?