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 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.
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 columns, 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.
where
1 is an c x 1 sum vector
X is an r x c matrix
Σ Xic 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
Matrix-wide. And finally, it is possible to compute a grand sum
of all the elements in matrix X, as shown below.
1r' X1c
= Σ Xrc
= S
where
1r is an r x 1 sum vector,
and 1r' is its
transpose
1c is an c x 1 sum vector
X is an r x c matrix
Σ Xrc 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' = [ Σ Ai1
Σ Ai2
Σ Ai3 ]
Hint: Use the sum vector, 12.
Solution
The 1 x 3 vector b' can be derived by premultiplying
matrix A by the
transpose
of 12, as shown below.
Notice that each element of vector b' is indeed equal to the
sum of column elements from matrix A.