Re: complex numbers
- To: mathgroup at smc.vnet.net
- Subject: [mg105909] Re: [mg105904] complex numbers
- From: Bob Hanlon <hanlonr at cox.net>
- Date: Thu, 24 Dec 2009 20:59:10 -0500 (EST)
- Reply-to: hanlonr at cox.net
Presumably, because Abs[x + I*y] // LeafCount 8 Sqrt[x^2 + y^2] // LeafCount 11 Bob Hanlon ---- Jon Joseph <josco.jon at gmail.com> wrote: ============= Thanks Bob. One question on you solutions: Since you declare both x and y to be real in the following Assuming[{Element[{x, y}, Reals]}, #[{Re[z], Im[z], Abs[z]}] & /@ {Simplify, FullSimplify}] Why doesn't Abs[z] expand to Sqrt[x^2+y^2] the same way it does in ComplexExpand? Jon On Dec 24, 2009, at 7:24 AM, Bob Hanlon wrote: > > Clear[x, y, z]; > z = x + I*y; > > {Re[z], Im[z], Abs[z]} > > {Re[x] - Im[y], Im[x] + Re[y], Abs[x + I*y]} > > Use assumptions to target specific variables as Real > > Assuming[{Element[{x, y}, Reals]}, > #[{Re[z], Im[z], Abs[z]}] & /@ {Simplify, FullSimplify}] > > {{x, y, Abs[x + I*y]}, {x, y, Abs[x + I*y]}} > > Assuming[{Element[{x, y}, Reals]}, > #[{Re[z], Im[z], Abs[z]}] & /@ {Simplify, FullSimplify}] > > {{x, y, Abs[x + I*y]}, {x, y, Abs[x + I*y]}} > > If appropriate (i.e., all variables are Real), use ComplexExpand > > {Re[z], Im[z], Abs[z]} // ComplexExpand > > {x, y, Sqrt[x^2 + y^2]} > > Use TagSet for x and y > > x /: Im[x] = 0; > x /: Re[x] = x; > y /: Im[y] = 0; > y /: Re[y] = y; > > {Re[z], Im[z], Abs[z]} > > {x, y, Abs[x + I*y]} > > > Bob Hanlon > > ---- Jon Joseph <josco.jon at gmail.com> wrote: > > ============= > All: Something fundamental about complex number initialization I am > failing to understand. I wish to define a complex number > > z=x+ I y where x and y are both reals. Can someone tell me the > proper way to tell Mathematica that x, y are real so that Re[z] returns > x and Im[z] returns y? Much appreciated, Jon. >