# Strange behavior of Plot over a domain containing very large x-values

When I plot a function of (1 + 1/n)^n,There you can see:

Plot[{(1 + 1/n)^n, E}, {n, 1, 10^13}]


When I add a option of WorkingPrecision,Even the values is just 1,it will be normally:

Plot[{(1 + 1/n)^n, E}, {n, 1, 10^13}, WorkingPrecision -> 1]


But when I change the 10^13 to 10^17,the WorkingPrecision  will not work anymore:

Plot[{(1 + 1/n)^n, E}, {n, 1, 10^17}, WorkingPrecision -> 100]


So what is on with the Plot?Have Anybody had a confusion like this?

• 1. : Welcome to the world of inexact arithmetic. 2. and 3.:Good thing you learned about WorkingPrecision. Now, try looking at PlotRange. Nov 1, 2015 at 2:07
• Ever heard of Overflow?
– paw
Nov 1, 2015 at 2:09
• @J.M. Is about PlotRange this problem?When I add PlotRange -> {0, 3},the question is still.But the maximize is just E.So do you have another prompt?
– yode
Nov 1, 2015 at 2:13
• @paw Maybe a little.If you have very understanding about this,could you post a answer to help who don't know this include me.
– yode
Nov 1, 2015 at 2:17
• @yode The real question is, what the hell are you trying to achieve with those crazy high numbers?!
– paw
Nov 1, 2015 at 2:23

The short answer to your question is that what you are attempting is insane, so it should be no surprise the result is insane.

That said, let us explore the problem in a way that may enlighten you as to what is going on. For this it is useful to look at the numeric behavior of (1 + 1/x)^x for large x.

f[x_] := (1 + 1/x)^x

Table[N[f[x]], {x, 1.*10^Range[6, 13]}]


{2.71828, 2.71828, 2.71828, 2.71828, 2.71828, 2.71828, 2.71852, 2.71611}

Notice, that for the larger exponents, the value is a worse approximation of E than for the smaller ones. Now, Let's look at what happens between 10^12 and 10^13, which is 99+ per cent of what shows up in your first plot.

Table[N[f[x]], {x, 1.*^12, 1.*^13, 1.*^12}]


{2.71852, 2.71852, 2.71792, 2.71852, 2.71913, 2.71973, 2.71671, 2.71852, 2.71611, 2.71611}

This shows the same kind of jitter that your plot shows. Machine arithmetic is just not up to this computation.

Asking for more precision in a naive way doesn't help.

Table[N[f[x], 50], {x, 1.*^12, 1.*^13, 1.*^12}]


{2.71852, 2.71852, 2.71792, 2.71852, 2.71913, 2.71973, 2.71671, 2.71852, 2.71611, 2.71611}

That's because the x values are still in machine precision.

Doing it this way will improve the values.

Table[N[f[x], 25], {x, 1.20*^12, 1.20*^13, 1.20*^12}]


{2.7182818284576860944, 2.7182818284583656649, 2.7182818284585921884, 2.7182818284587054501, 2.7182818284587734072, 2.7182818284588187119, 2.7182818284588510724, 2.7182818284588753427, 2.7182818284588942197, 2.7182818284589093213}

To get an accurate plot, you could make a table this way and plot it using ListLinePlot, but you will just see a flat line, so why bother.

There is an old adage (circa 1950) amongst numerics geeks: garbage in -- garbage out. It applies strongly to your question.

– yode
Nov 1, 2015 at 5:30
• I'd have upvoted even if the post was only your first sentence and last sentence... :) Nov 1, 2015 at 5:44

With an extremely large domain you need to use LogLinearPlot to see the region of interest.

LogLinearPlot[{(1 + 1/n)^n, E}, {n, 1, 10^17}, WorkingPrecision -> 15,
PlotRange -> {2.7, 2.72}]


EDIT: As the domain grows the working precision must grow as well.

Manipulate[
LogLinearPlot[{(1 + 1/n)^n, E}, {n, 1, 10^m},
WorkingPrecision -> m,
PlotRange -> {2.7, 2.72}],
{{m, 5}, 5, 50, 1, Appearance -> "Labeled"},
ControlPlacement -> Bottom]


• Tank you very much to take this question as a question.And the LogLinearPlot` to be solved a part of problem like this.But when I change the 10^17 to 10^35 or more large,the problem will be appearing again.If you can resolve it ,I'll change the acceptance to you.^_^
– yode
Nov 2, 2015 at 15:25