cumsum

cumsum(a, b, c, ...)

cumsum(A)

Try it yourself:


Build running totals with cumsum

cumsum(a, b, c, ...) returns cumulative sums. Instead of producing one total, it records the running total after each supplied value. For inputs 2, 3, and 5, the result is 2, 5, 10.

When running totals help

Cumulative sums are ideal for spending balances, accumulated distance, frequency distributions, and time-series progress. Compare sum, which returns only the final total. A cumulative sequence can be paired with diff to recover successive changes, subject to the usual initial-value convention.

Examples

Use cumsum(4, -1, 6) to see a balance move from 4 to 3 to 9. With a vector or matrix, the function follows its supported collection semantics, so inspect the result shape with size. If source values require preparation, use map for a transformation or filter to retain qualifying entries.

Input and precision caveats

Each input should be numeric or compatible with addition. A running total preserves every intermediate rounding effect, so long floating-point sequences can differ slightly from an exact symbolic total. Keep units consistent—adding dollars to percentages is meaningless—and validate missing data before accumulation. For an average that evolves with observations, combine the cumulative total with count rather than dividing by a fixed number.

Try Cumsum in Calcul.io

Start with one of the editable examples above, then replace its arguments with your own values. Keeping the function on a separate calculator line makes the input and result easy to compare. For a longer workflow, assign the result to a variable or reference that line in the next expression.

Check the shown signature before adding optional arguments, and use the related-function links to compare operations with similar purposes.

All functions