       Re: Complex Oddity

• To: mathgroup at smc.vnet.net
• Subject: [mg57491] Re: Complex Oddity
• From: Jean-Marc Gulliet <jeanmarc.gulliet at 9online.fr>
• Date: Sun, 29 May 2005 21:00:08 -0400 (EDT)
• Organization: New York University
• References: <d79enu\$lbl\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```John Reed 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
>

Hi John,

the expression z = a + I y may not be translated internally as you expect:

In:= z = x + I y

Out= x+\[ImaginaryI] y

In:= FullForm[z]

Out= Plus[x,Times[Complex[0,1],y]]

You could try

In:= imagPart = z/.{a_+I b_\[Rule]b}

Out= y

In:= realPart=z/.{a_+I b_\[Rule]a}

Out= x

Best regards,
/J.M.

```

• Prev by Date: Related quastions. Question 2
• Next by Date: Creating hyperlinks from text?
• Previous by thread: Re: Complex Oddity
• Next by thread: Re: Complex Oddity