# Grouping by multiple coefficients

Good day! I have an output equation that has a very large amount of coeff. b(x,y), like so:

8*b(0,0) + 2*x*b(0,0) + 3*y*b(0,0) + 5*x*y*b(0,0) + 4*b(0,1) + 3*x*b(0,1) + ...


I need to group by b, so each b(x,y) was seperate. I can Collect[] by b(0,0), but what abut the other coeff.? I'm trying to get something like this:

(8 + 2*x + 3*y + 5*x*y) * b(0,0) + (4 + 3*x + ...


Any ideas about how to do this?

To clarify: each x,y in b(x,y) is written as a Subscript. Not all b(x,y) have a "full" group.The grouping i'm trying to achieve will correspond to a cell in a matrix. The equation is a matrix row, and there are several equations which will form an equation group. I'm new to Wolfram, so any general advice is very welcome.

Thank you all in advance!

• In the future would you please give your input as valid Mathematica code? Commented Jun 3, 2015 at 17:37
• Take a look at CoefficientList[ ] Commented Jun 3, 2015 at 17:46
• What is your purpose in group the terms together? For instance, if you're trying to construct the matrix, there are probably other ways to go. Commented Jun 3, 2015 at 18:33

expr = 8*Subscript[b, 0, 0] + 2*x*Subscript[b, 0, 0] - 3*y*Subscript[b, 0, 0] +

(8 + 2 x - 3 y + 5 x y) Subscript[b, 0, 0] + (-4 + 3 x) Subscript[b, 0, 1]

( _Subscript is the Blank pattern that matches any expression with head Subscript. )