5
$\begingroup$

Why the first one works fine but not the second one? How can I make it work?

  1. Abs[#] Exp[I Arg[#]] &@(1 + I)
  2. Abs[#] Exp[I Arg[#]] &@(1.1 + I)
$\endgroup$

1 Answer 1

9
$\begingroup$

You can see why when you break it up. Since you use 1.1 then Mathematica evaluated it numerically.

Compare

v = 1 + I
a = Abs[v] 
b = Exp[I Arg[v]]
a*b

Mathematica graphics

With

v = 1.10 + I
a = Abs[v] 
b = Exp[I Arg[v]]
a*b

Mathematica graphics

You see that Exp[I Arg[v]] now is 0.73994 + 0.672673 I

To keep things nice, as your first example, use exact number

v = 11/10 + I
a = Abs[v] 
b = Exp[I Arg[v]]
a*b

And now it gives

Mathematica graphics

You see it kept Exp[I Arg[v]] as E^(I ArcTan[10/11]) and not 0.73994 + 0.672673 I as before, since the number is now exact.

I tend to avoid inexact numbers, unless I am doing numerical computation and using functions such as NDSolve and NIntegrate and such, then it is OK.

You can always at the very end of the calculation, convert things to numerical values using N function. This gives more accurate results also.

$\endgroup$
4
  • $\begingroup$ I would request you to modify the title of this post as you see fit. $\endgroup$
    – Syed
    Oct 9, 2021 at 6:54
  • $\begingroup$ @Syed I assume you meant to ask the OP about this and not me? As I am not the one who asked the question ;) $\endgroup$
    – Nasser
    Oct 9, 2021 at 6:59
  • $\begingroup$ No, I think that since you have answered the post convincingly, it is only appropriate that you edit the title to make it useful for future web searches. Thanks. $\endgroup$
    – Syed
    Oct 9, 2021 at 7:01
  • $\begingroup$ @Syed sorry, I do not feel comfortable changing titles of questions of others. But feel free to ask the OP or the site moderator to do this if you want. If you have enough rep, you can also do that yourself if you wish. $\endgroup$
    – Nasser
    Oct 9, 2021 at 7:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.