MathGroup Archive 1998

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

Search the Archive

Re: `Collect' with complex numbers??



Craig P Earls wrote:
> 
> I couldn't figure out how to do an annoyingly straightforward
> transformation with crtesian complex numbers:
> 
> Collect[(a+b)c +b d,b]
> 
> yields
> 
> a c + b(c+d)
> 
> Which is good, but
> 
> Collect[(a+i)b + c I , I]
> 
> yields
> 
> (a+I)b +c I
> 
> How can I do complex algebra when I can't get this transformation? Using
> ComplexExpand and Re is less than satisfying.
> 
> --
> ----------------------------------------------------------------------
> Craig P Earls, LT U.S. Navy                      cearls@ix.netcom.com
> MIT Naval Construction and Engineering           cpearls@mit.edu
> ----------------------------------------------------------------------

The entity I is a number (it is a symbolic convenience for Complex[0,1])
and Collect cannot use a number for its variable. Roughly, this is
because Complex[a,b] is an atomic entity (for integer/rational/real
a,b), hence will not be split for purposes of collection.

You can work around this with simple replacement rules. I do it inside a
module in order to localize the 

complexCollect[expr_, var_] := Module[
	{myI,e2,v2},
	{e2,v2} = {expr,var} /. Complex[a_,b_]->a+myI*b;
	Collect[e2,v2] /. myI->I
	]

In[18]:= complexCollect[(a+I)b + c I , I] Out[18]= a b + I (b + c)


Daniel Lichtblau
Wolfram Research



  • Prev by Date: Re: Determinant
  • Next by Date: RE: Mathemtica notebooks on web sites
  • Prev by thread: `Collect' with complex numbers??
  • Next by thread: Spherical Harmonics Visualization Study