comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Inaccuracies
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Inaccuracies [message #5292 is a reply to message #5290] Thu, 16 November 1995 00:00 Go to previous messageGo to previous message
Hermann Mannstein is currently offline  Hermann Mannstein
Messages: 22
Registered: September 1995
Junior Member
Andy Loughe <afl@cdc.noaa.gov> wrote:
> 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

It get clearer when you type:


IDL> a=indgen(15) - 7
IDL> print,double(a*.2)
-1.4000000 -1.2000000 -1.0000000 -0.80000001
-0.60000002 -0.40000001 -0.20000000 0.0000000
0.20000000 0.40000001 0.60000002 0.80000001
1.0000000 1.2000000 1.4000000
IDL>
but you get:

IDL> print,total(double(a*.2))
0.0000000
and
IDL> print,total(a*.2D)
-2.2204460e-16


by the way,
IDL> a=indgen(13) - 6
IDL> print,double(a*.2)
-1.2000000 -1.0000000 -0.80000001 -0.60000002
-0.40000001 -0.20000000 0.0000000 0.20000000
0.40000001 0.60000002 0.80000001 1.0000000
1.2000000
IDL>

it's the multiplication, and the 'total' works with 13 elements, because the
deviations cancel each other
--
Regards,

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~
Hermann Mannstein Tel.: +49 8153 28-2503
Institut fuer Physik der Atmosphaere or -2558
DLR - Oberpfaffenhofen Fax.: +49 8153 28-1841
Postfach 1116 \ mailto:H.Mannstein@dlr.de
D-82230 Wessling \ 0 http://www.op.dlr.de/~pa64
Germany ________\/|________
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`--------\--------'~ ~~~~~~~~~~~~~~~~~~~~
\
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: How can I add parameter to curvefit?
Next Topic: XLoadCT in a procedure ?????

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 19:34:31 PDT 2025

Total time taken to generate the page: 0.00457 seconds