SUM2D
The SUM2D function returns the sum of values in a two-dimensional array. The format of the function is
SUM2D(ArrayName[], Row1, RowN, Col1, ColM)
ArrayName is the name of the array. The bracket characters [] must appear after the array name with nothing enclosed
Row1 and RowN are the first and last rows to be included in the sum. Note that the row number is represented by the first argument in the array, i.e., X[Row,Col]
Col1 and ColM are the first and last columns to be included in the sum.
Row1, RowN, Col1, and ColM must be integers or previously-defined EES variables. If mathematical operations are required, do them in separate equations before setting these limits.
Example:
N = 3 // Number of rows
M = 3 // Number of columns
x[1..N, 1] = [0.34,0.25,0.4]
x[1..N, 2] = [0.33,0.25,0.4]
x[1..N, 3] = [0.33,0.5,0.2]
Sumx=SUM2D(x[],1,N,1,M)
{Solution:
SumX=3}
Note: When used within Functions or Procedures, Row1, RowN, Col1, and ColM must be known at the time of compilation. This requirement means that the limits cannot be provided as arguments or calculated within the Function/Procedure. A work-around for this situation is to use do the sum within the Function or Procedure using Repeat - Until groups, as in the following example.
FUNCTION doSum2D(N,M)
$Common X[1..3,1..3]
i=0
thesum=0
REPEAT
i=i+1
j=0
REPEAT
j=j+1
theSum=theSum+X[i,j]
UNTIL (j>=3)
UNTIL (i>=N)
doSum2D=theSum
END
N = 3 // Number of rows
M = 3 // Number of columns
x[1..N, 1] = [0.34,0.25,0.4]
x[1..N, 2] = [0.33,0.25,0.4]
x[1..N, 3] = [0.33,0.5,0.2]
Sumx=doSum2D(N,M)
Mathematical functions