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?
numerical error analysis
in 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? $\endgroup$1.0000+1.0000e-100 = 1.0000
since the1.0000e-100
is rounded away. Then subtracting1.0000
again gives0.0000
and multiplying with1.0000e100
won't change that. $\endgroup$