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>
- Reply-to: jmg336 at nyu.edu
- 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[1]:= z = x + I y Out[1]= x+\[ImaginaryI] y In[2]:= FullForm[z] Out[2]= Plus[x,Times[Complex[0,1],y]] You could try In[3]:= imagPart = z/.{a_+I b_\[Rule]b} Out[3]= y In[4]:= realPart=z/.{a_+I b_\[Rule]a} Out[4]= x Best regards, /J.M.