Sum


Returns the sum of array X over the dimension indexed by variable I.

Declaration

In Analytica 4.0:

Sum( A : Array[I] ; I : optional Index )

In Analytica 4.1:

Sum( A : Array[I] ; I : ... optional Index ; IgnoreNonNumbers,IgnoreNaN: optional boolean )

Analytica 4.1 Notes

In Analytica 4.1 or later, you can sum over mulitple indexes in one step:

Sum(A,I,J,K)

Null values in A are ignored.

If the optional IgnoreNonNumbers is specified as true, then non-numerics such as text or references are ignored, e.g.:

Sum(A,I,J,IgnoreNonNumbers:true)

Compare:

X := Array(I,[5,6,'0',7])
IgnoreWarnings(Sum(X,I)) → "1107" 
Sum(X,I,IgnoreNonNumbers:true) → 18

Using Sum to concatenate text is strongly discouraged, and the JoinText function should be used for that purpose instead. A straight sum over X results in a warning to this effect, but the functionality is still supported for legacy reasons. In that case, (5+6+'0'+7) evaluates as ( ( (5+6)&'0' ) & 7 ). In the second example, numbers are ignored so only the numbers, 5+6+7, are added.

The IgnoreNaN parameter ignores indeterminate numeric values, known as NaNs. Normally NaNs propagate through (which helps in spotting numeric problems in your logic). But if you know there are NaNs that you don't want to sum over, include the optional IgnoreNaN parameter.

Sum(A,I,IgnoreNaN:true)

Use of IgnoreNonNumbers and IgnoreNaN parameters requires the named parameter syntax, as shown in the above examples.

Using Sum to add arrays

Arrays can be added using a simple expression in the form: (Array1 + Array2)

The sum function can also be used to add arrays: Sum([Array1, Array2]). In this example, the I parameter is omitted. The reduced index is the self-index of the list of arrays. Therefore no array indexes are reduced. The two methods are equivalent except for the handling of <<null>> values:

(Array1 + Array2): A null value will nullify the result for a particular coordinate location within the array.

Sum([Array1, Array2]): Null values are treated as zero.

See Also

Comments


You are not allowed to post comments.