MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Common factors in a list

  • To: mathgroup at smc.vnet.net
  • Subject: [mg58373] Re: Common factors in a list
  • From: Peter Pein <petsie at dordos.net>
  • Date: Tue, 28 Jun 2005 21:57:05 -0400 (EDT)
  • References: <d9r50q$568$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

John Reed schrieb:
> I'm working with a list (vector) that's composed of functions such as 
> complex exponentials and Bessel functions.  Some of the functions are common 
> to each element of the list.  I'm trying to find a way to do the following:
> 
>    {a x, a y, a z}-> a *{x, y, z}
> 
> In this expression, a, x, y, z are polynomials, exponentials and/or Bessel 
> functions.
> 
> So far I haven't had any luck with this.  Does anyone have a simple 
> solution?
> 
> John Reed 
> 

Because of Mathematica's built-in "simplification" of
In[1]:= a*{x, y, z}
to
Out[1]={a*x, a*y, a*z},
I'll use \[CircleDot] as replacement for the multiplication character:
In[2]:= a \[CircleDot] {x, y, z}
Out[2]= a \[CircleDot] {x, y, z}

In[3]:=
vecFactor[vec_List] :=
  Module[{ql, fl = FactorList[Plus @@ vec], mp, f2},
   ql = FoldList[Cancel[#1/Power @@ #2]& , vec, fl];
   f2 = ql[[ mp = Position[#1, Min[#1]]&[LeafCount /@ ql][[1, 1]]]];
   ql = Times @@ Power @@@ Take[fl, {1, mp - 1}];
   ql \[CircleDot] f2
  ]
In[4]:=
vecFactor[
 {6*BesselJ[0, x]* xp[-x]*(x^2 - 1), 4*(x - 1)*Exp[-x]*BesselJ[1, x],
  2*(1 - x)^2*BesselJ[2, x]*Exp[-x]}
]
Out[4]=
((2*(-1 + x))/E^x) \[CircleDot]
  {3*(1 + x)*BesselJ[0, x], 2*BesselJ[1, x], (-1 + x)*BesselJ[2, x]}

Later you can use expr/.\[CircleDot]->Times to get back your product.
Maybe someone else has a better trick to avoid the distribution of the
common factor...

-- 
Peter Pein
Berlin


  • Prev by Date: New Visualization - Earthquake data
  • Next by Date: (presumably) easy AspectRatio question
  • Previous by thread: Re: Common factors in a list
  • Next by thread: exact integer from Log[ ]