0
$\begingroup$

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!

$\endgroup$
3
  • 1
    $\begingroup$ In the future would you please give your input as valid Mathematica code? $\endgroup$
    – Mr.Wizard
    Jun 3, 2015 at 17:37
  • $\begingroup$ Take a look at CoefficientList[ ] $\endgroup$ Jun 3, 2015 at 17:46
  • $\begingroup$ 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. $\endgroup$
    – Michael E2
    Jun 3, 2015 at 18:33

1 Answer 1

4
$\begingroup$

Like this?

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

Collect[expr, _Subscript]
(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. )

$\endgroup$

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.