0% found this document useful (0 votes)
9 views24 pages

Basic Matrix Operations Explained

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views24 pages

Basic Matrix Operations Explained

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

LESSON 4 - BASIC MATRIX OPERATIONS

AND SOLUTIONS FOR SYSTEMS OF


LINEAR EQUATIONS

1. Matrix Algebra
1.1 Definition of a Matrix

In mathematics, a matrix (plural–matrices) is a rectangular array of


elements (or entries), which may be numbers or, more generally, any
abstract quantities that can be added and multiplied. These elements are
arranged in m number of rows and n number of columns.

Matrices are used to describe linear equations. They can be added,


multiplied, and decomposed in various ways, which also makes them a key
concept in the field of linear algebra.

1.2 Size (Dimension) of a Matrix

The size or dimension of a matrix is determined by the number of its rows


and columns.
The size of the matrix is denoted by m x n
A matrix is denoted by a bold face letter, say A.

For example, a matrix A with m rows and n columns is illustrated below:

FND100 CDCE - University Of Peradeniya Page 1


Element/Component of matrix A

A= a11 a12 a13 ….. a1n


a21 a22 a23 ….. a2n
a31 a32 a33 ….. a3n
am1 am2 am3 ….. amn
mxn

Size/Dimension of matrix A

Amxn = [ aij ]mxn


where,
i=1,2…..n
j=1,2…..m
th
aij = i jth element of matrix A (ith row and jth column)

Example:

2 4 5 3 
A = 1 2 0 − 1
0 2 5 7 
3x 4

This matrix has 3 rows (horizontal lines) and 4 columns (vertical lines)
and thus it is called a 3X4 matrix, read as a “3 by 4 matrix”. The first
number (3) indicates the number of rows and the second number (4)
indicates the number of columns.

FND100 CDCE - University Of Peradeniya Page 2


1.3 Special Types of Matrices

Vector: - a matrix which consists of only 1 row or 1 column. Thus, there are
2 types of vectors – row vector (1 row) and column vector (1column).

Row Vector: any 1xn matrix – [x1 x2 …. xn]


Column Vector: any mx1 matrix – x1
x2
.
Xm

Square Matrix:- any matrix with the same number of rows and
columns
 x11 x12 x13 x14 
x x22 x23 x24 
X =
21
4 rows and 4 columns (m=n)
 x31 x32 x33 x34 
 
 x41 x42 x43 x44 

Identity Matrix: - a square matrix, where all primary diagonal elements


are 1, and off-diagonal elements (all other elements) are 0. The Identity
Matrix is generally denoted by I

I(2X2) = 1 0
01

1 0 0 0
0 1 0 0
I ( 4 x 4) =
0 0 1 0
 
0 0 0 1
primary/main diagonal

FND100 CDCE - University Of Peradeniya Page 3


Diagonal Matrix: - a square matrix in which the elements outside the main
diagonal (off-diagonal elements) are all zero. The diagonal elements
themselves can be any number, in contrast to the Identity Matrix, where
they are equal to one.

1 0 0 
D = 0 4 0 
0 0 − 3 3 x 3

Zero (Null) Matrix: - a matrix composed of all zeros, and can be of any
dimension. It is not necessarily a square matrix. Addition or subtraction of a
null matrix leaves the original matrix unchanged; multiplication by a null
matrix produces another null matrix.

0 0 0 
N = 0 0 0
0 0 0 3 x 3

Transpose of a Matrix: - the Transpose of an mxn matrix A is the nxm


matrix, whose rows are the columns in A, and whose columns are the rows
in A. The transpose of matrix A can be denoted by AT or A’.

If A2X3 = 1 2 3 , then A’3X2 = 1 4


4 5 6 2 5
3 6

If you transpose a column vector, it becomes a row vector.

FND100 CDCE - University Of Peradeniya Page 4


Properties of a Transpose

(A’)’ = A

(A + B)’ = A’ + B’

(AB)’ = B’.A’

Symmetric Matrix: - A square matrix that is equal to its transpose. If A is


a symmetric matrix:
A = AT
The elements of a symmetric matrix are symmetric with respect to the
primary/main diagonal. So if the entries are written as A=aij, then
aij = aji

The following 3x3 matrix is symmetric:


1 2 3
A = A = 2 4 − 5
T 
3 − 5 6  3 x 3

Every diagonal/identity matrix is symmetric, since all off-diagonal entries are


zero.

Note: Equality of Matrices

Two matrices A and B are equal only if they have the same dimensions
(number of rows and columns), and each element in A is identical to the
corresponding element in B.
aij = bij for all i,j

FND100 CDCE - University Of Peradeniya Page 5


1 2 4 3
A=  , B=  ; A ≠ B (different elements)
3 4 2 1

1 2 3 
1 2
A=  , B = 4 5 6 ; A ≠ B (different dimensions)
3 4 7 8 9

1 2 1 2
A=  B=  ; A = B (same elements and dimensions)
3 4 3 4

1.4. Matrix Operations

1.4.1 Matrix Addition

If A and B are two matrices with the same dimensions mxn, (i.e.
conformable for addition) the sum of A and B is the mxn matrix C, whose
elements are ;
Ci,j = ai,j + bi,j for i = 1,2,……m
j = 1,2,…...n

Example:
4 9 2 0
A=  , B = 0 7 
2 1 2 x 2   2x2

Then,
 4 9  2 0   4 + 2 9 + 0 6 9 
A+ B =  + = = 
 2 1 0 7   2 + 0 1 + 7   2 8

FND100 CDCE - University Of Peradeniya Page 6


Laws of Matrix Addition
¾ Commutative Law: A+B=B+A
¾ Associative Law: A+ (B+C) =(A+B)+C

1.4.2 Matrix Subtraction

A – B = A + (-B)

Example:
1 2   2 − 3
A=  , B= 
0 − 1 2 x 2 − 1 7  2 x 2

A–B= 1+(-2) 2+[-(-3)]


0+[-(-1)] -1+(-7)
2X2

− 1 5 
A− B= 
 1 − 8 2 x 2

Note: Matrices with different dimensions cannot be added or subtracted.

FND100 CDCE - University Of Peradeniya Page 7


1.4.3 Matrix Multiplication

1. Scalar Multiplication (Multiplication by a Constant)

In matrix algebra, a simple number (constant) such as 12, -2, or 0.07 is


called a scalar. Multiplication of a matrix by a scalar involves multiplication
of every element of the matrix by that number. The process is called scalar
multiplication because it scales the matrix up or down according to the size
of the number.
If k is any real number (scalar) and A is an mxn matrix, then the
product k.A is defined as the matrix whose elements are given by,
k.A = [[Link]]mxn

Example:
1 2  4 8 
A=  ; k = 4, then k.A =  
0 − 1 2 x 2 0 − 4 2 x 2

2. Matrix Multiplication

Multiplication of two vectors


The product of an n component row vector A, and n component column
vector B,
 b1 
b 
A = [a1 a2 …….an ]1xn , B =  2
....
 
bn  nx1

FND100 CDCE - University Of Peradeniya Page 8


A .B = [a1b1+a2b2+………………..anbn]1x1

Example:

 4
A = [1 2 3] , B = 5 
 
6
A.B = [(1 × 4) + (2 × 5) + (3 × 6)]

A . B = [4+10+18] 1x1 = [32]1x1

Multiplication of two matrices

For any two matrices A and B, the product A.B is defined if and only if the
number of columns in A is equal to the number of rows in B. If so, we say
that “A is conformable to B for multiplication”.
The resulting matrix is the matrix whose elements are the products of the ith
row of A and jth column of B.

Amxp . Bpxn = Cmxn


no of columns in B
no of rows in A
1st
condition

Dimensions of the
resulting matrix

FND100 CDCE - University Of Peradeniya Page 9


Example:

 2 4  5 6 1
A= , B= 
 3 1  7 8 3

5 6  1
A .B = [2 4]   [2 4]   [2 4]  
7  8  3

5  6  1
[3 1]   [3 1]   [3 1]  
7  8  3

= 10+28 12+32 2+12


15+7 18+8 3+3

= 38 44 14
22 26 6 2x3

Properties Matrix Multiplication


A.(B.C) = (A.B).C Associative Law

A.(B+C) = A.B+A.C Distributive Law

A.B ≠ B.A Commutative Law breaks down

Note: Multiplication of matrix A by I (Identity Matrix) leaves matrix A


unchanged. Therefore, the I matrix is similar to the number 1 in algebra.

Stop your reading now and move on to Self


Assessment Exercise 1

FND100 CDCE - University Of Peradeniya Page 10


2.0 Matrix Inverse

2.1. Determinant of a Matrix

The determinant of a square matrix A, denoted by |A|, is a uniquely defined


scalar (number) associated with that matrix. Note that determinants are
defined only for square matrices. A determinant is an expansion around
any row or column, which is the sum of each element multiplied by its
cofactor.

The following concepts are necessary in calculating the determinant of a


matrix.

Minor: Let A be an nxn matrix. Let Aij be the (n-1)(n-1) sub matrix

obtained by deleting row i and column j from A .

Then, the scalar M ij = Aij = det Aij is called the (i,j)th minor of the element

aij of Matrix A.

Cofactor: It is a scalar C ij is called the (ij)th cofactor of the aijth element of


Matrix A. It is the minor with a specified sign. (signed minor)

Cij = (−1) i + j M ij

Note: if i+j is an even number, Cij = Mij

if i+j is an odd number, Cij = -Mij

FND100 CDCE - University Of Peradeniya Page 11


Determinant of a 2x2 Matrix:

a a12 
A =  11 ,
a21 a22 

Set of Minors: Set of Cofactors:


M11 = |a22| C11 = (-1)1+1M11 = (-1)2M11 = a22
M12 = |a21| C12 = (-1)1+2M12 = (-1)3M12 = -a21
M21 = |a12| C21 = (-1)2+1M21 = (-1)3M21 = -a12
M22 = |a11| C22 = (-1)2+2M22 = (-1)4M22 = a11

The determinant of matrix A, |A|, is the expansion (sum of each element


multiplied by its cofactor) around any row or column:
Row one: R1 = a11C11 + a12C12 = a11a22 – a12C21
Row two: R2 = a21C21 + a22C22 = -a21a12 + a22a11

Example:
A= 1 2
3 4

M11=|4|, M12=|3|, M21=|2|, M22=|1|, C11=4, C12=(-3), C21=(-2), C22 = 1

|A| = a11C11 + a12C12 = (1x4) + (2x-3)


= -2

A simple method to find the determinant of a 2x2 matrix is illustrated below:

a a12 
A =  11 , |A| = a11.a22 – a21.a12
a21 a22 
The product of diagonal elements minus the product of off-diagonal
elements gives the determinant.

FND100 CDCE - University Of Peradeniya Page 12


Example 1

A = -1 -4 , |A| = (-1x57) – (5x-4) = -37


5 57

Determinant of a 3x3 Matrix:

 a12 a12 a13 


A = a21 a22 a23 
 
 a31 a32 a33 

ƒ The first step is to find the minors:

a 22 a 23 a 21 a 23 a 21 a 22
M 11 = . M 12 = , M 13 =
a32 a33 a31 a33 a31 a32

It is sufficient to find the minors of only 1 row or 1 column. Here we have


found the minors for row 1 of the A matrix.

ƒ
Next, find the cofactors C11=(-1)1+1.M11, C12=(-1)1+2.M12,

ƒ
C13=(-1)1+3.M13
C11=(+)M11, C12=(-)M12, C13=(+)M13

ƒ Thirdly, expand around the 1st row (multiply element by cofactor):


a11.C11 + a12.C12 + a13.C13

|A| = a11(a22.a33 – a23.a32) – a12(a21.a33 – a23.a31) + a13(a21.a32 – a22.a31)

FND100 CDCE - University Of Peradeniya Page 13


Example 2

3 2 5
A = 3 4 1
 
5 6 1

Expansion of 1st row:


|A| = 3x(-1)1+1. 4 1 + 2x(-1)1+2. 3 1 + 5x(-1)1+3. 3 4
6 1 5 1 5 6

= 3x(4x1 – 6x1) + (-2)x(3X1 – 5x1) + 5x(6x3 – 5x4)


= 3x(-2) - 2x(-2) + 5x(-2)
= -6 –(-4) + (-10)
= -12

We can verify whether we get the same answer by expanding another row.

Expansion of row 2:
|A| = 3x(-1)2+1. 2 5 + 4x(-1)2+2. 3 5 + 1x(-1)2+3. 3 2
6 1 5 1 5 6

= -3x(-28) + 4x(-22) -1x8


= 84 – 88 – 8
= -12

FND100 CDCE - University Of Peradeniya Page 14


Note: Singularity and Non singularity

If A = 0 , it is said that A is a singular matrix no matrix inverse exists

If A ≠ 0 , it is said that A is a nonsingular matrix a matrix inverse exists

2.2 Inverse of a Matrix

Let A(k , k ) be a non-singular matrix. Then there exists a unique matrix, call it

B(k ,k ) such that


,

AB = BA = I (K , K )

The matrix B is called the INVERSE of A and is denoted by A−1.

AA−1 = A−1 A = I (k , k )

where I(k,k) denotes the identity matrix.

FND100 CDCE - University Of Peradeniya Page 15


2.2.1 Finding Inverse using Determinants (Adjoint Matrix
Method)

Let A be a nonsingular matrix, that is A ≠ 0 , then,

1
A −1 = adjA
A

AdjA = C T (Transpose of C), where C is the cofactor matrix

Example 1:

1 2
A= 
3 4

First, it is important to check whether A is a non-singular matrix (|A|≠0), in


order to clarify that A is invertible.

|A| = (1X4) – (3X2) = -2 ≠ 0 (an inverse thus exists)

C (cofactor matrix) = (-1)1+1.4 (-1)1+2.3 = 4 -3


(-1)2+1.2 (-1)2+2.1 -2 1

We can see that the cofactor matrix, C, can be derived by simply


interchanging the diagonal elements , 1 and 4 , and changing the sign of
the off-diagonal elements , 2 and 3 of matrix A. However this condition
can be applied only to 2x2 matrices.

Adj.A = CT = 4 -2
-3 1

FND100 CDCE - University Of Peradeniya Page 16


1
A −1 = adjA , det A=-2
det A

1  4 − 2  − 2 1 
A−1 = −  =
2 − 3 1  3 / 2 − 1 / 2

Of course, if A−1 really is the inverse of A , then A−1 A and AA−1 should
multiply out to give I (identity matrix). Checking this condition:

− 2 1  1 2 1 0
A−1 A =   3 4 = 0 1
3 / 2 − 1 / 2    

1 2  − 2 1  1 0
AA−1    = 
3 4 3 / 2 − 1 / 2 0 1

Thus A-1 is truly the inverse of A in this example.

Example 2:

9 1 5
A = 1 2 3 ,
 
5 3 4

2 3 1 3 1 2
A = (- 1 ) 91 1+1
+ (-1) + (-1) 5
1+ 2 1+ 3

3 4 5 4 5 3

= 9(8 − 9) − 1(4 − 15) + 5(3 − 10)


= −9 + 11 − 35
= −33

FND100 CDCE - University Of Peradeniya Page 17


Adj A=CT

 c11 c12 c13 


C = c 21 c 22 c 23
 
c31 c32 c33

2 3
C11 = (−1)1+1 = 1 * (8 − 9) = −1
3 4

1 3
C12 = (−1)1+2 = −1 * (4 − 15) = 11
5 4

1 2
C13 = (−1)1+3 = 1 * (3 − 10) = −7
5 3

1 5
C 21 = (−1) 2+1 = −1 * (4 − 15) = 11
3 4

9 5
C 22 = (−1) 2+ 2 = 1 * (36 − 25) = 11
5 4

9 1
C 23 = (−1) 2+3 = −1 * (27 − 5) = −22
5 3

1 5
C 31 = (−1) 3+1 = 1 * (3 − 10) = −7
2 3

9 5
C 32 = (−1) 3+ 2 = −1 * (27 − 5) = −22
1 3

9 1
C 33 = (−1) 3+3 = 1 * (18 − 1) = 17
1 2

FND100 CDCE - University Of Peradeniya Page 18


 − 1 11 −7 
C =  11 11 − 22
 
− 7 − 22 17 

 − 1 11 −7 
C T =  11 11 − 22
 
− 7 − 22 17 

 − 1 11 − 7   1 / 33 − / 3 7 / 33 
1   
−1
A = 11 11 − 22 = − 1 / 3 − 1 / 3 2/3 
− 33    
− 7 − 22 17   7 / 33 2 / 3 − 17 / 33

You can multiply this answer (A-1) by A and see whether you get the identity
matrix.

Example 3:

2 5  2 5
B=  det( B) = = 2(10) − 5(4) = 20 − 20 = 0
4 10 4 10

We see that det( B) = 0 so this matrix is singular and the inverse does not

exist.
Properties of an Inverse

A-k = (A-1)k

(A-1)-1 = A

(k.A)-1 = (1/k).A-1 for k≠0

(A’)-1 = (A-1)’

2.3. (A.B)-1 = B-1.A-1

FND100 CDCE - University Of Peradeniya Page 19


Solving Systems of Linear Equations

General Case: a11x1 + a12x2 = b1


a21x1 + a22x2 = b2

In matrix form: a11 a12 x1 = b1


a21 a22 x2 b2

A X B
Right-hand side
Coefficient
Vector of vector of constants
matrix
unknowns

2.3.1 Methods of Solving Linear Equations

1. Using Matrix Inversion

Basic equation: A.X = B


If A is invertible,
A-1. A.X = A-1.B (pre-multiplying both sides of the equation by A-1)
But, A-1.A = I and I.X = X
Therefore,
X = A-1.B

FND100 CDCE - University Of Peradeniya Page 20


Example:
The equilibrium prices P1 and P2 for two goods satisfy the equations,
− 4 P1 + P2 = −13
2 P1 − 5P2 = −7

The equations can be written in matrix form as:

− 4 1   P1  − 13
 2 − 5  P  =  − 7 
  2   
A X B
|A| =
−4 1
= (−4)(−5) − (1)(2) = 20 − 2 = 18
2 −5

To find A−1 we swap the diagonal elements -4 and -5 , and change the
sign of the off–diagonal elements, 1 and 2, and divide by the determinant,
18, to get,
1  − 5 − 1
A−1 =
18 − 2 − 4

−1
Finally, to calculate X we multiply A by B,
X = A-1.B
1  − 5 − 1   − 13
=
18  − 2 − 4  − 7 

1 72
=
18 54

 4
= , Hence P1 =4 and P2 = 3.
 3

FND100 CDCE - University Of Peradeniya Page 21


2. Using Cramer’s Rule

Cramer’s rule provides a simplified method of solving a system of linear


equations through the use of determinants. Cramer’s rule states that,

Ai
xi =
A

th
where xi is the i unknown variable in a series of equations, A is the

determinant of the coefficient matrix and Ai is the determinant of a special

matrix formed from the original coefficient matrix by replacing the column of
coefficients of xi with the column vector of constants.

This method is further explained using the following example.

Example:
Solve the following system of equations using Cramer’s rule.
6 x1 + 5 x2 = 49

3 x1 + 4 x2 = 32

Firstly, express the equation in matrix form:


AX=B
6 5  x1  49
3 4  x  = 32
   2  

Find the determinant of A,


A = 6(4)-5(3) =9

FND100 CDCE - University Of Peradeniya Page 22


Then to solve for x1 , replace column 1, the coefficients of x1 with the vector

of constants B, forming a new matrix A1 ,

49 5
A1 =  
32 4
Find the determinant of A1

A1 = 49(4)-5(32) = 36

Then use the formula for Cramer’s rule,


A1 36
x1 = = =4
A 9

To solve for x2 , replace the column 2, the coefficients of x2 , from the original

matrix, with the column vector of constants B, forming a new matrix A2

6 49
A2 =  
3 32

Take the determinant of |A2|,


A2 =6(32)-49(3)=45

And use the formula


A2 45
x2 = = =5
A 9

Thus the solutions of the above example are:


x1=4 and x2=5

FND100 CDCE - University Of Peradeniya Page 23


2.4. Points to be remembered

−1
An inverse matrix A , which can be found only for a square, nonsingular
matrix A, is a unique matrix satisfying the following relationship.

AA−1 = I = A−1 A
Cramer’s rule provides a simplified way of solving a system of linear
equations through the use of determinants and it states that,
Ai
xi =
A

Stop your reading now and move on to Self


Assessment Exercise 2.

FND100 CDCE - University Of Peradeniya Page 24

You might also like