C1 Introduction to Linear Algebra
C1 Introduction to Linear Algebra
We start our discussion on the use of MATLAB® with an introduction on the concept of vectors and
matrices. A matrix is a rectangular array of numbers or functions. In general, we call the contents of a
matrix its elements. An example of a matrix is shown below:
An m × n matrix simply means that it has m number of rows and n number of columns. The size of a
matrix is often referred to using this notation, e.g., a 3×4 (read as “3 by 4”) matrix has a size of 3 rows and
4 columns. To identify elements in a matrix, we use the indices i (to refer to its row assignment) and j (to
refer to its column assignment). For example, element a12 is the element of matrix A found in the first
row (i =1) and second column (j=2). Thus, amn simply refers to the element found in the mth row and nth
column.
In this course, you will encounter several types of matrices when programming. The following list
summarizes the characteristics of each special type:
A = a1 a2 ... an
b1
b
B= 2
...
bm
3. Square Matrix – matrix in which the number of rows equals the number of columns. The
principal/main diagonal contains the elements where the subscripts are equal (i=j). The trace of
a square matrix is the sum of the elements of its principal diagonal.
2
4. Upper Triangular Matrix – a square matrix in which all elements below the principal diagonal are
zero. Matrix U is an example.
5. Lower Triangular Matrix – a square matrix in which all elements above the principal diagonal are
zero. Matrix L is an example.
l 11 0 0
L = l 21 l 22 0
l 31 l 32 l 33
6. Diagonal Matrix – a square matrix in which the only non-zero elements are the elements on the
principal diagonal. Matrix D is an example.
d11 0 0
D = 0 d22 0
0 0 d33
7. Scalar Matrix – a diagonal matrix whose diagonal elements are all equal. In the example below,
matrix S is a diagonal matrix whose element is s.
s 0 0
S = 0 s 0
0 0 s
8. Identity Matrix – a diagonal matrix whose diagonal elements are equal to 1. Matrix IS is an
example.
1 0 0
I S = 0 1 0
0 0 1
Arithmetic operations on matrices and vectors can also be done. In matrix addition (and subtraction),
the corresponding elements of two matrices (which must be of equal sizes) are just algebraically added
(or subtracted). For example, for matrices A and B:
1 −2 4 3 2 −2
A= B=
−3 2 1 4 −1 1
3
1+3 −2 + 2 4 − 2 4 0 2
A+B = C = =
−3 + 4 2 − 1 1 + 1 1 1 2
For scalar multiplication, each element in the matrix is multiplied with a scalar quantity (a matrix with
only one element). Note that multiplication with a vector quantity will result in a different product
matrix, as vectors can have more than one element. For example, when matrix A in the previous example
is multiplied with -3, the resulting matrix will be:
1 −2 4 −3 6 −12
−3A = −3 =
−3 2 1 9 −6 −3
u v
a b c
A= C = w x
d e f y z
au + bw + cy av + bx + cz
AC =
du + ew + fy dv + ex + fz
The elements of this product matrix can be obtained using a summation rule. As an exercise, you can
verify the elements of the product matrix AC by making use of the following equation:
n
xij = a c
k =1
ik kj
Any element of product matrix AC (xij) can be obtained by summing up from k=1 until n (where n is the
number of columns, and k is another index) the product of aik and ckj (elements of matrices A and C).
IMPORTANT: Matrix multiplication will only work when an m×n matrix is multiplied by an n×p matrix.
The resulting product matrix will have a size of m rows and p columns.
Matrix transposition occurs when the subscript for a row (i) is written as a subscript for a column, and the
subscript for a column (j) is written for a row. The transpose of matrix A is denoted as AT:
u v
a b c
A= B = w x
d e f y z
a d
u w y
A = b e
T
BT =
v x z
c f