Possible Duplicate:
Funny behaviour when plotting a polynomial of high degree and large coefficients
1/x^2 + (3 + x)/(6 (1 - Exp[x] + x))
——This is a expression that seems nothing special, so does its limit when x->0:
Limit[1/x^2 + (3 + x)/(6 (1 - Exp[x] + x)), x -> 0]
(* => 1/12 *)
But it becomes strange when trying to calculate a x near zero,
1/x^2 + (3 + x)/(6 (1 - Exp[x] + x)) /. x -> 0.00001
(* => -19403.7 *)
1/0.00001^2 + (3 + 0.00001)/(6 (1 - Exp[0.00001] + 0.00001))
(* => -19403.7 *)
Limit[1/x^2 + (3 + x)/(6 (1 - Exp[x] + x)), x -> 0.00001]
(* => 0. *)
Many people (including me) may check the curve of the expression as the first reaction for these results:
Plot[1/x^2 + (3 + x)/(6 (1 - Exp[x] + x)), {x, 0, 0.00001}]
And see:

Aha, it explains the matter! The curve is actually oscillating near zero!… but wait, try this:
Plot[1/x^2 + (3 + x)/(6 (1 - Exp[x] + x)), {x, 0, 0.001}, WorkingPrecision -> 30]
Now we see:

So all of these turn out to be a story about precision once again (why I always encounter this! ). I also found some resource for this error:
Series[1/x^2 + (3 + x)/(6 (1 - Exp[x] + x)), {x, 0, 10}];
Normal[%] /. x -> 0.00001
(* => 0.0833332 *)
N[1/x^2 + (3 + x)/(6 (1 - Exp[x] + x)) /. x -> 10^-5, 6]
(* => 0.0833332 *)
But, can this problem be solved only with ReplaceAll and Limit? Also, we see that Mma doesn't give warnings for these great error (while this sort of thing frequently occurs when I use NDSolve though the error seems not that big…it's another story), any way to make Mma give a warning message or something?


2 - 2*E^x + 2 x + x^2which is part of your expression when you simplify it. Note to which degree the numerical values of the 4 parts in the sum differ. Didn't you have numerical error analysis in university? – halirutan Sep 19 '12 at 11:55numerical error analysisin my university…at least it's not a required course for my major and in my memory I never see this in the list of elective course, too… our lessons always talk about those analytical solutions and say little about numeric solutions, usually the books just say "the numeric solution should be done with computer". So, can you explain the details? – xzczd Sep 19 '12 at 12:21x = 10^-7``15;{Precision[x], Precision[2 - 2*E^x + 2 x + x^2]}. This should give you a start. And as @J.M. ensured me, there was already a Q&A about the different forms of numbers and precision tracking. – halirutan Sep 19 '12 at 12:231.0000+1.0000e-100 = 1.0000since the1.0000e-100is rounded away. Then subtracting1.0000again gives0.0000and multiplying with1.0000e100won't change that. – celtschk Sep 19 '12 at 15:091.00+0.00100is calculated to 3 digits, then the answer is1.00, right? If so, OK…I know this, though my lesson say little about numeric error analysis it's still involved in the little, but I don't expect it also exists in mathematica 囧. – xzczd Sep 20 '12 at 05:41Numericizewhich takes an expression, and returns another expression which calculates the original expression in a numerically accurate way for numeric values for all variables, but isn't necessarily exact for exact values). BTW, the "M." for Mathematica was due to comment length; I didn't want to add a second comment for just a few characters, so I decided to shorten what I can. I didn't expect the meaning to be that hard to derive. Obviously my expectation was wrong. – celtschk Sep 20 '12 at 09:25