From symbolic expression to vector

6 views (last 30 days)
I have a symbolic expression in the form of a polynomial in several variables (e.g. 2*x*y*z - x*z - y*z - x*y + 1), is there any way I could get a vector out of this, I mean something like [2*x*y*z, - x*z, - y*z, - x*y, 1].

Accepted Answer

Star Strider
Star Strider on 23 Jun 2015
Use the coeffs function and then get slightly creative:
syms x y z
f = 2*x*y*z - x*z - y*z - x*y + 1;
[cf,T] = coeffs(f);
V = cf .* T % Desired Output
V =
[ 2*x*y*z, -x*y, -x*z, -y*z, 1]

More Answers (0)

Community Treasure Hunt

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

Start Hunting!