GNU Octave: Sums and Products

Next: Utility Functions, Previous: Trigonometry, Up: Arithmetic [Contents][Index]

### 17.4 Sums and Products

Built-in Function: sum (x)
Built-in Function: sum (x, dim)
Built-in Function: sum (…, "native")
Built-in Function: sum (…, "double")
Built-in Function: sum (…, "extra")

  Sum of elements along dimension dim.

  If dim is omitted, it defaults to the first non-singleton dimension.

  The optional `"type"` input determines the class of the variable used for calculations. If the argument `"native"` is given, then the operation is performed in the same type as the original argument, rather than the default double type.

  For example:

      sum ([true, true])
         ⇒ 2
      sum ([true, true], "native")
         ⇒ true

  On the contrary, if `"double"` is given, the sum is performed in double precision even for single precision inputs.

  For double precision inputs, the `"extra"` option will use a more accurate algorithm than straightforward summation. For single precision inputs, `"extra"` is the same as `"double"`. Otherwise, `"extra"` has no effect.

  See also: cumsum, sumsq, prod.

Built-in Function: prod (x)
Built-in Function: prod (x, dim)
Built-in Function: prod (…, "native")
Built-in Function: prod (…, "double")

  Product of elements along dimension dim.

  If dim is omitted, it defaults to the first non-singleton dimension.

  The optional `"type"` input determines the class of the variable used for calculations. If the argument `"native"` is given, then the operation is performed in the same type as the original argument, rather than the default double type.

  For example:

      prod ([true, true])
         ⇒ 1
      prod ([true, true], "native")
         ⇒ true

  On the contrary, if `"double"` is given, the operation is performed in double precision even for single precision inputs.

  See also: cumprod, sum.

Built-in Function: cumsum (x)
Built-in Function: cumsum (x, dim)
Built-in Function: cumsum (…, "native")
Built-in Function: cumsum (…, "double")
Built-in Function: cumsum (…, "extra")

  Cumulative sum of elements along dimension dim. If dim is omitted, it defaults to the first non-singleton dimension.

  See `sum` for an explanation of the optional parameters `"native"`, `"double"`, and `"extra"`.

  See also: sum, cumprod.

Built-in Function: cumprod (x)
Built-in Function: cumprod (x, dim)

  Cumulative product of elements along dimension dim. If dim is omitted, it defaults to the first non-singleton dimension.

  See also: prod, cumsum.

Built-in Function: sumsq (x)
Built-in Function: sumsq (x, dim)

  Sum of squares of elements along dimension dim. If dim is omitted, it defaults to the first non-singleton dimension.

  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.

  See also: sum, prod.

Next: Utility Functions, Previous: Trigonometry, Up: Arithmetic [Contents][Index]