SUM (matrix1 <, matrix2, …, matrix15> );
The SUM function returns as a single numeric value the sum of all the elements in all arguments. There can be as many as 15 argument matrices. The SUM function checks for missing values and does not include them in the summation. It returns 0 if all values are missing.
For example, following statements compute the sum of all elements in the matrix A:
a = {2 1 ., 0 -1 0}; b = sum(a); print b;
If you want to compute the sum for each row or for each column of a matrix, you can use the subscript reduction operator, as follows:
a[+,]
computes a row vector that contains the sum of each column.
a[,+]
computes a column vector that contains the sum of each row.
a[+]
computes a scalar value that is equivalent to sum(a)
.
See the section Subscript Reduction Operators for more information about subscript reduction operators.