2
$\begingroup$

It is known that there are the following functions:

f[x_] := x - 1/2 + 1/Pi Sum[Sin[2 Pi k x]/k, {k, 1, Infinity}]

Tests on some of the values taken.

f[0] // Chop
f[0.5] // Chop
f[1] // Chop
f[1.5] // Chop
f[2] // Chop

-(1/2), 0, 1/2, 1., 3/2

But with Table, the result will be different.

Table[f[x], {x, 0, 2, 0.5}] // Chop

{-0.5, 0, 0, 1., 1.}

It is clear that the values of the function at $x=1$ and $x=2$ cannot correspond, why is that?

$\endgroup$
3
  • 2
    $\begingroup$ It comes from this Sum[Sin[2 Pi k x]/k, {k, 1, Infinity}], here is screen shot to illustrate !Mathematica graphics Seems to have caused some issue here. Need more investigation to find exactly why. But as a general rule, Try to avoid non exact numbers when doing exact calculations. $\endgroup$
    – Nasser
    Aug 31, 2023 at 13:25
  • $\begingroup$ The results in the picture shocked me, first time I've had this problem @Nasser. $\endgroup$
    – Vancheers
    Aug 31, 2023 at 13:30
  • $\begingroup$ Yes, seems to be some numerical issue in the sum you have. Could be a bug. But need more looking into it to know exactly why it happened. (but as I said, to be safe, avoid non-exact numbers in exact calculations). $\endgroup$
    – Nasser
    Aug 31, 2023 at 13:32

1 Answer 1

8
$\begingroup$

Your function is discontinuous on the integers, and so it matters exactly where you are evaluating it. Numerical is not equal to analytical evaluation for discontinuous functions.

f[x_] = x - 1/2 + 1/π Sum[Sin[2 π k x]/k, {k, 1, ∞}]
(*    -1/2 + x + (I (Log[1 - E^(2 I π x)] - Log[E^(-2 I π x) (-1 + E^(2 I π x))]))/(2 π)    *)

Plot[f[x], {x, 0, 10}]

enter image description here

Show the discontinuity at $x=2$ for example:

Limit[f[x], x -> 2, Direction -> "FromBelow"]
(*    1    *)

Limit[f[x], x -> 2, Direction -> "FromAbove"]
(*    2    *)

So, numerically, you may get 1, 2, or their average 1.5 depending on details.

$\endgroup$

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.