How far can you trust your computer?

User avatar
AlanMiller
BronzeLounger
Posts: 1545
Joined: 26 Jan 2010, 11:36
Location: Melbourne, Australia

How far can you trust your computer?

Post by AlanMiller »

The equation

y = ex ln(1 + e-x)

is one of those functions which asymptotes towards a fixed value (y=1) as x gets bigger and bigger: y ® 1 as x ® ¥

This computer-generated graph (or any graphing calculator) shows this behaviour as expected for x ranging from 0 to 30.

Now, change the x-range maximum to 37. What's happened? Bonus points if you can identify the unexpected "artefacts".

Mathematicians/ numerical analysts will readily pick up on this ... so maybe put your answers in spoiler tags.

Alan

User avatar
Rudi
gamma jay
Posts: 25455
Joined: 17 Mar 2010, 17:33
Location: Cape Town

Re: How far can you trust your computer?

Post by Rudi »

AlanMiller wrote:Now, change the x-range maximum to 37. What's happened?
Spoiler
My heart took a beat.

Not a math(s) answer, but it's what happened on the graph I saw. :grin:
Regards,
Rudi

If your absence does not affect them, your presence didn't matter.

User avatar
HansV
Administrator
Posts: 78393
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: How far can you trust your computer?

Post by HansV »

Excel shows the same behavior:
S1178.png
Spoiler
Many applications, including Excel, compute floating numbers with a precision of about 15 significant digits.
e-x becomes very small. For example, e-37 ~ 8.5*10-17. That in itself is not a problem.
But that means that 1+e-x is so close to 1 that the difference is beyond the 15th digit.
Effectively, 1+e-x becomes indistinguishable from 1, and its logarithm becomes 0.
And although ex becomes very large, multiplying with 0 still yields 0.
In the range between x=30 and x=37, rounding errors cause the chart to 'wobble'.
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans

User avatar
AlanMiller
BronzeLounger
Posts: 1545
Joined: 26 Jan 2010, 11:36
Location: Melbourne, Australia

Re: How far can you trust your computer?

Post by AlanMiller »

This may provide some insight as to what those "wobbles" actually are, and what their root cause is.

Alan

User avatar
AlanMiller
BronzeLounger
Posts: 1545
Joined: 26 Jan 2010, 11:36
Location: Melbourne, Australia

Re: How far can you trust your computer?

Post by AlanMiller »

I should have really signed this topic off. The key to the behaviour is a limitation of computers called machine epsilon e.
It is essentially the smallest number a computer can store, about 2 x 10-16 as shown on this graph of e-x.

So if you follow the original plot from right to left, the value of the function (as calculated by the computer) is actually
y = ex ln(1 + ne) where n = 0, 1, 2, 3, ....

For n=0 (for x > 36.7 or so) y = 0
For n=1 (the first "step") y = ex ln(1 + e)
For n=2 (second step) y = ex ln(1 + 2e) etc.

The strange curves or "wobbles" are all just exponentials of x multiplied by constants over small ranges of constant ne.

The whole phenomenon can create "all hell done break loose" when it occurs deep internally in iterative models, unbeknownst to the modeller e.g. like in the original "puzzle", where the inputs and outputs are just "ordinary-sized" numbers - neither excessively small or large for the computer capabilities.

Alan