How to Compute Sums of Matrix Elements
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 1_{n} 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 x_{n}.
Let's demonstrate with an example.
Then, the sum of elements from vector x is:
Σ x_{i} = 1'x
= ( 1 * 1 ) + ( 1 * 2) + ( 1 * 3 ) = 1 + 2 + 3 = 6
Note: For this web site, 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 columns, within rows, and matrixwide.
Within columns.
Probably, the most frequent application is to sum elements within
columns, as shown below.
1'X
= [ Σ X_{r}_{1}
Σ X_{r}_{2}
...
Σ X_{r}_{c} ]
= S
where
1 is an r x 1 sum vector,
and 1' is its
transpose
X is an r x c matrix
Σ X_{r}_{i} 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.
X1 =



Σ X_{1}_{c} 

Σ X_{2}_{c} 
. . . 
Σ X_{r}_{c} 

= 
S 
where
1 is an c x 1 sum vector
X is an r x c matrix
Σ X_{i}_{c} is the sum of elements from
row i of matrix X
S is a r x 1 column matrix whose elements are
row sums from matrix X
Matrixwide. And finally, it is possible to compute a grand sum
of all the elements in matrix X, as shown below.
1_{r}' X1_{c}
= Σ X_{r}_{c}
= S
where
1_{r} is an r x 1 sum vector,
and 1_{r}' is its
transpose
1_{c} is an c x 1 sum vector
X is an r x c matrix
Σ X_{r}_{c} is the sum of all elements from
matrix X
S is a real number equal to the sum of all elements from
matrix X
Test Your Understanding
Problem 1
Consider matrix A.
Using matrix methods, create a 1 x 3 vector b', such that
the elements of b' are the sum of column elements from
A. That is,
b' = [ Σ A_{i}_{1}
Σ A_{i}_{2}
Σ A_{i}_{3} ]
Hint: Use the sum vector, 1_{2}.
Solution
The 1 x 3 vector b' can be derived by premultiplying
matrix A by the
transpose
of 1_{2}, as shown below.
Notice that each element of vector b' is indeed equal to the
sum of column elements from matrix A.