My list of variables is

var = {a1 Y1,a2 Y2,a1 Y1 Ym1,a2 Y2 Ym1,a1 Y1 Ym2,a2 Y2 Ym2}

and the polynomial is

poly = -2 a1 m^2 Y1-2 a1 Y1 Ym1-2 a2 m^2 Y2+a2 p^2 Y2-a2 Y2 Ym1-a2 Y2 Ym2+d

However when I write

CoefficientList[poly, vars]

the output that I get is

(((-2 a1 Y1 m^2-2 a2 Y2 m^2+d+a2 p^2 Y2-2 a1 Y1 Ym1-a2 Y2 Ym1-a2 Y2 Ym2)))

why is this so ? On the other hand:

Coefficient[poly, {a1 Y1}]

gives the output

{-2 m^2-2 Ym1}
  • 3
    $\begingroup$ for CoefficientList your "variables" can not be products of symbols. If you compare the docs for Coefficient and CoefficientList the difference in the second argument ( form vs var ) should be apparent. $\endgroup$ – george2079 Mar 16 '17 at 18:23

this may do what you want: (Notice I reordered the var list with the three-factor terms first )

var = {a1 Y1 Ym1, a2 Y2 Ym1, a1 Y1 Ym2, a2 Y2 Ym2, a1 Y1, a2 Y2};
poly = -2 a1 m^2 Y1 - 2 a1 Y1 Ym1 - 2 a2 m^2 Y2 + a2 p^2 Y2 - 
   a2 Y2 Ym1 - a2 Y2 Ym2 + d;
{rem, coef} = 
     Simplify[#1 - #2 Sow@Coefficient[#1, #2 ]] & ,
      poly , var] // Reap

{d, {{-2, -1, 0, -1, -2 m^2, -2 m^2 + p^2}}}

Total@Join[{rem}, First@coef var ] == poly  // Simplify


| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.