Sums and Products Next: Previous: Trigonometry Up: Arithmetic



Sums and Products

sum (x dim) Built-in Function
Sum of elements along dimension dim. If dim is omitted it defaults to 1 (column-wise sum).

As a special case if x is a vector and dim is omitted, return the sum of the elements.

prod (x dim) Built-in Function
Product of elements along dimension dim. If dim is omitted it defaults to 1 (column-wise products).

As a special case if x is a vector and dim is omitted, return the product of the elements.

cumsum (x dim) Built-in Function
Cumulative sum of elements along dimension dim. If dim is omitted it defaults to 1 (column-wise cumulative sums).

As a special case if x is a vector and dim is omitted, return the cumulative sum of the elements as a vector with the same orientation as x.

cumprod (x dim) Built-in Function
Cumulative product of elements along dimension dim. If dim is omitted it defaults to 1 (column-wise cumulative products).

As a special case if x is a vector and dim is omitted, return the cumulative product of the elements as a vector with the same orientation as x.

sumsq (x dim) Built-in Function
Sum of squares of elements along dimension dim. If dim is omitted it defaults to 1 (column-wise sum of squares).

As a special case if x is a vector and dim is omitted, return the sum of squares of the elements.

This function is conceptually equivalent to computing

          sum (x .* conj (x) dim)
          
but it uses less memory and avoids calling conj if x is real.