| matlab求多项式的系数: 
 单变量:
 
 syms x y
 f1=x^4+2*x+1;
 f2=y^6+5*y^3+3;
 f3=x^5+2*x^3*y^4+x*y^2+4;
 c = sym2poly(f1)
 c =
 1     0     0     2     1
 >> c = sym2poly(f2)
 c =
 1     0     0     5     0     0     3
 
 多变量:
 
 unction coef=poly_coef(f,var)
 %提取多项式f中指定变量var的系数,将结果赋给数组coef
 %f可以是含多变量的多项式
 %var是多项式中指定的变量,可选,默认是x
 %要用到函数poly_degree()来获得f中指定变量var的最高次幂
 IF nargin==1
 var=sym('x');
 end
 degree=poly_degree(f,var);
 temp_f=f;
 coef(degree+1)=subs(temp_f,var,0);
 for n=1:degree
 temp_f=simple((temp_f-coef(degree+2-n))/var);
 coef(degree+1-n)=subs(temp_f,var,0);
 end
 end
 举几个例子:
 复制内容到剪贴板
 代码:
 
 >> syms x y
 >> f1=x^4+2*x+1;
 >> f2=y^6+5*y^3+3;
 >> f3=x^5+2*x^3*y^4+x*y^2+4;
 >> poly_coef(f1)
 
 ans =
 
 [1, 0, 0, 2, 1]
 >> poly_coef(f1,y)
 
 ans =
 
 [ 4       ]
 [x   + 2 x + 1]
 >> poly_coef(f2)
 
 ans =
 
 [ 6    3 ]
 [y   + 5 y   + 3]
 >> poly_coef(f2,y)
 
 ans =
 
 [1, 0, 0, 5, 0, 0, 3]
 >> poly_coef(f3)
 
 ans =
 
 [       4    2 ]
 [1, 0, 2 y , 0, y , 4]
 >> poly_coef(f3,y)
 
 ans =
 
 [ 3          5 ]
 [2 x , 0, x, 0, x   + 4]
 
 |