Message Boards Message Boards

0
|
5289 Views
|
2 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Why Arg[z] is not always the same as Im[Log[z]]

Posted 7 years ago

My question regards this calculation. First define:

x := N[9999999966650702/10^16,16]
y := N[-6618533197939224/10^28,16]
z := x + I y

Then, I want to compute the arg of z, and I can do this in three different ways, but the result is not always the same:

Arg[z]

gives -6.61853322001157*10^-13

ArcTan[y / x]

gives also -6.61853322001157*10^-13

Im[Log[z]]

gives -6.619*10^-13

i.e. otherwise the same result but only to four digits of precision.

This puzzles me.

  1. Is the result of the Im[Log[z]] calculation correct (and is the precision also correct)?
  2. Why it is correct, as one would expect that the imaginary part of Log[z] is equal to the arg of z (and to the same precision, one might expect)?

Is it simply because Arg[z] and Im[Log[z]] are implemented with a different algorithm? Are all of the results "correct"? Why?

POSTED BY: Mikko Tommila
2 Replies

It is the same but with a different precision, which is more clear with more digits:

x = N[9999999966650702/10^16, 50];
y = N[-6618533197939224/10^28, 50];
z = x + I y;

Arg[z]
Precision[%]
ArcTan[y/x]
Precision[%]
ArcTan[x, y]
Precision[%]
Im[Log[z]]
Precision[%]

-6.618533220011567667706532393335254203668654848053*10^-13
49.699
-6.618533220011567667706532393335254203668654848053*10^-13
49.699
-6.618533220011567667706532393335254203668654848053*10^-13
49.699
-6.6185332200115676677065323933352542037*10^-13
37.9713

as you can see the 'log'-route costs more precision. Why exactly? it depends on how Log is calculated internally. Log might be optimized for a different range of numbers compared to Arg and ArcTan. Note that the 'angle' is very very close to 0. Such that y/x = ArcTan(y/x) very closely which might aid in finding higher numbers of high precision. A series expansion of Log around {1,0} in complex plane gives a similar answer, but with higher precision:

Series[Log[\[FormalX] + I \[FormalY]], {\[FormalX], 1, 5}, {\[FormalY], 0, 5}] // Normal
Im[% /. {\[FormalX] -> x, \[FormalY] -> y}]

-6.618533220011567667706532393335254203668654848053*10^-13

Always try to use the function that is intended to do the job. If you go a 'long route' it might costs you precision in each step...

Second thought: Log calculates both the Real and Imaginary part:

ReIm[Log[z]]
{-3.33492980556087817880253613684648132101666*10^-9,  -6.6185332200115676677065323933352542037*10^-13}

Could it be that some precision is 'lost' in the real component? I'm not sure if that is possible, but I could imagine that there is a balance in precision for each component somehow...

POSTED BY: Sander Huisman

Note that if z is accurate to 16 figures, Log[z] is accurate to Log[16] approx 3. Try this:

In[1]:= x = N[9999999966650702/10^16, 40];
y = N[-6618533197939224/10^28, 40];
z := x + I y

In[4]:= Arg[z]

Out[4]= -6.61853322001156766770653239333525420367*10^-13

In[5]:= ArcTan[y/x]

Out[5]= -6.61853322001156766770653239333525420367*10^-13

In[6]:= Im[Log[z]]

Out[6]= -6.618533220011567667706532393*10^-13
POSTED BY: S M Blinder
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract