|
The function
sum
computes the sum of the elements of an array
with respect to a given dimension. The default dimension is the first
one, i.e. the elements of the matrix are summed columnwise. The
following and all other examples of this section can be found in
XLGmatrix06.xpl
.
x=#(1,3)~#(2,4) sum(x)displays
Contents of sum [1,] 4 6while
sum(x,2)gives
[1,] 3 [2,] 7
Similarly, the function
cumsum
computes the cumulative sum of
the elements of an array with respect to a given dimension:
cumsum(#(5,4,3)~#(1,2,3))yields
Contents of cumsum [1,] 5 1 [2,] 9 3 [3,] 12 6
The functions
prod
and
cumprod
evaluate respectively the
product and cumulative product of the elements of a matrix with
respect to a given dimension. The syntax of these functions is the
same as the functions
sum
and
cumsum
. Thus,
prod(#(5,4,3)~#(1,2,3))returns
Contents of mul [1,] 60 6while
cumprod(#(5,4,3)~#(1,2,3))gives
Contents of cumprod [1,] 5 1 [2,] 20 2 [3,] 60 6