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.
Enable comment auto-refresher