MATLAB: From symbolic expression to vector

symbolicvector

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].

Best Answer

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]