Problem 44263. Multivariate polynomials - emulate symbolic form

Solution 2980768

Submitted on 22 Sep 2020 by Rafael S.T. Vieira
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test Status Code Input and Output
1   Pass
filetext = fileread('mPolySym.m'); assert(~contains(filetext,'regexp'))

2   Pass
r = randi(1000); x = mPolySym(r); assert(isempty(x.varnames)) assert(isequal(x.exponents,0)) assert(isequal(x.coefficients,r))

3   Pass
r = randi(1000); x = mPolySym('x'); y = r*x; assert(isequal(y.varnames,"x")) assert(isequal(y.exponents,1)) assert(isequal(y.coefficients,r)) assert(isequal(r*x,x*r))

4   Pass
x = mPolySym('x'); y = mPolySym("y"); z = mPolySym('z'); w = x*y*z; assert(isequal(w.varnames,["x" "y" "z"])) assert(isequal(w.exponents,[1 1 1])) assert(isequal(w.coefficients,1))

5   Pass
m = randi(5); n = randi(4); x = mPolySym("x"); y = mPolySym("y"); p = [repmat(x,1,m) repmat(y,1,n)]; p = p(randperm(length(p))); r = randi(1000); p_prod = r; for ii=1:length(p) p_prod = p_prod*p(ii); end s = randi(1000); p_prod = p_prod*s; assert(isequal(p_prod.varnames,["x" "y"])) assert(isequal(p_prod.exponents,[m n])) assert(isequal(p_prod.coefficients,r*s))

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!