For ex:
In[2]:= ToExp[z_] := Abs[z] E^(I Arg[z])
In[4]:= ToExp[3 + 4 I]
Out[4]= 5 E^(I ArcTan[4/3])
However, this converts back to rectangular form when a float is involved:
In[5]:= ToExp[3 + 4. I]
Out[5]= 3.+ 4. I
Any idea how to make a consistent exponential complex number output?
Thanks.
--
_____________________
Mr.CRC
crobc...@REMOVETHISsbcglobal.net
SuSE 10.3 Linux 2.6.22.17
>For ex:
>In[2]:= ToExp[z_] := Abs[z] E^(I Arg[z])
>In[4]:= ToExp[3 + 4 I]
>Out[4]= 5 E^(I ArcTan[4/3])
>However, this converts back to rectangular form when a float is
>involved:
>In[5]:= ToExp[3 + 4. I]
>Out[5]= 3.+ 4. I
>Any idea how to make a consistent exponential complex number output?
Use Rationalize to convert the machine precision values to exact
values, i.e.,
In[5]:= toExp[z_] := Module[{x = Rationalize[z]},
Abs[x] E^(I Arg[x])]
In[6]:= toExp[3. + 4. I]
Out[6]= 5*E^(I*ArcTan[4/3])
If you only need to do it occasionally, then you could just define a function like
ComplexToPolar[z_] /; Element[z, Complexes] :=
Interpretation[
Grid[{{Abs[z], Superscript[E, Row[{I, Arg[z]}]]}}, Spacings -> .2],
z]
If always want objects with Head Complex, then something like
Unprotect[Complex];
Complex /: MakeBoxes[Complex[a_, b_], StandardForm] :=
With[{abs = Abs[Complex[a, b]], arg = Arg[Complex[a, b]]},
RowBox[{MakeBoxes[abs, StandardForm],
SuperscriptBox["\[ExponentialE]",
RowBox[{"\[ImaginaryI]", MakeBoxes[arg, StandardForm]}]]}]]
Protect[Complex];
For complex numbers such as 3 + 4 Pi I, the first option works, but the second doesn't. This is clear from the FullForm.
Thanks for the response.
I think the first option works.