How to use poly2list for specific variables?

Hi there,
In the example 2 of the help for 'poly2list' https://www.mathworks.com/help/symbolic/mupad_ref/poly2list.html?s_tid=srchtitle, it shows as follows:
In this example the polynomial is bivariate, thus exponent vectors are returned:
poly2list((x*(y + 1))^2, [x, y])
How to use this in MATLAB? I tried feval but it shows error:
>> syms x y
>> feval(symengine, 'poly2list', (x*(y + 1))^2, [x, y])
Error using mupadengine/feval (line 163)
The number of arguments is incorrect.
Thanks,
Dan

 채택된 답변

Walter Roberson
Walter Roberson 2017년 11월 30일

1 개 추천

symLIST = @(varargin)feval(symengine,'DOM_LIST',varargin{:});
feval(symengine,'poly2list', (x*(y + 1))^2, symLIST(x,y))

댓글 수: 5

Dan Li
Dan Li 2017년 11월 30일
Thanks very much!
This is a quite advanced usage, and not many people will understand why it is necessary to do things this way. But it works.
Dan Li
Dan Li 2017년 11월 30일
Hi Walter,
Thanks for the help.
If I want to store the symbolic variables in a matrix first, how to convert it correctly? For example: X = [x, y], then symLIST(X) will not generate a list of x y but a matrix([[x, y]]). I tried feval(symengine, 'coerce', X, 'DOM_LIST'), but this still not work for the poly2list.
varcell = num2cell(X);
feval(symengine,'poly2list', (x*(y + 1))^2, symLIST(varcell{:}))
Dan Li
Dan Li 2017년 11월 30일
Thanks you very much! This really helps me a lot!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Karan Gill
Karan Gill 2017년 11월 30일
편집: Karan Gill 2017년 12월 5일

0 개 추천

In general, I don't recommend using MuPAD commands, as the note at the top says.
Is coeffs helpful?
>> syms x y
p = (x*(y + 1))^2;
[C,T] = coeffs(p,[x y]) % C = coeffs, T = terms
C =
[ 1, 2, 1]
T =
[ x^2*y^2, x^2*y, x^2]

댓글 수: 1

Dan Li
Dan Li 2017년 11월 30일
I also want extract the power value of every variable in every monomial. Is there any way to convert the x^2*y^2 to [2, 2]?
Thanks,
Dan

댓글을 달려면 로그인하십시오.

질문:

2017년 11월 30일

편집:

2017년 12월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by