.ModelicaReference.Operators.'sum()'

Information

Returns the scalar sum

Syntax

sum(A)
sum(e(i, ..., j) for i in u, ..., j in v)

Description

The first form returns the scalar sum of all the elements of array expression A:
A[1,...,1]+A[2,...,1]+....+A[end,...,1]+A[end,...,end]

The second form is a reduction expression and returns the sum of the expression e(i, ..., j) evaluated for all combinations of i in u, ..., j in v:

e(u[1],...,v[1]) + e(u[2],...,v[1]) + ... +
e(u[end],...,v[1]) + ... + e(u[end],...,v[end])

The type of sum(e(i, ..., j) for i in u, ..., j in v) is the same as the type of e(i,...j).

Examples

sum(i for i in 1:10)  // Gives  1+2+...+10=55
   // Read it as: compute the sum of i for i in the range 1 to 10.

Generated at 2019-07-16T01:39:24Z by OpenModelicaOpenModelica 1.14.0~dev-26600-g7be26d6 using GenerateDoc.mos