MathGroup Archive 2004

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

Search the Archive

Re: Re: A way around the limitations of Re[] and Im[]


I see no advantage of this definition of ReadPart over a use of the 
built-in ComplexExpand composed with the built-in Re.  That is,

   RealPart[c_] := ComplexExpand[Re[c]]

gives the same results in the 4 examples shown below as does the 
definition of RealPart also shown below.  Are there other situations 
where there would be a significant distinction?

Analogously:

   ImaginaryPart[c_] := ComplexExpand[Im[c]]



Carlos Felippa wrote:
> carlos at colorado.edu (Carlos Felippa) wrote in message news:<cjr8lg$opp$1 at smc.vnet.net>...
> 
>>As you know, Re[expr] and Im[expr] are left unevaluated when expr is
>>not numeric.  I had good luck in simple cases with the following
>>substitution trick:
>>  
>>        Real[c_]:=c/.I->0;     Imag[c_]:=(c-Real[c])/.I->1;
>>
>>Do you see any problem with these definitions?
> 
> 
> Not yet there. Found limitations because n*I is internally stored as
> Complex[0,n].  This  version has done better:
> 
> RealPart[c_]:=ComplexExpand[c]/.{Complex[0,_]->0};
> 
> Examples:
> 
> Print[     RealPart[(a+I*b)^2]    //InputForm];
> Print[     RealPart[(a+I*b)^n]    //InputForm];
> Print[     RealPart[Exp[I*x]/I]   //InputForm];
> Print[     RealPart[Cosh[x+y*I]]  //InputForm];
> 
> Results:
> 
> a^2 - b^2
> Abs[a]^n*Cos[n*Arg[a]]
> Sin[x]
> Cos[y]*Cosh[x]
> 
> 
> 

-- 
Murray Eisenberg                     murray at math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower      phone 413 549-1020 (H)
University of Massachusetts                413 545-2859 (W)
710 North Pleasant Street            fax   413 545-1801
Amherst, MA 01003-9305


  • Prev by Date: Re: keymap and mouse problems with 5.0 frontend under linux
  • Next by Date: Re: Oddities of Plot[]
  • Previous by thread: Re: A way around the limitations of Re[] and Im[]
  • Next by thread: Re: A way around the limitations of Re[] and Im[]