Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2004
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2004

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

Search the Archive

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

  • To: mathgroup at smc.vnet.net
  • Subject: [mg51118] Re: A way around the limitations of Re[] and Im[]
  • From: carlos at colorado.edu (Carlos Felippa)
  • Date: Tue, 5 Oct 2004 04:37:04 -0400 (EDT)
  • References: <cjr8lg$opp$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

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]


  • Prev by Date: Re: Limit problem
  • Next by Date: Re: Print with limited precision
  • Previous by thread: Re: A way around the limitations of Re[] and Im[]
  • Next by thread: Re: Re: A way around the limitations of Re[] and Im[]