5
$\begingroup$

I'm not experienced in Wolfram Language, so couldn't you please help me with its syntax? Given the polynomial expression:

poly = 59049 Subscript[B, 1] Subscript[Abx, 1, 1] + 
  32805 Subscript[B, 1] Subscript[Abx, 1, 2] + 
  7290 Subscript[B, 1] Subscript[Abx, 1, 3] + 
  810 Subscript[B, 1] Subscript[Abx, 1, 4] + 
  45 Subscript[B, 1] Subscript[Abx, 1, 5] + 
  Subscript[B, 1] Subscript[Abx, 1, 6] - 
  59049 Subscript[B, 1] Subscript[Abx, 2, 1] - 
  32805 Subscript[B, 1] Subscript[Abx, 2, 2] - 
  7290 Subscript[B, 1] Subscript[Abx, 2, 3] - 
  810 Subscript[B, 1] Subscript[Abx, 2, 4] - 
  45 Subscript[B, 1] Subscript[Abx, 2, 5] - 
  Subscript[B, 1] Subscript[Abx, 2, 6] - 59049 Subscript[Aby, 1, 1] - 
  32805 Subscript[Aby, 1, 2] - 7290 Subscript[Aby, 1, 3] - 
  810 Subscript[Aby, 1, 4] - 45 Subscript[Aby, 1, 5] - 
  Subscript[Aby, 1, 6] + 59049 Subscript[Aby, 2, 1] + 
  32805 Subscript[Aby, 2, 2] + 7290 Subscript[Aby, 2, 3] + 
  810 Subscript[Aby, 2, 4] + 45 Subscript[Aby, 2, 5] + 
  Subscript[Aby, 2, 6]

and the list:

subs = {Subscript[Abx, 2, 4], Subscript[Abx, 2, 5], 
  Subscript[Abx, 2, 6], Subscript[Aby, 2, 1], Subscript[Aby, 2, 2], 
  Subscript[Aby, 2, 3], Subscript[Aby, 2, 4], Subscript[Aby, 2, 5], 
  Subscript[Aby, 2, 6]}

I need to collect the coefficients of monomials of the polynomial, that contain the variables from the list. So the answer should be:

{-810 Subscript[B, 1], -45 Subscript[B, 1], -Subscript[B, 
  1], 59049, 32805, 7290, 810, 45, 1}

I know how to do this using a lot of "For" and "If" constructions, but I know that it is not advisable because Wolfram Language has very powerful, beautiful and fast-acting built-in functions. Can you please help me and write, how to solve my problem with the most efficient way? Thank you!

$\endgroup$

2 Answers 2

5
$\begingroup$
Last@CoefficientList[poly, #] & /@ subs
{-810 Subscript[B, 1], -45 Subscript[B, 1], -Subscript[B, 
  1], 59049, 32805, 7290, 810, 45, 1}
$\endgroup$
1
5
$\begingroup$
Normal @ Last @ CoefficientArrays[poly, subs]

enter image description here

$\endgroup$
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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