Numerical precision problem
- To: mathgroup at smc.vnet.net
- Subject: [mg43016] Numerical precision problem
- From: "Gareth J. Russell" <gjr2008 at columbia.edu>
- Date: Fri, 8 Aug 2003 00:26:30 -0400 (EDT)
- Organization: Columbia University
- Sender: owner-wri-mathgroup at wolfram.com
Hi All,
I have the following expression (in the form of a function):
f[r_, {t1_, t2_}, {d1_, d2_}] := (2*E^(d1*r) - 2*E^(d2*r) - (d1 -
d2)*E^(r*t2)*r*(2 + r*(d1 + d2 - 2*t2)))/(2*(d1 - d2)*
E^(r*t2)*r^2*(-t1 + t2))
r is a rate parameter, with values 0 to infinity. The expression goes to
0 in the limit as r goes to 0.
The problem is that as r gets smaller (roughly, smaller than about 0.
0001), significant numerical errors appear and then get huge:
In[531]:=
fDOverlap[1/1000000000., {2, 4}, {2, 4}]
Out[531]=
39.8702
The only way to avoid them that I have found is to provide r as an exact
number, and them simplify the result before getting an approximate
result
In[525]:=
fDOverlap[1/1000000000, {2, 4}, {2, 4}]
Simplify[%]
% // N
Out[525]=
(-125000000000000000*(2*E^(1/500000000) - (499999999000000001*E^(1/
250000000))/
250000000000000000))/E^(1/250000000)
Out[526]=
499999999000000001/2 - 250000000000000000/E^(1/500000000)
Out[527]=
0.
But of course, I need to be able to use real vales of r.
Any suggestions for how to deal with the precision issue, other than
arbitrarily setting the value to zero for r less than some constant?
The original expression is as simple as I can make it, but I'm not
convinced some more terms might not cancel, which could help.
Advice appreciated as always!
Gareth
Columbia University
- Follow-Ups:
- Re: Numerical precision problem
- From: Daniel Lichtblau <danl@wolfram.com>
- Re: Numerical precision problem