Inaccuracies [message #5313] |
Mon, 13 November 1995 00:00  |
Andy Loughe
Messages: 174 Registered: November 1995
|
Senior Member |
|
|
Ok, I am sure this has been discussed before, but let
me start this thread again. I wish to create a 15-element
vector which contains the numbers -1.4 to 1.4 by an increment
of 0.2 I also wish the sum of these elements to be zero
(No, this isn't the new math). Here is what I tried...
TRIAL #1
========
IDL> a = findgen(15)*.2 - 1.4
IDL> print, total(a)
7.15256e-07
Hmmm! Not so good.
TRIAL #2
========
IDL> a = dindgen(15)*(.2D)-1.4D
IDL> print, total(a, /double)
4.4408921e-15
Ok, this is better but not correct.
And what are the values of a?
IDL> print, a
-1.4000000 -1.2000000 -1.0000000 -0.80000000
-0.60000000 -0.40000000 -0.20000000 2.2204460e-16
0.20000000 0.40000000 0.60000000 0.80000000
1.0000000 1.2000000 1.4000000
I seem to have lost a zero somewhere, and for me this matters!!!
TRIAL #3
========
What if I only needed 13 numbers between -1.2 and 1.2.
IDL> a = findgen(13)*.2 - 1.2
IDL> print, total(a)
0.00000
Now how can I get this to work for 15 numbers?
Maybe I am missing something here, but this kind of behavior
makes IDL a bit problematical for scientific use. With only 15
numbers and double precision arithmetic, I can't believe this
would fail in FORTRAN or C!
--
Andrew F. Loughe (afl@cdc.noaa.gov)
University of Colorado, CIRES * Campus Box 449 * Boulder, CO 80309
phone: (303) 492-0707 fax: (303) 497-7013
|
|
|