Re: Strange behavior of /cumulative keyword in total() [message #63295 is a reply to message #63285] |
Tue, 04 November 2008 05:38   |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Chris writes:
> Can anybody explain this?
>
> arr = fltarr( 500000) + .1
> cumul = total(array, /cumulative)
>
> print, (cumul - shift(cumul, 1)) [1 : 10]
> print, (cumul - shift(cumul,1)) [499990:499999]
>
>> 0.100000 0.100000 0.100000 0.100000 0.100000 0.100000
> 0.100000 0.100000 0.100000 0.100000
>
>
>> 0.101562 0.101562 0.101562 0.101562 0.101562 0.101562
> 0.101562 0.101562 0.101562 0.101562
>
> Plotting cumul - shift(cumul,1) is even weirder. I can understand the
> net error of cumul growing over time, as floating point precision
> errors accumulate. However, shouldn't the error between any two
> entries in a cumulative sum not accumulate over the array?
Two words: double precision.
IDL> arr = fltarr( 500000) + .1D
IDL> cumul = total(arr, /cumulative, /double)
IDL>
IDL> print, (cumul - shift(cumul, 1)) [1 : 10]
0.10000000 0.10000000 0.10000000 0.10000000
0.10000000 0.10000000 0.10000000 0.10000000
0.10000000 0.10000000
IDL> print, (cumul - shift(cumul,1)) [499990:499999]
0.10000000 0.10000000 0.10000000 0.10000000
0.10000000 0.10000000 0.10000000 0.10000000
0.10000000 0.10000000
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|