Group Abstract Group Abstract

Message Boards Message Boards

0
|
4.3K Views
|
4 Replies
|
1 Total Like
View groups...
Share
Share this post:

Collect[ ] function for vectors {a x, c x} --> x {a, c} ?

Posted 10 years ago
POSTED BY: Matt Po
4 Replies

One of the problems is that x{1,3} automatically gets expanded back into {x,3x}. You can of course 'freeze' this behavior using Hold, or other means:

Something like this could work (no guarantees):

expr = {a x + b x^2, c x + d x + 3 x^2};
expr = Factor /@ expr;
divisors = 
  If[MatchQ[#, Times[___]], Cases[#, Times[x__] :> x], {1}] & /@ 
   expr;
common = Times @@ Intersection @@ divisors;
expr /= common;
expr = Inactivate[common expr]
expr // Activate

giving:

x * {a + b x, c + d + 3 x}
{x (a + b x), x (c + d + 3 x)}
POSTED BY: Sander Huisman
Posted 10 years ago
POSTED BY: Matt Po

The problem is that you have version 9 which does not have Activate and Inactive. If you leave out In[7] and In[8]. You will have prefactor and the vector in the variables common and expr, respectively.

POSTED BY: Sander Huisman
Posted 10 years ago
POSTED BY: Matt Po
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard