This lesson explains how to use matrix methods to compute sums of vector elements and sums of matrix elements.
How to Compute Sums: Vector Elements
The sum vector 1n is a 1 x n column vector having all n elements equal to one. The main use of the sum vector is to find the sum of the
elements from another 1 x n vector, say vector xn.
Let's demonstrate with an example.
1 1
1 = 1 x = 2
1 3
Then, the sum of elements from vector x is:
Σ xi = 1'x = ( 1 * 1 ) + ( 1 * 2) + ( 1 * 3 ) = 1 + 2 + 3 = 6
Note: For this website, we have defined the sum vector to be a column vector. In other places, you may see it defined as a row vector.
How to Compute Sums: Matrix Elements
The sum vector is also used to find the sum of matrix elements. Matrix elements can be summed in three different ways: within column
within rows, and matrix-wide.
Within columns. Probably, the most frequent application is to sum elements within columns, as shown below.
1'X = [ Σ Xr1 Σ Xr2 ... Σ Xrc ] = S
where
1 is an r x 1 sum vector, and 1' is its transpose
X is an r x c matrix
Σ Xri is the sum of elements from column i of matrix X
S is a 1 x c row matrix whose elements are column sums from matrix X
Within rows. It is also possible to sum elements within rows, as shown below.
Σ X1c
Σ X2c
X1 = = S
...
Σ Xrc
where
1 is an c x 1 sum vector
X is an r x c matrix