# Write complex number in terms of absolute value and phase

I have a long vector and some of the values (19 out of 64) are complex. I got them using the Mathematica Rationalize function, so the complex ones are written in the a+bi form. Is there a function I can apply to the entire vector, that would change my complex numbers to the form AExp[Iphi]?

• AbsArg will give the absolute value and argument. The trouble with making a function like argForm[n_] := (#1 E^(I #2)) & @@ AbsArg@n is that, for floating point numbers, a E^(I b) is automatically converted back to the original form – Jason B. Apr 8 '16 at 13:13
• This and this are related. – J. M. will be back soon Apr 8 '16 at 13:57

Try this:

{1, 1 + 2 I, 3 - 5 I, 7, 9 + I} /.x_ /; Head[x] == Complex ->
Sqrt[Re[x]^2 + Im[x]^2]*Exp[ArcTan[Re[x], Im[x]]]


yielding

(*   {1, Sqrt[5] E^ArcTan[2], Sqrt[34] E^-ArcTan[5/3], 7,
Sqrt[82] E^ArcTan[1/9]}   *)


Edit: to address your question If you want to have the argument shown as fractions of Pi sa for the angles of 45 grad or 60 grad, this is achieved automatically. If you need to express each argument as the fraction of Pi, you might try this:

{1, 1 + 2 I, 3 - 5 I, 7, 9 + I, 1 + I, 3 + I} /.
x_ /; Head[x] == Complex ->Sqrt[Re[x]^2 + Im[x]^2]*
Exp[NumberForm[Rationalize[N[ArcTan[Re[x], Im[x]]/\[Pi]]], {3, 2}]*I*\[Pi]]


But this will not be the form which you can further operate with, just because of the NumberForm function and also the negative arguments look ugly.

The way to transform it depends upon the answer to the question, what do you want it for in such a form?

Have fun!

• Not bad, but is there a way to approximate the phases so you don't get Pi + or - some ArcTan of something ugly? – PhysNerd90 Apr 8 '16 at 13:18
• Did you want to have an I after Exp[? – Jason B. Apr 8 '16 at 13:37

The trouble with many methods is that they only work on integer inputs. Trying Alexei's answer with approximate numbers

{1.0, 1.0 + 2 I, 3.0 - 5 I, 7, 9.0 + I} /.
x_ /; Head[x] == Complex ->
Sqrt[Re[x]^2 + Im[x]^2]*Exp[I ArcTan[Re[x], Im[x]]]
(* {1., 1. + 2. I, 3. - 5. I, 7, 9. + 1. I} *)


just spits back out the original answer. Also, a simpler way to do this would be

argForm[n_] := (#1 E^(I #2)) & @@ AbsArg@n


But again, if the numbers are decimals this won't work because Mathematica automatically parses numbers like these to have into the original form,

1. Exp[2. I]//FullForm
(* Complex[-0.4161468365471424,0.9092974268256817] *)


If you want the numbers to be in exponential form for display purposes, then this is the way to go,

argForm[n_] := (Row@{Abs[n],
Superscript["\[ExponentialE]",
"\[ImaginaryI]" <> ToString[Arg[n]]]})


This will work for exact and approximate numbers,

argForm[1 + 2. I]
argForm[1 + 2 I]


Since the arguments are rational:

v = {1/10, -1 - 2 I, 3 - 5/3 I, 7, 9/10 + I};
Abs[v] Exp[I Arg[v]]

{1/10, Sqrt[5] E^(I (-π + ArcTan[2])), 1/3 Sqrt[106] E^(-I ArcTan[5/9]), 7,
1/10 Sqrt[181] E^(I ArcTan[10/9])}

• I tried something similar: Abs[numericGamma2[[4]]]*Exp[I*Arg[numericGamma2[[4]]]], the problem is the result looks ugly Exp[I *( -pi + ArcTan(93/80))]. Is there a way to approximate this? – PhysNerd90 Apr 8 '16 at 13:15
• You get a simpler form using rectangular coordinates. – bill s Apr 8 '16 at 13:22
• Yep, I think I'll stick with that. Thanks. – PhysNerd90 Apr 8 '16 at 13:25