[Thread Prev][Thread Next][Index]

[ferret_users] How to do @rsum and @iin in reverse?



This may be a really stupid question. How does one perform @rsum or @iin in reverse (i.e. sum from the high-index end of the list)?

The answer I would have given before I actually looked at it in detail would have been: subtract the running sum or integral from the definite sum over the whole range. And indeed I have done this many times. But the result is not quite as expected, as the following example shows:

yes? let test = {1,2,3,4,5,6}
yes? list test, test[i=@rsum], test[i=@sum] - test[i=@rsum]
X: 0.5 to 6.5
Column 1: TEST is {1,2,3,4,5,6}
Column 2: TEST[X=@RSU] is {1,2,3,4,5,6} (running sum on X)
Column 3: EX#3 is TEST[I=@SUM]-TEST[I=@RSUM]
TEST TEST EX#3
1 / 1: 1.000 1.00 20.00
2 / 2: 2.000 3.00 18.00
3 / 3: 3.000 6.00 15.00
4 / 4: 4.000 10.00 11.00
5 / 5: 5.000 15.00 6.00
6 / 6: 6.000 21.00 0.00

The second column does what we want in a running sum: the first value is the value of the function over interval 1. The second value is the sum of the function at intervals 1+2. The last value is the sum over the whole range, as it should be. But I had hoped and expected that the third column would be the reverse: The last value (i=6) should be the last value of the function (6), the second-to-last should be the sum of the two last values (6+5=11), and the first value should be the same sum as if the operation were done the other way (21). But it isn't. The whole thing is shifted by 1 interval, the value in position 6 is 0, and the value in position 1 is not the whole sum.

Am I missing something obvious???? What is the proper way to take a running sum or integral in reverse? It should be possible to get the same qualities of the answer doing the operation in either direction.

Billy K

[Thread Prev][Thread Next][Index]

Dept of Commerce / NOAA / OAR / PMEL / TMAP

Contact Us | Privacy Policy | Disclaimer | Accessibility Statement