Find the support of a mpol type variable
4 次查看(过去 30 天)
显示 更早的评论
Hi,
I have a polynomial of type mpol (ref: GloptiPoly 3: moments, optimization and semidefinite programming (archives-ouvertes.fr)).
It is like a symbolic polynomial defined in MATLAB.
The polynomial is of the form:
f= 1+a1*x1+a2*x2+a3*x3+a4*x4+a5*x1^2+a6*x1*x2+a7*x1*x3+a8*x1*x4+a9*x2^2+a10*x2*x3+......so on
I need to get its support/order of monomial terms, i.e:
[0,0,0,0;
1,0,0,0;
0,1,0,0;
0,0,1,0;
0,0,0,1;
2,0,0,0;
1,1,0,0;
1,0,1,0,
1,0,0,1;
0,2,0,0;
0,1,1,0;
...... so on]
I can get the coeffecients using the coef() function.
But, I need its support/monomial orders.
Is there any matlab function to do so?
Thanks a lot for your help.
Regards
0 个评论
回答(1 个)
SAI SRUJAN
2023-10-10
Hi Aksh Chordia,
I understand that you are trying to get the order of monomial terms for a given polynomial.
You can follow the below given example to resolve the issue.
syms a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 x1 x2 x3 x4
f= 1+a1*x1+a2*x2+a3*x3+a4*x4+a5*x1^2+a6*x1*x2+a7*x1*x3+a8*x1*x4+a9*x2^2+a10*x2*x3
ch=children(f)
order=[];
for i=1:length(ch)
exp=ch{i};
coeff=[polynomialDegree(exp,x1)];
coeff=[coeff polynomialDegree(exp,x2)];
coeff=[coeff polynomialDegree(exp,x3)];
coeff=[coeff polynomialDegree(exp,x4)];
order=[order;coeff];
end
order
You can use the "children" and "polynomialDegree" MATLAB function to get monomial order of a polynomial.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Polynomials 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!