得到复方程的系数

时间:2013-03-14 19:25:31

标签: matlab

我试图得到以下等式的系数:

enter image description here

我的代码是:

args=[1,1,1,0,0,0,0,0,-5,0];
a=args(1);b=args(2);c=args(3);d=args(4);e=args(5);f=args(6);g=args(7);h=args(8);m=args(9);s=args(10); %M=i  , j = s

syms x y z real


Q=[a,d,e,g;
   d,b,f,h;
   e,f,c,m;
   g,h,m,s];
X=[x,y,z,1]';

func(x,y,z)=X'*Q*X;

[A,B]=coeffs(func)

我的问题是我没有得到所有具有零值的系数 我的结果应该是: [1,1,1,0,0,0,0,0,-5,0]

我得到: [1,1,1,-10]

我如何获得零

1 个答案:

答案 0 :(得分:0)

我找到的唯一解决方案是:

[parameters,Eqations]=coeffs(funcToConvert)
parameters= sym2poly(parameters(x,y,z));

EqationsCells=arrayfun(@char,Eqations(x,y,z),'Un',0);


SerachRes=Myeq(EqationsCells,{'matrix([[x^2, 1, 1]])'});
index= GetSearchIndex( SerachRes );
if 0==index
    a=0;
else
    a=parameters(index);
end


SerachRes=Myeq(EqationsCells,{'matrix([[x, x, 1]])'});
index= GetSearchIndex( SerachRes );
if 0==index
    d=0;
else
    d=parameters(index)/2;
end

SerachRes=Myeq(EqationsCells,{'matrix([[x, 1, x]])'});
index= GetSearchIndex( SerachRes );
if 0==index
    e=0;
else
    e=parameters(index)/2;
end



SerachRes=Myeq(EqationsCells,{'matrix([[x, 1, 1]])'});
index= GetSearchIndex( SerachRes );
if 0==index
    g=0;
else
    g=parameters(index)/2;
end


SerachRes=Myeq(EqationsCells,{'matrix([[1, x^2, 1]])'});
index= GetSearchIndex( SerachRes );
if 0==index
    b=0;
else
    b=parameters(index);
end


SerachRes=Myeq(EqationsCells,{'matrix([[1, x, x]])'});
index= GetSearchIndex( SerachRes );
if 0==index
    f=0;
else
    f=parameters(index)/2;
end


SerachRes=Myeq(EqationsCells,{'matrix([[1, x, 1]])'});
index= GetSearchIndex( SerachRes );
if 0==index
    h=0;
else
    h=parameters(index)/2;
end


SerachRes=Myeq(EqationsCells,{'matrix([[1, 1, x^2]])'});
index= GetSearchIndex( SerachRes );
if 0==index
    c=0;
else
    c=parameters(index);
end


SerachRes=Myeq(EqationsCells,{'matrix([[1, 1, x]])'});
index= GetSearchIndex( SerachRes );
if 0==index
    m=0;
else
    m=parameters(index)/2;
end



SerachRes=Myeq(EqationsCells,{'matrix([[1, 1, 1]])'});
index= GetSearchIndex( SerachRes );
if 0==index
    s=0;
else
    s=parameters(index);
end

但似乎效率不高