HP Forums

Full Version: Problems with the command cumSum and Workaround
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Example: store {10, 20, 10} to L1

cumSum(L1):

sometimes returns {10, 40, Nan}
sometimes returns {10, 30, 40} (the right answer)
sometimes causes the calcualtor to crash

Software Version 6975


Here is a possible workaround:
CSUM(list)
BEGIN
LOCAL k;
FOR k FROM 2 TO SIZE(list) DO
list[k]:=list[k]+list[k-1];
END;
RETURN list;
END;

CSUM({10,20.10}) returns {10,30,40}
I couldn't reproduce the errors and the crash you're reporting!
Hi Eddie'

I could not reproduce your error. Tried in HOME mode and CAS with various values in L1.
eddie,

I tried 20 times in CAS and same in Home but could not reproduce the error. Textbook setting, 6975 SW on the actual calculator.

Cheers, Terje
One oddity I have just noted is that whereas cumSum normally returns a list, the built-in cumSum({}) returns numerical 0 instead - a result of a different type.
I am not certain what the correct result should be, but I would expect/hope for either {} or {0}, not 0.
I have implemented cumSum for TI compatibility, and it returns 0 for an empty list.
Reference URL's