# What makes imaginary parts show up?

If I define a function using

alpha[y_, d_] := 2 ArcCos[1 - (2 y)/d]


Then if $y$ and $d$ are equal, the result is $2\pi$ :

alpha[x, x]


and

alpha[4, 4]


are both evaluated as

$2 \pi$

But when I use this in a table with:

Table[alpha[y1, d1], {d1, 0.1, 5, 0.1}, {y1, 0, d1, 0.1}]

Some imaginary parts (although very small) for example $6.28319 - 5.96046*10^-8 i$ appear. Am I doing something wrong? It seems like something basic that I am doing wrong because of not understanding a concept in MMA.

• Prolly just your machine's floating point arithmetic. On my box, I'm not getting tiny imaginary parts at all (10.4 on Xubuntu Trusty). Note that the evaluation of arccosine is ill-conditioned near $\pm 1$, so tiny perturbations in the argument can cause not very small perturbations in the output. Apr 12, 2016 at 17:06
• Basically since your numbers in Table are approximate your problem appears to be trivial. Nevertheless if there is a certain problem at all, it was raised in his question How to eliminate the zero real part of a purely imaginary number?. The issue is version dependent. Apr 12, 2016 at 17:09
• @J.M. I'm using 10.3 on Windows 8. Good point about the ill-conditioned behavior. Apr 12, 2016 at 17:13
• It's not Table[] that's doing the approximation; it's your use of 0.1in the iterator. Try replacing all those with 1/10, and apply N[] afterwards. Apr 12, 2016 at 17:19
• In general, inexact numbers "contaminate" every calculation in which they are introduced; the result's precision will be the same as that of the least precise number. In your case, the machine precision 0.1 resulted in everything being done in machine precision. Apr 12, 2016 at 18:05

Many thanks to @J.M. and @Artes I found out that the iterator 0.1 in the Table function was making this artifact, which is also version dependent.
 Table[N[alpha[y1, d1]], {d1, 1/10, 5, 1/10}, {y1, 0, d1, 1/10}]

• Specifying the precision of your iterator should also prevent the imaginary part from showing up: Table[alpha[y1, d1], {d1, 0.16, 5, 0.16}, {y1, 0, d1, 0.16}]` Apr 13, 2016 at 5:16