MathGroup Archive 2005

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

Search the Archive

Re: Complex Oddity

  • To: mathgroup at smc.vnet.net
  • Subject: [mg57483] Re: [mg57455] Complex Oddity
  • From: Chris Chiasson <chris.chiasson at gmail.com>
  • Date: Sun, 29 May 2005 01:03:44 -0400 (EDT)
  • References: <200505280939.FAA21738@smc.vnet.net>
  • Reply-to: Chris Chiasson <chris.chiasson at gmail.com>
  • Sender: owner-wri-mathgroup at wolfram.com

Is the expression, z, atomic (AtomQ[z])? Otherwise, the replacement
code may not work.

Since you said the expression was complicated, I assume that it is not
atomic. You could
always numerically evaluate z and then use the replacement code.

The other (exact) alternative is Im[z] and Re[z], where you will have
to work with Im[x] and Im[y] because you probably have not told
Mathematica anything about x and y.

If you know that x and y are, for example, real, you can try:

{imagpart,realpart}=Refine[{Re@#,Im@#}&@z,{Element[x,Reals],Element[y,Reals]]

Disclaimer: I didn't test any of the above code.

Regards,

On 5/28/05, John Reed <nospamjreed at alum.mit.edu> wrote:
> I was trying to separate the real and imaginary parts of a complicated
> expression, and ended up with something strange.  Here is a short version of
> what happened.
> 
> Let z = x + I y, then realPart = z /. {Complex[a_,b_]->a} gives realPart =
> x.  Great!
> 
> Now, try imagPart = z /. {Complex[a_,b_]->b}  returns with imagPart = x + y.
> Oops
> 
> In my original expression, it was harder to see, but the same error was
> occuring.  What I tried first was using Re[z] and Im[z], but then I have to
> work with Im[y] and Im[x].  It seems to me two things need to be done here.
> First, be able to assign variables so that they always stay real or else
> indicate an error is occuring if they turn out to be complex, and second do
> something to avoid errors like the above.  I have to say that I don't trust
> Mathematica's answers as much as I did before this came up. Now I feel like
> I better have a good idea of what the answer is before I  trust Mathematica.
> 
> John Reed
> 
> 


-- 
Chris Chiasson
http://chrischiasson.com/
1 (810) 265-3161


  • References:
  • Prev by Date: Re: Complex Oddity
  • Next by Date: Re: Re: Re: Applying a list of functions to a list of arguments
  • Previous by thread: Complex Oddity
  • Next by thread: Re: Complex Oddity