2
$\begingroup$

My mathematica is doing weird things. Consider the function

f[n_]:=Re[(1/2)*(I*Pi+(-1)^n*n!*Gamma[-n,-n])] 

Let's make a list out of this

points:=Table[{n,f[n]},{n,60,63}] 

when evaluated I get that the list points has these four entries

N@points (* {{60., 0.0539289}, {61., 0.0534851}, {62., 0.00402142}, {63.,0.00395776}} *) 

That is, the first two are above 0.05 and the last two are significantly smaller. Nonetheless, when I perform a ListPlot of points I get a plot where the four dots are way above 0.05. What is going on? Is this a bug?

ListPlot[points, PlotRange -> {0, 0.06}, PlotStyle -> Red] 

enter image description here

$\endgroup$
8
  • $\begingroup$ Your Table is missing an iterator (n) and Gamma[-60,-60] doesn't evaluate for me. Did you transcribe your code correctly? $\endgroup$ Commented Apr 20, 2017 at 13:52
  • $\begingroup$ edited and Gamma[-60,-60] evaluates without any problems to me $\endgroup$ Commented Apr 20, 2017 at 14:04
  • $\begingroup$ In order to see the decimal output you show, you had to use N, otherwise you would see something with very large integers multiplied by Gama[-60,-60], so I added that line to the post. So if you use ListPlot[N@points] then you see what you expect $\endgroup$ Commented Apr 20, 2017 at 14:04
  • 1
    $\begingroup$ @JasonB. ok. But why does not my code work? It should work shouldnt it? $\endgroup$ Commented Apr 20, 2017 at 14:06
  • $\begingroup$ @AnarchistBirdsWorshipFungus - you are multiplying very huge numbers (10^83) by very small numbers (10^-82), so you have to give some consideration to precision. I think that ListPlot is being smarter than N in this case, check the output from this: Block[{$MaxExtraPrecision = 100}, N[points, {∞, 5}] ] $\endgroup$ Commented Apr 20, 2017 at 14:09

1 Answer 1

4
$\begingroup$

N @ points is using machine arithmetic and giving you bad values at 62 and 63. Changing over to Mathematica's arbitrary precision arithmetic, even at the fairly low precision of 20 digits,

N[points, 20] 

gives

{{60.000000000000000000, 0.053928873945168632029}, {61.000000000000000000, 0.053485094513170474678}, {62.000000000000000000, 0.053052093270633190146}, {63.000000000000000000, 0.052629440880266559186}} 

showing that your list plot is correct.

$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.