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

Hi,

I want to rearrange a term so that I can bring out a symbol (that exists in each component of the vector) out of a vector.

In a scalar term (tensor order #0), I get it successfully by the "Collect" function:

input: Collect[a x + c x, x]
output: (a + c) x

so, I am happy with this.

But when I tried this function at a vector (tensor order #1), it does not work the way I want:

input: Collect[{a x, c x}, x]
output: {a x, c x}

But the output, I want to have, shoud be: x {a, c}

Please can you help me? Maybe I forgot some parameters in the "Collect" function or I need a completely different function for my problem. I do not know.

Thanks. Matthias

Wolfram Mathematica Student Edition Version 9.0.1.0 Windows 8.1, 64 bit

POSTED BY: Matt Po
4 Replies
Posted 10 years ago
POSTED BY: Matt Po
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

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
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard