I have a polynomial like this one:
p := -1.604609130*10^(-11)*z^9+.1111140258*z^8+3.210741142*10^(-11)*z^7-.3955586214*z^6-2.108471910*10^(-11)*z^5+.6692726719*z^4+5.024523477*10^(-12)*z^3-.8174429322*z^2-3.142106870*10^(-13)*z+.9089252367
You see, just a regular polynomial with numeric coefficients. Then I call coeffs
on it and get this:
> coeffs(p, z, 't'); t
-11
0.9089252367, -0.3955586214, -2.108471910 10 , 0.6692726719,
-12 -11
5.024523477 10 , -0.8174429322, -1.604609130 10 ,
-11 -13
0.1111140258, 3.210741142 10 , -3.142106870 10
6 5 4 3 2 9 8 7
1, z , z , z , z , z , z , z , z , z
Why on Earth it returns coefficients in such order?! I would expect it to be either from higher powers to lower powers (like in MATLAB) or from lower powers to higher powers (like in Mathematica), but Maple does something absolutely weird. My program depends on the order of coefficients extracted by coeffs
, so I just can't use it.
Is there a way in Maple to extract coefficients in some sane order?
You should use the CoefficientList
or CoefficientVector
commands for this.
Note the comments about efficiency relative to using coeffs
for this, in that help page.
Those commands also have an option for returning the coefficients in reverse order.
restart:
p := -1.604609130*10^(-11)*z^9 + .1111140258*z^8 + 3.210741142*10^(-11)*z^7
-.3955586214*z^6 - 2.108471910*10^(-11)*z^5 + .6692726719*z^4
+ 5.024523477*10^(-12)*z^3 - .8174429322*z^2 - 3.142106870*10^(-13)*z
+ .9089252367:
V := PolynomialTools:-CoefficientVector( p, z );
[ 0.9089252367]
[ ]
[ -13]
[-3.142106870 10 ]
[ ]
[ -0.8174429322]
[ ]
[ -12]
[ 5.024523477 10 ]
[ ]
[ 0.6692726719]
[ ]
V := [ -11]
[-2.108471910 10 ]
[ ]
[ -0.3955586214]
[ ]
[ -11]
[ 3.210741142 10 ]
[ ]
[ 0.1111140258]
[ ]
[ -11]
[-1.604609130 10 ]
L := PolynomialTools:-CoefficientList( p, z );
[ -13 -12
L := [0.9089252367, -3.142106870 10 , -0.8174429322, 5.024523477 10 ,
-11 -11
0.6692726719, -2.108471910 10 , -0.3955586214, 3.210741142 10 ,
-11]
0.1111140258, -1.604609130 10 ]