Simple Operations with Mathematical Matrices

This is a brief study guide to explain rudimentary operations involving the mathematical matrices that are used in linear algebra.

Introduction

Mathematical matrices are used  to solve systems of linear equations. Matrices are used in applications such as physics, engineering, probability and statistics, economics, biology, and computer science. (especially in the area of computer graphics) 

Matrices appear in the following form:

This matrix represents this system of linear equations:

  x +  5y + 10z =  5
 6x +  4y + 12z =  4
10x +  5y + 12z = 11
 5x + 11y + 23z =  9

The above matrix has 4 rows and 4 columns, but the number of rows and columns do not have to be equal. In other words it does not have to a square matrix, only rectangular. Each entry can be an integer or real number. In the following examples I only use integers. In this explanation of the behaviors, I use the following notation for matrices.

a0_0  a0_1  a0_2  a0_3

a1_0  a1_1  a1_2  a1_3

a2_0  a2_1  a2_2  a2_3

a1_2 refers to the element in the row 1, column 2 In the actual matrix above that entry is equal to 12.

Matrix addition

Adding matrices is only possible if they have an equal number of rows and columns. 

matrix a        matrix b     result of a + b
a0_0  a0_1      b0_0  b0_1   (a0_0 + b0_0) (a0_1 + b0_1)

a1_0  a1_1      b1_0  b1_1   (a1_0 + b1_0) (a1_1 + b1_1)

a2_0  a2_1      b2_0  b2_1   (a2_0 + b2_0) (a2_1 + b2_1)

Example with values.

matrix a       matrix b      result of a + b
 1    5         5    6         6    11
17    3         5    2        22     5
 5   -3         2    1         7    -2

Matrix Subtraction

Matrix subtraction works almost exactly like matrix  addition. The two matrices must have the same number of rows and the same number of columns.

matrix a        matrix b     result of a - b
a0_0  a0_1      b0_0  b0_1   (a0_0 - b0_0) (a0_1 - b0_1)

a1_0  a1_1      b1_0  b1_1   (a1_0 - b1_0) (a1_1 - b1_1)

a2_0  a2_1      b2_0  b2_1   (a2_0 - b2_0) (a2_1 - b2_1)

matrix a        matrix b      result of a - b
 1    5         5    6        -4    -1
17    3         5    2        12     1
 5   -3         2    1         3    -4

Matrix Multiplication

Matrix multiplication does not work as you would expect. You do not simply multiplying the matching elements. Instead matrices may be multiplied as long as the number of columns in the first matrix equals the number of rows in the second matrix. The number of rows in the resulting matrix is equal to the number of rows in the first matrix (the left hand side operand) and the number of columns in the resulting matrix is equal to the number of columns in the second matrix (the right hand side operand).

Here is an example

Matrix a is a N (rows) by M (columns) matrix and matrix b is a K by L matrix a * b is allowed if M = K.  The result will be a N by L matrix.

Here are the mechanics of matrix multiplication ( _ removed from notation of elements):

matrix a(3X2) matrix b(2X3)     result of a * b (3X3)
a00  a01      b00  b01  b02     (a00*b00 + a01*b10)   (a00*b01 + a01*b11)    (a00*b02 + a01*b12)

a10  a11      b10  b11  b12     (a10*b00 + a11*b10)   (a10*b01 + a11*b11)    (a10*b02 + a11*b12)

a20  a21                        (a20*b00 + a21*b10)   (a20*b01 + a21*b11)    (a20*b02 + a21*b12)

Example with values
matrix a  matrix b   result of a * b
2  4      3 4 1      (2*3 + 4*1 = 10)  (2*4 + 4*8 = 40) (2*1 + 4*4 = 18)
5  2      1 8 4      (5*3 + 2*1 = 17)  (5*4 + 2*8 = 36) (5*1 + 2*4 = 13)
1  5                 (1*3 + 5*1 =  8)  (1*4 + 5*8 = 44) (1*1 + 5*4 = 21)

Or more simply

2  4      3  4  1     10  40  18
5  2   *  1  8  4  =  17  36  13
1  5                   8  44  21

 

Scaling a Matrix Scalar multiplication of a matrix is exactly what you would think. Every element in the matrix is multiplied by the same constant.

Here is an example of scaling matrix a by the constant 2.

matrix a   scale a by 2      resulting matrix
3  4  5    3*2   4*2  5*2     6  8 10 
6  2  6    6*2   2*2  6*2    12  4 12  
9 10  2    9*2  10*2  2*2    18 20  4

Matrix transposition

To transpose a matrix the rows of the original matrix become the columns of the resulting matrix.. The Nth row of the original matrix becomes the Nth column of the transposed matrix.

matrix a    transpose of matrix a
2  4   0    2   5  

5  2  12    4   2       

            0  12

 

 

Back to the CS 307 homepage.