终于我找到了一种解决方案。 不幸的是(或没有),我使用了Symbolic Toolbox 。 就我而言,我考虑了7个符号变量,多项式的变量是X和Y matlab变量poly是一个包含字段p的struct 。 p是多项式的symfun矩阵。
对于输出参数, C , E , MX和MY分别包含在polyOut.mult , polyOut.exph , polyOut.expoX和polyOut.expoY 。
%% Build the polynomial matrices
function polyOut=buildPolyMat(poly)
syms X Y real
syms c11 c12 c21 c22 c33 real
P=poly.p(X,Y);
sizP=size(P);
polyOut.mult=sym(zeros(sizP));
polyOut.expoX=zeros(sizP);
polyOut.expoY=zeros(sizP);
%for each term of the polynomial matrix
for it=1:prod(sizP)
%polynomial
pT=P(it);
%read coeff and exponents
[C,M]=coeffs(pT,[X,Y]);
if ~isempty(C)
%subscripts in matrix
[sC,sR]=ind2sub(sizP,it);
%exponents
for iE=1:numel(C)
eX=feval(symengine,'degree',M(iE),X);
eY=feval(symengine,'degree',M(iE),Y);
polyOut.mult(sC,sR,iE)=C(iE);
polyOut.expoX(sC,sR,iE)=eX;
polyOut.expoY(sC,sR,iE)=eY;
end
end
end
polyOut.exph=poly.eH*ones(size(polyOut.mult));
%clean matrices with zeros multiplier
Ind=(polyOut.mult==0);
polyOut.expoX(Ind)=0;
polyOut.expoY(Ind)=0;
polyOut.exph(Ind)=0;
end