Description
Returns the sum of the elements of the
matrix x
where x is a
logical, integer, real, double-precision or complex matrix.
If x is logical,
s is integer.
Otherwise s has the same type as x.
Vectors
If x is a vector,
s is a scalar and
s = x * x * ... * x
1 2 n where n is the number of elements in x.
If you enter
x = [ 1, 2, 3 ]
sum(x)
O-Matrix will respond
6
If you enter
x = { 1, 2, 3 }
sum(x)
O-Matrix will respond
6
Matrices
If x is not a vector,
s is a row vector with the same column dimension as x and
s = x * x * ... * x j 1,j 2,jm,j where m is the number of rows in the matrix x.
If you enter
x = { [ 1, 2, 3 ], [3, 4, 5] }
sum(x)
O-Matrix will respond
{
[ 4 , 6 , 8 ]
}
Dimension
If the argument d is present, it specifies which
dimension the sum is taken with respect to.
It must be an integer, real, or double-precision scalar equal to 1 or 2.
If you enter
x = { [ 1, 2, 3 ], [3, 4, 5] }
sum(x, 2)
O-Matrix will respond
{
6
12
}