Computational Mathematics Open University
Computational Mathematics Open University
Computational Mathematics Open University
Mathematics
OUbs033112
Table of Contents
UNIT 1 – Matrices 2
1.1 Introduction
In this Unit, you will be introduced to matrices. The aim of Unit 1 is to explain how
to manipulate matrices. Matrices are useful in Computer Graphics. For instance if
you have to rotate an object, you assign the coordinates to the vertices of the object
and multiply coordinates by a matrix that does rotation.
We can also represent this matrix A by A = (aij), i =1, 2, 3,…,m and j = 1, 2, 3,…,n.
An example of a (2 x 3) matrix B is
2 3.5 −45
𝐵 = ( 1 −6.7 2 )
2
In matrix B:
There are 2 rows and 3 columns. Here m = 2 and n = 3.
2
The first column is C1 = ( 1 )
2
3.5
The second column is C2 = ( )
−6.7
−45
The third column is C3 = ( )
2
Answer:
(a) (4 x 2)
(b) (-7 8)
−3.1
(c) ( 6 )
8
1
(d) 6
(e) -7
A Row Matrix is a matrix with one row. Example: (2 5 4) has one row and three
columns.
−7
A Column Matrix is a matrix with one column. Example: ( ) has two rows and one
10
column. A column matrix is also called a vector.
A Square Matrix is one that has equal number of rows and columns m = n. For example,
1 4 2
(−12 5 5) has three rows and three columns.
5 3 8
The main diagonal of a square matrix constitute of the elements: a11, a22, a33,…
𝒂𝟏𝟏 𝑎12 ⋯ 𝑎1𝑛
𝑎21 𝒂𝟐𝟐 ⋯ 𝑎2𝑛
𝐴= ( ⋮ ⋮ ⋮ ⋮ )
𝑎𝑚1 𝑎𝑚2 ⋯ 𝒂𝒎𝒏
In the matrix 𝐴 = ( 2
3
) the elements 2 and 5 lie on the main diagonal.
−1 5
2 3
In the matrix A = ( ) the elements 2 and 5 lie on the main diagonal.
−1 5
An identity matrix is a square matrix in which all the elements on the main
diagonal have a value of one and all the other remaining elements have a value of
zero:
1 0 0
1 0
𝐼2 = ( ) 𝐼3 = (0 1 0)
0 1
0 0 1
I2 is a (2 x 2) identity matrix.
I3 is a (3 x 3) identity matrix.
Note IA = A and AI = A provided it is possible to multiply the matrices.
A diagonal matrix is one in which the elements that are not on the main
diagonal are zero while at least one element on the main diagonal is non-zero.
2 0 0
𝐷 = (0 −1 0)
0 0 3
A zero matrix is one in which all the elements have a value of zero.
A lower triangular matrix is one in which all the elements above the main
diagonal are zero.
2 0 0
𝐿 = (5 −1 0)
6 1 3
An upper triangular matrix is one in which all the elements below the main
diagonal are zero.
2 60 8
𝑈 = (0 −1 9)
0 0 3
Note if A + B = B + A, A – B ≠ B – A
2 − 10 −3 − 20 4−0 −8 −23 4
𝐴−𝐵 = ( )=( )
5−7 1−8 6−9 −2 −7 −3
10 − 2 20 − −3 0 − 4 8 23 −4
𝐵−𝐴 = ( )=( )
7−5 8−1 9−6 2 7 3
Scalar Multiplication
Suppose that k is a number. Let A be a matrix. Then kA is a matrix that has exactly the same order
as A. The matrix kA is obtained by multiplying all the elements of matrix A by k. For example 2A
means we multiply all the elements of A by 2.
5 −3 4 5 −3 4
𝐼𝑓 𝐴 = ( ) 𝑡ℎ𝑒𝑛 2𝐴 = 2 ( )
7 1 6 7 1 6
6
10 −6 8
2𝐴 = ( )
14 2 12
Activity 2
𝟗 𝟓 𝟔 𝟏𝟎
𝑨=( ) and 𝑩 = ( )
−𝟏 𝟒 𝟎 𝟕
Write the matrix (1) 2A
(2) 3B
(3) 2A + 3B
(4) 2B - 3A
Answer
𝟏𝟖 𝟏𝟎 𝟏𝟖 𝟑𝟎
𝟐𝑨 = ( ) 𝟑𝑩 = ( )
−𝟐 𝟖 𝟎 𝟐𝟏
𝟑𝟔 𝟒𝟎
𝟐𝑨 + 𝟑𝑩 = ( )
−𝟐 𝟐𝟗
−𝟏𝟓 𝟓
𝟐𝑩 − 𝟑𝑨 = ( )
𝟑 𝟐
Matrix Multiplication
When we multiply two matrices, the product is a matrix. However, it is not always
possible to multiply two matrices. If A and B are two matrices then for the matrix
AB to exist, the number of columns in matrix A must be equal to the number of
rows in matrix B.
Note that AB ≠BA. Existence of AB does not guarantee that BA will also exist.
Suppose that matrix A has order (m x n) and matrix B has order (p x q). The
product AB will exist only if n = p.
If AB exists then its order will be (m x q).
Rows of matrix A are multiplied by columns of matrix B.
For example:
𝑥
(𝑎 𝑏) (𝑦) = (𝑎𝑥 + 𝑏𝑦)
𝑥
(2) multiply the row (a b c) by the column (𝑦):
𝑧
𝑥
(𝑎 𝑏 𝑐 ) (𝑦) = (𝑎𝑥 + 𝑏𝑦 + 𝑐𝑧)
𝑧
For example
(1 2) (5) = (1x5 + 2x6) = (17)
6
5
(1 2 3) (6) = (1x5 + 2x6 + 3x7) = (38)
7
−𝟐
𝟏 𝟐 𝟑
𝑨 = ( ) 𝑩=( 𝟎 )
𝟒 𝟓 𝟔
𝟏𝟎
The matrix A has order (2 x 3). The matrix B has order (3 x 1). Clearly, the matrix AB exists
because number of columns in matrix A is equal to number of rows in matrix B. The order of matrix
AB is (2 x 1).
1x − 2 + 2x0 + 3x10 28
𝑨𝑩 = ( )= ( )
4x − 2 + 5x0 + 6x10 52
Note matrix B has three rows and one column while matrix A has two rows and three columns. Matrix
BA does not exist because number of columns in matrix B is not equal to number of rows in matrix A.
−7 12
𝐴2 = ( )
−24 17
10 1
For example, if 𝐴 = ( )
−2 20
Then |A| = (10 times 20) minus (1 times -2) =200 - -2=202
Example
1 2 3
𝐴=( 7 8 9)
−4 6 5
Minors
A minor is a determinant. A square matrix of order (m x m) has m minors. To find the minor Mij,
proceed as follows:
Step 1: Delete the row i and column j.
Step 2: Minor is the determinant of the remaining matrix after deleting the ith row and jth column.
Cofactors
The cofactor of Cij is defined as Cij = (-1)i+j Mij
Matrix of Minors
The (3x3) matrix of minors is defined as
𝑀11 𝑀12 𝑀13
𝑀 = (𝑀21 𝑀22 𝑀23 )
𝑀31 𝑀32 𝑀33
Matrix of Cofactors
The (3x3) matrix of cofactors is defined as
𝐶11 𝐶12 𝐶13
𝐶 = (𝐶21 𝐶22 𝐶23 )
𝐶31 𝐶32 𝐶33
Adjoint
Adjoint is obtained by the transpose of the matrix of cofactors
𝐶11 𝐶12 𝐶13 𝑇 𝐶11 𝐶21 𝐶31
𝑇
𝐴𝑑𝑗𝑜𝑖𝑛𝑡 = 𝐶 = (𝐶21 𝐶22 𝐶23 ) = (𝐶12 𝐶22 𝐶32 )
𝐶31 𝐶32 𝐶33 𝐶13 𝐶23 𝐶33
Example
Find the minors and cofactors of the matrix A.
9 8 7
𝐴 = (6 5 4)
1 2 3
Write the matrix of minors.
Write the matrix of cofactors.
Write the adjoint of matrix A.
Solution
To find the minor M11, we will delete the first row and first column from matrix A. We will then
calculate the determinant of the remaining matrix:
10
To find the minor M12, we will delete the first row and second column from
matrix A. We will then calculate the determinant of the remaining matrix:
6 4
𝑀12 = | | = (6x3 − 1x4) = 14
1 3
To find the minor M13, we will delete the first row and third column from matrix
A. We will then calculate the determinant of the remaining matrix:
6 5
𝑀13 = | | = (6x2 − 1x5) = 7
1 2
To find the minor M21, we will delete the second row and first column from
matrix A. We will then calculate the determinant of the remaining matrix:
8 7
𝑀21 = | | = (8x3 − 2x7) = 10
2 3
To find the minor M22, we will delete the second row and second column from
matrix A. We will then calculate the determinant of the remaining matrix:
9 7
𝑀22 = | | = (9x3 − 1x7) = 20
1 3
To find the minor M23, we will delete the second row and third column from
matrix A. We will then calculate the determinant of the remaining matrix:
9 8
𝑀23 = | | = (9x2 − 1x8) = 10
1 2
To find the minor M31, we will delete the third row and first column from matrix
A. We will then calculate the determinant of the remaining matrix:
8 7
𝑀31 = | | = (8𝑥4 − 5𝑥7) = −3
5 4
11
To find the minor M33, we will delete the third row and third column from matrix A. We will then
calculate the determinant of the remaining matrix:
9 8
𝑀33 = | | = (9x5 − 6x8) = −3
6 5
𝟕 −𝟏𝟒 𝟕 𝑻 𝟕 −𝟏𝟎 −𝟑
𝑇
𝐴𝑑𝑗𝑜𝑖𝑛𝑡 𝑜𝑓 𝑀𝑎𝑡𝑟𝑖𝑥 𝐴 = 𝒂𝒅𝒋 (𝑨) = 𝐶 = (−𝟏𝟎 𝟐𝟎 −𝟏𝟎) = (−𝟏𝟒 𝟐𝟎 𝟔)
−𝟑 𝟔 −𝟑 𝟕 −𝟏𝟎 −𝟑
Determinant of Matrix
The determinant of matrix A is obtained by using any row or column of matrix A.
For instance if you use the first row then |𝐴| = 𝑎11 𝐶11 + 𝑎12 𝐶12 + 𝑎13 𝐶13
For instance if you use the second row then |𝐴| = 𝑎21 𝐶21 + 𝑎22 𝐶22 + 𝑎23 𝐶23
For instance if you use the third row then |𝐴| = 𝑎31 𝐶31 + 𝑎32 𝐶32 + 𝑎33 𝐶33
For instance if you use the first column then |𝐴| = 𝑎11 𝐶11 + 𝑎21 𝐶21 + 𝑎31 𝐶32
For instance if you use the second column then |𝐴| = 𝑎12 𝐶12 + 𝑎22 𝐶22 + 𝑎32 𝐶32
For instance if you use the third column then |𝐴| = 𝑎13 𝐶13 + 𝑎23 𝐶23 + 𝑎33 𝐶33
Example
Find the determinant of the matrix A.
𝟗 8 𝟕
𝐴 = (6 5 4)
1 2 3
Solution
We found that the matrix of cofactors is
12
You can try using any other rows and column of matrix A, you will always get the
same answer for determinant of A.
Inverse of Matrix
If a matrix A is NOT singular, that is, the determinant of the matrix A is NOT zero,
then we can find the inverse of the matrix A, which we write as A-1, using the
formula
1
𝐴−1 = 𝑎𝑑𝑗 (𝐴)
|𝐴|
Example
Find the minors and cofactors of the matrix A.
−1 1 2
𝐴 = ( 2 −2 1 )
1 4 −1
Write the matrix of minors.
Write the matrix of cofactors.
Write the adjoint of matrix A.
Find the determinant of matrix A.
Find the inverse of matrix A.
Solution
−2 1
𝑀11 = | | = (−2 𝑥 − 1 − 1𝑥4) = −2
4 −1
2 1
𝑀12 = | | = (2x − 1 − 1x1) = −3
1 −1
2 −2
𝑀13 = | | = (2 x 4 − 1x − 2) = 10
1 4
1 2
𝑀21 = | | = (1x − 1 − 4x2) = −9
4 −1
13
−1 2
𝑀22 = | | = (−1𝑥 − 1 − 1𝑥2) = −1
1 −1
−1 1
𝑀23 = | | = (−1x4 − 1x1) = −5
1 4
1 2
𝑀31 = | | = (1𝑥1 − 2𝑥 − 2) = 5
−2 1
−1 2
𝑀32 = | | = (−1x1 − 2x2) = −5
2 1
−1 1
𝑀33 = | | = (−1x − 2 − 1x2) = 0
2 −2
−2 9 5
𝐴𝑑𝑗𝑜𝑖𝑛𝑡 𝑜𝑓 𝑀𝑎𝑡𝑟𝑖𝑥 𝐴 = 𝒂𝒅𝒋 (𝑨) = 𝐶 𝑇 = ( 3 −1 5)
10 5 0
Determinant of Matrix
Using the first row
|𝐴| = 𝑎11 𝐶11 + 𝑎12 𝐶12 + 𝑎13 𝐶13 = (−1x − 2) + (1x3) + (2x10) = 25
Inverse of Matrix
Inverse of Matrix A is
14
Answer
−1 5 7
(b) (−14 −2 2 )
−3 −9 −3
−1 −5 7
(c) ( 14 −2 −2)
−3 9 −3
−1 14 −3
(d) (−5 −2 9 )
7 −2 −3
(e) 24
(f)
−1 7 −1
24 12 8
−5 −1 3
𝐴−1 =
24 12 8
7 −1 −1
( 24 12 8 )
Question 2.
(a) Find the minors and cofactors of the matrix A.
1 3 −1 1
𝐴 = (1 3 1 2 )
1 3 3 −1
2 2 0 2
(b) Write the matrix of minors.
15
Answer
(a) Follow the steps in the examples.
−2 −10 −12 8
(b) ( 20 4 −8 16)
6 −2 4 8
−24 −8 0 0
−2 10 −12 −8
(c) ( −20 4 8 16 )
6 2 4 −8
24 −8 0 0
−2 −20 6 −8
(d) ( 10 4 2 16 )
−12 8 4 −8
−8 16 −8 0
(e) 32
1 5 3 3
− 16 −8 16 4
5 1 1 −1
16 8 16 4
(f) 3 1 1
−8 0
4 8
1 1 1
( −4 2
−4 0)
16
2 Equations
1
UNIT STRUCTURE
2.1 Introduction
2.2 Learning Outcomes
2.3 System of Simultaneous Equations
2.4 Method of Determinants
2.5 Elimination Method
2.6 Activities
2.1 Introduction
In this Unit, you will learn how to solve equations simultaneously. The aim of Unit 2
is to explain how to use matrix operations to solve simultaneous equations. System
of equations emanate from various processes.
We will now use matrix method to solve these equations 2x + 3y = 34 and 3x + y = 23 simultaneously.
17
𝟐 𝟑
The determinant of the matrix of coefficient ( ) = (2 x 1) – (3 x 3) = -7
𝟑 1
𝟐 𝟑 1 1 −𝟑
The inverse of the matrix of coefficient ( )= ( )
𝟑 1 −7 −𝟑 𝟐
𝟐 𝟑 𝑥 34
Therefore, ( ) ( ) = ( ) becomes
𝟑 1 𝑦 23
𝑥 5
(𝑦 ) = ( )
8
Hence x = 5 and y = 8.
The simultaneous equations y = 2x + 5 and y = 2x – 1 have no solution. If you plot the graphs, then you
will see that there is a pair of parallel lines.
18
Where
19
AX = B implies X = A-1 B
Cramer’s Rule
Cramer’s rule uses determinants to solve simultaneous equations.
Consider the system of equations with two unknowns x and y:
a1x + b1y = d1
a2x + b2y = d2
Step 1. We find the determinant of the coefficient matrix. Of course this should
NOT be zero.
𝑎 𝑏1
𝐴= ( 1 )
𝑎2 𝑏2
|A| = (a1 b2) – (a2 b1)
Step 2. We find the determinant of the coefficient matrix with the coefficient of x
replaced by the constants.
𝑑 𝑏1
𝐴𝑥 = ( 1 )
𝑑2 𝑏2
Step 3. We find the determinant of the coefficient matrix with the coefficient of y
replaced by the constants.
𝑎 𝑑1
𝐴𝑦 = ( 1 )
𝑎 2 𝑑2
20
𝟓 𝟏
𝐴𝑥 = ( ) then | 𝐴𝑥 | = (5 x − 1) − (2 x 1) = −5 − 2 = −7
𝟐 −𝟏
|𝐴𝑥 | −7
𝑥= = =1
|𝐴| −7
𝟐 𝟓
𝐴𝑦 = ( ) then | 𝐴𝑦 | = (2 x 2) − (5 x 5) = 4 − 25 = −21
𝟓 𝟐
|𝐴𝑦 | −21
𝑦= = =3
|𝐴| −7
-x + y + 2z = 3
2x - 2y + y = 9
x + 4y – z = -5
−1 1 2
𝑨= (2 −2 1)
1 4 −1
𝟑 1 2
𝑨𝒙 = ( 𝟗 −2 1 )
−𝟓 4 −1
−1 𝟑 2
(
𝑨𝒚 = 2 𝟗 1)
1 −𝟓 −1
−1 1 𝟑
𝑨𝒛 = ( 2 −2 𝟗)
1 4 −𝟓
We calculate x, y and z:
|𝐴𝑥 | 50
𝑥= = =2
|𝐴| 25
|𝐴𝑦 | −25
𝑦= = = −1
|𝐴| 25
21
Step 1.
We will start with the augmented matrix:
Step 2.
We will use the Elementary Row Operations (ERO)
EROi: Interchanging Rows
In the simultaneous equations y = x + 3 and 3y = 5x – 1, it does not matter which equation is written
first. We can write y = x + 3 first or second. The solution will not change.
Since, interchanging two equations does not change the solution, the first elementary operation is
interchanging rows in the augmented matrix.
22
Row-echelon matrix
A row-echelon matrix is one in which
a row of all zeroes, if it exists, must be at the bottom of the augmented matrix;
the first non-zero element in any row of the augmented matrix has a value of
one. This is called a “leading one”;
the leading one of any row is to the immediate right of the leading one of the
previous row; and
all the elements below the leading one are zeroes.
Step 3.
Proceed with the process called Gaussian Elimination: perform the elementary
row operations till the augmented matrix becomes a row-echelon form.
Use back substitution to find the value of each unknown.
OR
Note that you can use the elementary operations in any order and for any
number of times.
Example.
-x + y + 2z = 3
2x - 2y + z = 9
x + 4y – z = -5
−1 1 2 | 3
𝑨 = ( 2 −2 1 | 9 )
1 4 −1 | −5
Row 3 is R3 = (1 4 -1 | -5)
1 −1 −2 | −3
(2 −2 1 | 9 )
1 4 −1 | −5
1 −1 −2 | −3
(1 4 −1 | −5)
0 0 5 | 15
1 −1 −2 | −3
(1 4 −1 | −5)
0 0 1 | 3
In the second row, we will create zero in the first position by subtracting row1 from row 2:
(1 4 -1 | -5) – (1 -1 -2 | -3) = (1 - 1 4- -1 -1- -2| -5- -3) = (0 5 1 | -2)
R2 R2 - R1 :
1 −1 −2 | −3
(0 5 1 | −2 )
0 0 1 | 3
Let’s create one in the second row so that there is a leading one by replacing R2 by 1/5 R2.
R2 1/5R2:
24
Hence x = 2, y = -1 and z = 3.
Note that we could have proceeded further to transform the echelon matrix
1 −1 −2 | −3
1 −2
(0 1 | )
5 5
0 0 1 | 3
−9 −17
1 0 |
5 5
1 −2
0 1 |
5 5
(0 0 1 | 3 )
25
2.6 Activities
Question 1.
Use Cramer’s rule to solve
x + 4y = 9
3x - y = 1
Answer x = 1 and y = 2.
Question 2.
Use Cramer’s rule to solve
-x + 2y + 3z = 8
2x - y + 2z = 1
x + 4y – z = 12
Answer x = 1; y = 3 and z = 1.
Question 3.
Use Cramer’s rule to solve
x + 2y + 3z = -7
2x - 3y - 5z = 9
-6x -8y + z = -22
Question 4.
Use Gaussian elimination to solve
-x + 2y + 3z = 8
2x - y + 2z = 1
26
Answer x = 1; y = 3 and z = 1.
Note that applying the elementary row operations:
2 −1 2 | 1
9 23
0 −2 |
2 2
14 14
0 0 |
( 3 3)
Question 5.
Use Gauss-Jordan elimination to solve
-x + 2y + 3z = 8
2x - y + 2z = 1
x + 4y – z = 12
Answer x = 1; y = 3 and z = 1.
Question 6.
Use Gaussian elimination to solve
x + 2y + 3z = -7
2x - 3y - 5z = 9
-6x -8y + z = -22
−6 −8 1 | −22
−17 −14 5
0 |
3 3 3
89 −178
0 0 |
( 34 17 )
27
Question 7.
Use Gauss-Jordan elimination to solve
x + 2y + 3z = -7
2x - 3y - 5z = 9
-6x -8y + z = -22
3
UNIT
Permutation and
Combination
1 UNIT STRUCTURE
28
3.1 Introduction
In this Unit, you will learn how to find total number of arrangements
of certain objects as well as total number of combinations. The aim
of Unit 3 is to explain how to apply different methods and formulas
to problems.
completing the last kth step. Hence the total number of ways of
n1 n2 n3 . . . . . . nk
Example
In a club there are 5 girls and 6 boys. You have been asked to select a team of one boy and one
girl to represent the club. How many different teams can you have?
Solution
29
The second step consists of selecting one boy out of 6 boys. As you have 6 choices here, you can
complete this step in 6 different ways.
= number of girls that can be chosen in step (1) times number of boys that can be chosen in step
(2)
=56
= 30 ←
Additive Rule
Suppose that there are m alternative methods to complete a task. Then the number of different ways
of completing the task is obtained by adding the number of ways we have to complete each
alternative method.
Example
Suppose that there are 2 girls and 5 boys in a club. Suppose that you have to form a team of 2 persons
with at least one girl. How many different teams can you form?
Solution
Note that at least one girl means here you can either have one girl or more.
= 2 x 5 = 10
The second alternative is to have 2 girls and no boys. This alternative can be completed in one way
only as you have to take both girls. This is the only way.
= 10 + 1 = 11
30
PermutationI
Suppose that it’s your birthday and we have to arrange an apple (A), a bottle of
cola (B) and the birthday cake (C) in a line. How many ways can we arrange the
3 objects A, B and C in a line ?
ABC
last: A C B
ABC
AC B There are six
BAC different ways of
BCA arranging or
CAB permuting the 3
CBA different objects.
31
Open University of Mauritius – Computational Mathematics
Factorial is represented by the exclamation mark !
n! = 1 x 2 x 3 x. . . . . . x n
3 factorial = 3! = 1 x 2 x 3 = 6
= 3! = 1 x 2 x 3 = 6 ←
Example
Suppose that you have four cards numbered 1, 2, 3 and 4. How many 4-digit
numbers (e.g 1234, 2134, . . . . . . ) can you form?
Solution
Forming 4-digit numbers requires arranging the cards. For instance if you want
the number 3241 then you must place card 3 first, then card 2, then card 4
and finally card 1.
Since we have 4 different cards and we would like to arrange all of them, then
this can be done in 4! = 24 ways. Thus we shall have 24 different 4-digit
numbers in all.
Example
Suppose that you had to arrange all the 6 letters in the word FRANCE. How
many different arrangements would you have?
Solution
Since we have 6 different objects that we would like to arrange, then we can
do so in 6! = 720 ways.
Permutation II
Suppose that we have n objects such that ‘a’ of these objects are identical, ‘b’ of
these objects are identical, ‘c’ of these objects are identical, . . . . . . Hence, total
number of arrangements of all these objects is
n!
a! b! c! . . .
32
Open University of Mauritius – Computational Mathematics
Example
In how many ways can you arrange all the letters in the word MISSISSIPPI?
Solution
There are 11 letters in the word MISSISSIPPI with 4 identical ‘S’, 4 identical
‘I’ and 2 identical ‘P’. Therefore, total number of arrangements is
11!
= 34 650
4! times 4! times 2!
Example
Solution
6! 720
= = 60
2! X 3! 2 X 6
because because
we have 2 we have 3
‘1’ ‘4’
33
Open University of Mauritius – Computational Mathematics
Permutation III
Suppose that we have n different objects. We would like to have arrangements
containing r objects. (Of course ‘r’ has a value less than n). How many
arrangements can we have?
𝑛!
Total number of arrangements = n
pr = (𝑛−𝑟 )!
Example
How many arrangements containing 3 letters can be made if the letters are
taken from the word FRANCE?
Solution
Example
Suppose that your dad gave you the four cards numbered 1, 2, 3 and 4. He asked
you to teach numbers to your younger sister. How many different numbers can
you teach her?
Solution
You can use 1 card at a time and teach her number ‘1’, then number ‘2’, then
number ‘3’ and finally ‘4’. So you can teach her 4 1-digit number only. This can
be viewed as arranging one card from the four. This can be done in 4P1 = 4 ways.
Alternatively, you can decide to use 2 cards at a time. Thus, you can teach her
numbers like 21, 12, 13, 14, . . . . . . This can be viewed as arranging 2 cards out
of 4. This can be done in 4P2 = 12 ways.
So you will have 12 2-digit numbers. (As we only have 12 we can write them:
12, 13,
14, 21, 23, 24, 31, 32, 34, 41, 42,
43).
Alternatively, you could have used 3 cards at a time to teach her 3-digit numbers
(e.g
123, 321, . . . . . . ). This means we are arranging 3 cards from four every time.
This can be done in 4P3 = 24. So we have 24 3-digit numbers.
Finally, you could have used all the four cards to form 4-digit numbers like 1234,
4312,
… This means we are arranging four cards out of four. This can be done in
4P4 = 24 ways. So we have 24 4-digits.
Hence, there
are
4P1 1-digit + 4P2 2-digit + 4P3 3-digit and 4P4 4-digit numbers that can be formed.
4P + 4P
2 + P3 + P4
4 4
1
= 4 + 12 + 24 + 24 = 64
34
Open University of Mauritius – Computational Mathematics
Permutation IV
Suppose that we have to arrange or permute such that some of the objects must
be together or “next to each other’’. We shall use the grouping method which
consists of putting all the objects that must be together into one group and calling
that group ‘X’ where X is considered as one object only.
Example
We saw that the total number of arrangements of all the letters in the word
FRANCE was
6! = 720. In how many of these 720 arrangements, the letters F, R, and C are
together?
F R A N C E
F R C
A N E
Hence out of the 720 arrangements, there are 144 arrangements in which F, R and
C are together. This also means that there are 720 – 144 = 576 arrangements in
which F, R and C are not together.
Note when F, R C are not together then this means that they can be completely
separated from each other (we shall use the Arrow method to find in how many
arrangements they are completely separated) or two of them are together and one
is separate.
F, R, C together
F R C
Grouping method : 144
F, R, C are completely
F R C
separated from each
other: use Arrow method
35
Open University of Mauritius – Computational Mathematics
Example
In how many arrangements of the letters in the word MAURITIUS, the letters
M, U, Uand R are together?
Solution
M A U R I T I U S
M U U R
A I T I S
4! 12 360 = 4320
= 12 ways
2!
The arrow method is used when we would like the objects to be completely
separated from each other.
Example
We saw that there are 6! = 720 arrangements of all the letters in the word
FRANCE. In how many of these arrangements, the letters F, R and C are
completely separated from each other?
Solution
Since the constraint is on letters F, R and C, let us arrange the remaining letters
(A, N, E) with a blank in between them, one at the beginning and one at the
end.
–A–N–E
–
36
Open University of Mauritius – Computational Mathematics
Step 2 There are 4 slots (shown by the arrows) where we can fit the first
letter out of the 3 (F, R, C)
–A– N– E–
Step 3 Consequently, 3 slots shall remain for the second letter and only 2 slots
for the third letter.
Example
Solution
Step 1 – A – B – C – D – E –
ABCDE can be arranged in 5! = 120 ways.
Step 2 The first of the 3 reports (X, Y, Z) can be inserted in any one of the six
slots (shown by the arrows)
–A– B– C– D– E–
Step 4 The third can be inserted in any one of the remaining 4 slots.
37
Open University of Mauritius – Computational Mathematics
Permutation VI: Box Method
Example
We saw that there are 720 arrangements of all the letters in the word
FRANCE. (a) How many of these start with letter R?
(b) How many of these start with letter R and end in letter A?
Solution
1 5
R F
A
N
C
E
Suppose we choose ‘F’ to fill this second position, we are left with A, N,
C, E for the third position. (So 4 choices for the third position)
1 5 4
R F A
A N
N C
C E
E
38
Open University of Mauritius – Computational Mathematics
If we continue in this way, there shall be 3 choices for the fourth position (N, C, E), 2 choices for
the fifth position (C, E) and 1 letter E will be used to fill the last position:
1 5 4 3 2 1
R F A N C E
A N C E
N C E
C E
E
(b) Since, we want arrangements starting with R and ending in A , we will draw 6
boxes. As we can fill the first position with ‘R’ only, there is only 1 way to fill the
first position. As we can fill the last position with ‘A’ only, there is only one way
to fill the last position.
1 1
R A
We are left with F, N, C, E for the second position M, C, E for 3rd position, C, E
for 4th position and E for the 5th position.
1 4 3 2 1 1
R F N C E A
N C E
C E
E
1 4 3 2 1 1 = 24
39
Open University of Mauritius – Computational Mathematics
Example
Suppose that you have six cards numbered 1, 2, 3, 4, 5 and 6. How many 4-digit
even numbers greater than 3000 can you form?
Solution
Since, we have 4-digit numbers, we will draw 4 boxes. Since, the 4-digit numbers
have to be greater than 3000, they can’t start with ‘1’ or ‘2’. They can only start
with 3, 4, 5 or 6. So we have 4 choices when filling the first position. Now since
the numbers have to be even, they must end in 2, 4 or 6.
3 2
4 4
5 6
6
So here it is preferable to work with the shorter list. So we will do it in 3 steps.
We shall find all those ending in ‘2’.
4 4 3 1 = 48
3 1 4 2
4 4 5
5 5 6
6 6
So there are 48 4-digit even numbers ending in ‘2’. Similarly, let’s find the 4-
digit even numbers ending in ‘4’.
3 4 3 1 = 36
3 1 2 4
5 2 5
6 5 6
6
So there are 36 4-digit even numbers ending in ‘4’. Finally, let’s find the 4-digit
numbers ending in ‘6’.
3 4 3 1
3 1 2 6
4 2 4
5 4 5
5
3 4 3 1 = 36
Hence, there are 36 4-digit even numbers that end in 6. Therefore, the total
number of even 4-digit numbers that are greater than 3000
48 36 36
= + +
(ending in ‘2’) (ending in 4) (ending with ‘6’)
= 120.
40
Open University of Mauritius – Computational Mathematics
3.5 Combination
Suppose that you have 3 fruits, Apple (A), Banana (B) and a citrus fruit (C). If you
have to use all the 3 fruits, how many different juices can you make? Only one!
When you are drinking the juice would you know in which order the fruits have
been put into the juicer? No.
Thus, if we have n objects, and we would like to combine all of them, then there
is only one combination that we can have. In combination the order does not
matter. This is indeed a major difference between permutation and combination.
Suppose that we decide to use only two fruits out of the three (A, B, C) to prepare
a juice. How many different juices can you make? Three. You can use A and B
or A and C or B and C.
Example
How many different juices can be made using two of the three fruits A, B and C?
3 different fruits 3
C2 = 3
How many different lotto combinations can you have if you have to choose 6
numbers out of 40?
Answer
40
C 6 = 38 383 80
Example
Suppose that there are ten members in a club. A team of 3 persons must be
selected to form the management team of the club.
(a) How many different management teams can be formed?
Solution
10
C3 = 120
(b) How many different ways are there to elect a President, a Secretary and a
Treasurer to form a management team?
Solution
10
C3 3! = 10
P3
Select 3 persons In general,
out of 10
41
Open University of Mauritius – Computational Mathematics
A range the 3 persons as President,
r Secretary and Treasurer
Cr r! = P r
n n
42
Suppose that a club has ten members: 6 males and 4 females. A team of 4 persons must
be selected to represent the team. How many different teams can be formed if
(a) There is no restriction?
Solution
10
C4
C
6 4
C
Chosen 2 2 2 2 = 90
4 females 6 males
4 6
1 3 C1 C3 = 80
4 6
or 2 2 C2 C2 = 90
4 6 24
or 3 1 C3 C1 =
4 6
or 4 0 C4 C0 = 1
195
(d) One of the males was John and one of the female was Mary. John and Mary don’t
get along. A team of 2 males and 2 females must be selected. How many different
teams can be formed with either John or Mary but not both?
Solution
We will solve this in two steps.
Step1 Let’s find those teams in which John is included. This means we need
to select one more male among the five (6 males minus John) and this
can be done in 5C1 = 5 ways.
Step 2 Let’s find the number of teams in which Mary is included but John is
excluded. So we need to find one more female from the three remaining
(4 females minus Mary) and this can be done in 3C1 = 3 ways.
We need to select two males from five (6 males minus John) and this
43
Open University of Mauritius – Computational Mathematics
5
can be done in C2 = 10 ways.
= 3 10 = 30
Hence, total number of teams in which either John or Mary are included
but not both is 15 + 30 = 45.
44
How many permutations containing 3 letters can you have if the letters are taken from
the word PRETTY?
Solution
PRETTY has 6 letters in total. As we would like to have arrangements of 3 letters, there
is a tendency to use 6P3 = 120. This is wrong because all the 6 letters are not different as
‘T’ appears twice. For this problem, we shall proceed in the following steps.
Note when we remove the 2 ‘T’ from the word PRETTY we are left with PREY.
Step 1 Let’s find those arrangements that don’t contain any ‘T’. This means we need
to choose 3 letters from PREY and then arrange the 3. This can be done in
C3 3! = 4 6 = 24
4
Step 2 Let’s find those arrangements that contain one letter ‘T’. This means we need
to choose 2 more letters from PREY before arranging all the 3. This can be
done in C2 3! = 6 6 = 36
4
Step 3 Let’s find those arrangements with 2 ‘T’. This means that we need to select
only one letter from PREY and arrange them. We can do this in
3!
C 1 = 4 3 = 12
4
2!
45
Open University of Mauritius – Computational Mathematics
3.6 Activities
1. Issam has 11 different CDs, of which 6 are pop music, 3 are jazz and 2 are
classical.
(i) How many different arrangements of all 11 CDs on a shelf are there if the
jazz CDs are all next to each other?
(ii) Issam makes a selection of 2 pop music CDs, 2 jazz CDs and 1 classical
CD. How many different possible selections can be made?
3. A builder is planning to build 12 houses along one side of a road. He will build 2
houses in style A, 2 houses in style B, 3 houses in style C, 4 houses in style D and
1 house in style E.
(i) Find the number of possible arrangements of these 12 houses.
(i)
Road
The 12 houses will be in two groups of 6 (see diagram). Find the number of
possible arrangements if all the houses in styles A and D are in the first
group and all the houses in style B, C and E are in the second group.
iii) Four of the 12 houses will be selected for a survey. Exactly one house must
be in style B and exactly one house in style C. Find the number of ways in
which these four houses can be selected.
6. A committee of 6 people, which must contain at least 4 men and at least 1 woman,
is to be chosen from 10 men and 9 women.
(i) Find the number of possible committees that can be chosen.
(ii) Find the probability that one particular man, Albert, and one particular
woman, Tracey, are both on the committee.
46
Open University of Mauritius – Computational Mathematics
(iii) Find the number of possible committees that include either Albert or Tracey
but not both.
(iv) The committee that is chosen consists of 4 men and 2 women. They queue
up randomly in a line for refreshments. Find the probability that the women
are not next to each other in the queue.
7. Eight men travel in two four-seater cars. In how many ways can the men be
allocated to the cars
(a) if all eight can drive;
(b) if only two can drive? (The same four men in a car count as one way no
matter in what positions the men are sitting).
8. In how many different ways can the letters of the word SALOON be arranged
(a) if the two O’s must not come together,
(b) if the consonants and vowels must occupy alternate places?
9. Calculate the number of 5-figure even numbers containing each of the digits 1, 3,
4, 7 and 8.
10. In how many ways can the letters of the word HORROR be arranged? In how
many of these arrangements are the vowels separated?
11. Seven cards, each bearing a letter, can be arranged to spell the word DOUBLES.
How many three-letter code-words can be formed from these cards? How many
of these words:
(a) contain the letter S,
(b) do not contain the leter O,
(c) consist of a vowel between two consonants?
12. A committee consisting of 2 men and 2 women is to be chosen from 5 men and 6
women. In how many ways can this be done?
One of the women is the wife of one of the men. In how many ways can the
committee be chosen if it must contain either the man and his wife, or neither?
13. The digits 1, 2, 3, 4, 5 are written down at random to form a five digit number.
Find:
(a) how many such numbers are possible,
(b) the chance that the last digit is odd,
(c) how many of the numbers are divisible by 4.
14. How many different 6-digit numbers can be made using the digits 1, 2 and 3 each
and the digit 4 three times?
How many of these numbers are odd? How many of these odd numbers have the
three 4’s together?
15. A committee of 6 is to be selected form 5 men and 4 women. Calculate the number
of different possible committees if:
(i) there is no restriction,
(ii) the number of men must be greater that the number of women.
16. A group of 12 cricketers is to be selected for a tour. The final selection is made by
choosing 6 batsmen out of 9, 4 bowlers out of 6 and 2 wicket-keepers out of 3.
Calculate the total number of different possible touring parties.
47
Open University of Mauritius – Computational Mathematics
17. From a class of 6 boys and 4 girls, a group of 3 children is to be selected. Calculate:
(i) the total number of possible groups,
(ii) the number of possible groups if at least one member of each group is to be
a boy.
18. Find the number of ways in which 4 questions can be chosen from 7 questions in
Section II of an examination paper, assuming that the order in which the questions
are chosen is not relevant.
19. A committee of 5 people is to be chosen from 6 men and 4 women. In how many
ways can this be done
(i) if there must be 3 men and 2 women on the committee,
(ii) if there must be more men than women on the committee,
(iii) if there must be 3 men and 2 women, and one particular women refuses to
be on the committee with one particular man?
20. A collection of 18 books contains one Harry Potter book. Linda is going to choose
6 of these books to take on holiday.
(i) In how many ways can she choose the 6 books?
(ii) How many of these choices will include the Harry Potter book?
21. A school is asked to send a delegation of six pupils selected from six badminton
players, six tennis players and five squash players. No pupil plays more than one
game. The delegation is to consist of at least one, and not more than three, players
drawn from each sport. Giving full details of your working, find the number of
ways in which the delegation can be selected.
22. Geoff wishes to plant 25 flowers in a flower-bed. He can choose from 15 different
geraniums, 10 different roses and 8 different lilies. He wants to have at least 11
geraniums and also to have the same number of roses and lilies. Find the number
of different selections of flowers he can make.
23. In how many ways can a group of 14 people eating at the restaurant be divided
between three tables seating 5, 5 and 4?
24. A football team consists of 3 players who play in a defence position, 3 players
who play in a midfield position and 5 players who play in a forward position.
Three players are chosen to collect a gold medal for the team. Find in how many
ways this can be done
(i) if the captain, who is a midfield player, must be included, together with one
defence and one forward player.
(ii) if exactly one forward player must be included, together with any two others.
25. (a) Calculate the number of different 6-digit numbers which can be formed
using the digits 0, 1, 2, 3, 4, 5 without repetition and assuming that a number
cannot begin with 0.
(b) A committee of 4 people is to be chosen from 4 women and 5 men. The
committee must contain at least 1 women. Calculate the number of different
committees that can be formed.
26. (a) The producer of a play requires a total cast of 5, of which 3 are actors and
2 are actresses. He auditions 5 actors and 4 actresses for the cast. Find the
total number of ways in which the cast can be obtained.
(b) Find how many different 4-digit odd numbers less than 4000 can be made
from the digits 1, 2, 3, 4, 5, 6, 7 if no digit may be repeated.
48
Open University of Mauritius – Computational Mathematics
27. (i) Find the number of different arrangements of the letters of the word
MEXICO.
Find the number of these arrangements
(ii) which begin with M,
(iii) which have the letter X at one end and the letter C at the other end.
Four of the letters of the word MEXICO are selected at random. Find the number
of different combinations if
(iv) there is no restriction on the letters selected,
(v) the letter M must be selected.
28. A garden centre sells 10 different varieties of rose bush. A gardener wishes to buy
6 rose bushes, all of different varieties.
(i) Calculate the number of ways she can make her selction.
Of the 10 varieties, 3 are pink, 5 are red and 2 are yellow. Calculate the number
of ways in which her selection of 6 rose bushes could contain
(ii) no pink rose bush,
(iii) at least one rose bush of each colour.
30. (a) Find the number of different arrangements of the 9 letters of the word
SINGAPORE in which S does not occur as the first letter.
(b) 3 students are selected to form a chess team from a group of 5 girls and 3
boys. Find the number of possible teams that can be selected in which there
are more girls than boys.
49
Open University of Mauritius – Computational Mathematics
Answers
15. (i) 84
(ii) 34
16. 3780
18. 35
50
Open University of Mauritius – Computational Mathematics
4
UNIT
Probability Distributions
3
UNIT STRUCTURE
1 4.1
4.2
4.3
Introduction
Learning Outcomes
Discrete v/s Continuous
4.4 Probability Distribution for Discrete Random Variables
4.5 Activities
4.6 Norma Probability Distribution
4.1 Introduction
In this Unit, you will learn about probability distributions. The aim of
Unit 4 is to explain the conditions to use the probability distributions.
You will also learn how to apply the distributions to solve real life
problems.
51
Open University of Mauritius – Computational Mathematics
Suppose that a d.r.v. X can take the n values x1, x2, x3, . . . . . . , xn. Suppose that each
value has exactly the same chance to occur. Then X is said to have a discrete uniform
distribution.
x1 x2 xn
= n + n +......+ n
x12 x2 2 xn2
E(X2) = n + n + . . . . . . = n
Example
Since the die is fair, all of the six scores are equally likely.
Hence, f (x) = 1
6
Outcome
x 1 2 3 4 5 6
1 1 1 1 1 1
P(X = x) 6 6 6 6 6 6
E(X) = 1 6 + 2 6 + 3 6 + 4 6 + 5 6 + 6
1 1 1 1 1 1
6
21 7
= = = 3.5
6 2
+ 32 + 42 + 52 + 62
1 1 1 1 1 1 91
E(X2) = 12 + 22 =
6
6 6 6 6 6 6
52
Open University of Mauritius – Computational Mathematics
The Binomial Probability Distribution
Very often an outcome has only two possible outcomes. For example
(i) tossing a coin results into a Head or Tail
(ii) verifying an electronic chip results in either the chip being good or faulty
(iii) At the beginning of a Ludo game the outcomes can be split into two : as you
Such trials that have two possible outcomes are called Bernoulli trials. The two
outcomes are also referred to as the ‘Success” and “Failure”.
A Binomial experiment is obtained when we repeat the Bernoulli trials several times.
For example, we throw a fair die five times or we test 12 electronic chips. Clearly we are
interested in the number of successes obtained.
Consider throwing a fair die five times. Let us define success as obtaining a , failure
as obtaining { , , , , }.
Let us define X as number of success (i.e. number of ), in five trials. How many
can you obtain when you throw a die five times? 0, 1, 2, 3, 4, 5.
Then X = 0, 1, 2, 3, 4, 5.
p+ q=1
53
Open University of Mauritius – Computational Mathematics
Suppose that we have n trials and
(i) the trials are independent
(ii) each trial has only two possible outcomes: success or failure
(iii) probability of obtaining a success in one trial, p, is same for all trials.
Var(X) = npq
Example
Solution
Here
success = a good chip
failure = a faulty chip
Probability of success, p = probability of a good chip
p = 75% = 0.75
probability of failure, q = 1 – p = 1 – 0.75 = 0.25
n = 12
Note instead of calculating these 12 probabilities, we can use the fact that
P(X = 0) + P(X = 1) + P(X = 2) + . . . . . . + P(x = 12) = = 1
= 2.25
= 1.5
For instance, number of faults reported in 5 hours; number of defects in 1m2 of cloth;
number of accidents in 3 weeks can be modelled by a Poisson distribution if events occur:
(i) randomly and independently;
(ii) “singly” in continuous space or time;
(iii) at a constant rate, in the sense that mean number of events occurring in an interval
is proportional to the length of the interval. For example, if the mean number of
calls received in one hour is 5 then mean number of calls received in two hours is
10.)
Let X = number of events occurring in a given interval, and = average or mean number
of events occurring in the interval. Then X can take value 0, 1, 2, 3, . . . . . up to
infinity.
−𝜆
𝜆𝑟
𝑃(𝑋 = 𝑟) = 𝑒 𝑟 = 0, 1, 2, 3, 4, ….
𝑟!
Example
Solution
Since X is defined for one day, we need to find mean, for one day :
= means number of faults reported in one day = 6
𝜆𝑟 60
𝑃(𝑋 = 0) = 𝑒 −𝜆 = 𝑒 −6 = 0.00248
𝑟! 0!
𝜆𝑟 61
𝑃(𝑋 = 1) = 𝑒 −𝜆 = 𝑒 −6 = 0.0149
𝑟! 1!
60 61
= e–6 + e–6 = 0.002479 + 0.0149
0! 1!
= 0.0174
(b) For one day, mean, = 6
For two days, mean, = 6 2 = 12
Y = no of faults reported on a two-day period
57
Open University of Mauritius – Computational Mathematics
The Poisson Probability Distribution Approximation to the
Binomial Probability Distribution
Example
The probability that an electronic chip is faulty is 0.01. Using a suitable approximation,
find the probability that in a randomly chosen set of 60 chips,
(a) none are faulty
(b) at least two are faulty
Solution
A chip can either be faulty or not. Among 60 chips, number of faulty chips can be 0, 1,
2, 3, . . . . . , 60
X ~ B(60, 0.01)
n = 60, p = 0.01
np = 60 0.01 = 0.6 5 and n = 60 50
X ~ Po (0.6)
0
–
(a) P (none are faulty) = P(X = 0) = e 0 !
= 1 – P(X = 0) – P(X = 1)
0 1
= 1 – e– 0 ! – e– 1 !
0.60 0.61
= 1 – e– 0 ! – e– 1 !
E.g X = 5 means first four trials were failures and the fifth trial results in a success.
State conditions under which a Poisson distribution can be used to give a good
approximation to a binomial distribution.
Packets of fruit gums contain 12 fruit gums altogether, and two flavours, orange and
lime are manufactured. The filling machine mixes the two flavours randomly in the
overall proportion of 2 oranges to 1 lime. Packets are regarded as acceptable provided
they contain at least 1 lime and at least 3 orange flavours. Calculate the probability that
a randomly chosen packet will not be acceptable.
The packets are delivered to shops in boxes of 200 packets. Use a Poisson distribution
to calculate the probability that a box will contain at least 2 unacceptable packets.
Solution
If X ~ B (n, p) and n is very large i.e. n 50, p is very small ( 0) such that np 5, the
Poisson distribution can be used as a good approximation to the Binomial distribution
by taking = np.
1
= (212 + 1 + 24 + 264)
312
4385
=
312
= 0.008251
= np
= 200(0.008251)
= 1.6502
P(W 2) = 1 – P(W 2)
= 1 – P(W = 0) – P(W = 1)
= 1 – e–1.6502 – 1.6502e–1.6502
= 0.4911
Example
At the ‘hot drinks’ counter in a cafeteria both tea and coffee are sold. The number of
cups of coffee sold per minute may be assumed to be a Poisson variable with mean 1.5,
and the number of cups of tea sold per minute may be assumed to be an independent
Poisson variable with mean 0.5.
(i) Calculate the probability that in a given one-minute period exactly one cup of tea
and one cup of coffee are sold.
(ii) Calculate the probability that in a given three-minute period fewer than 5 drinks
altogether are sold.
(iii) In a given one-minute period exactly three drinks are sold. Calculate the
probability that these are all cups of coffee.
Solution
Let X & Y be the number of cups of coffee and tea told per minute respectively.
Then X R Po (1.5) & Y R Po (0.5).
X + Y ~ Poisson (2)
23e–2
= 6
4 –2
= e
3
Required Probability
1.53 3
=
6 4
= 0.422
As part of its sale campaign for a new beauty preparation, a cosmetics manufacturer has
a counter in a large store at which each prospective customer is given a free 10-minute
individual session with a personal assistant to try the preparation. The store opens at
09 00. The first 10 minute session commences at 09 10 and, from then on, there are 50
sessions which run continuously throughout the day. It is estimated that the number of
customers arriving at the counter per hour has a Poisson distribution with a mean of 15.
Evaluate, to the nearest integer in each case, the expected number of 10-minute sessions
in the day during which 0, 1, 2, 3, more than 3, customers arrive at the counter.
Any assistant who has no customer waiting at the beginning of a 10-minute session is
allowed to have the whole of that session as a rest period. It is found that any customer
who would have to wait longer than the start of the next 10-minute session goes away,
that no customers buy the preparation without a trial, and that 50% of the customers who
do have a trial buy the preparation. The manufacturer makes a profit of £1.60 for each
sale and a loss on materials of £0.10 for every trial where no sale results. The daily wage
of an assistant is £20. Prove that, if the counter has two assistants, then the expected
daily profit is £21.50.
Find the expected daily profit if the counter has three assistants.
Solution
P(X 3) = 1 – P(X 3)
= £ 21.50
= 78.75 – 60
= £ 18.75
Example
(1 – p )8 (1 + 8p)
It is decided to modify the sampling scheme so that, when one defective is found in the
sample, a second sample of nine is taken and the batch rejected if this contains any
defectives. With this exception the original scheme is continued. Find an expression in
terms of p for the probability that a batch is accepted.
For this modified scheme evaluate the average number sampled per manufactured batch
over a large number of batches when p has the value 0.1.
Solution
Example
In a data transmission link between two computers, each character (ie letter, digit or
other symbol) is transmitted separately and there is a constant small probability that a
transmission error will occur; the mean failure rate is 1 error per ten million characters
transmitted.
(i) If 2 500 000 characters are transmitted, calculate the probability of no errors
occurring, and the probability of more than 2 errors occurring.
(ii) N characters of data are to be transmitted. Find and approximate value for the
maximum value of N such that the probability of no errors occurring is at least
0.999.
(iii) If an error occurs in transmitting a character, there is a probability p that it will be
discovered and corrected automatically. Prove that if N characters are transmitted
the probability of no errors finally remaining is e–(1 – p), where = N 10–7.
Solution
(i) Let X be the number of errors occurring in 2.5 million characters transmitted.
Then
1
N 10 000 000 ln p
0.999
N 10005.003
(iii) = N 10 – 7
P(no errors finally remaining)
= P(Y = 0) + P(Y = 1) + P2[P(Y = 2)] + . . . . . . PN[P(Y = N)]
(p)2 (p)N –
= e– + pe– + +
N!
e
2!
(p)2 (p)N
= e– (1 + (p) + +.....+
N!
2!
No. of group
0 1 2 3 4 5 6
wearing glasses(x)
No. of occurrences 17 53 65 45 18 2 0
Calculate the expected frequencies for a Poisson distribution having the same
mean number of goals per match.
3. Each week a security firm transports a large sum of money between two places.
The day on which the journey is made is varied at random, and in any week each
of the five days from Monday to Friday is equally likely to be chosen.
(i) Calculate the probability that, in a period of 10 weeks, Friday will be chosen
at least 3 times.
(ii) The event that, in a 4-week period, the same day is chosen on all four
occasions is denoted by S. Show that the probability of S occurring is 0.008.
Use an appropriate approximation to estimate the probability that, in one
hundred 4-week periods, the event S will occur at least 3 times.
7. A coin is biased in such a way that, on any throw, P(head) = p and P(tail) = q,
where p + q = 1. The random variable X denotes the number of heads resulting
from three throws of this coin. Tabulate the probability distribution of X, and show
from first principles (i.e without quoting any results relating to the binomial
distribution) and that E(X) = 3p and that Var(X) = 3pq.
In an experiment, three throws of the coin were repeated 1000 times. The numbers
of times each value of X occurred are shown in the table.
No. of heads 0 1 2 3
Calculate the mean number of heads from these figures, and use it to estimate the
value of p.
Hence, estimate the probability that five throws of this coin will result in at least
one head.
8. An advertising display contains a large number of light bulbs which are continually
being switched on and off. Individual lights fail at random times, and each day the
display is inspected and any failed lights are replaced. The number of lights that
fail in any one-day period has a Poisson distribution which mean
2.2. Calculate
(i) the probability that no light will need to be replaced on a particular day,
(ii) the probability that at least four lights will need to be replaced on a
particular day,
10. In a particular city, a person selected at random among those who have heard a
rumour has a probability of 0.75 of believing the rumour. Find the probability that
(a) the eight person to hear the rumour will be fifth to believe it
(b) the fifteenth person to hear the rumour will be the tenth person to believe it.
11 Stephen shoots at a target. The probability that he misses the target is 5%. Find
the probability that he will miss the target for the second time on the fifteenth shot.
12. At a factory, electronic toys are packed in boxes containing 18 toys each. An
inspector will accept the box if two randomly chosen toys from the box are not
defective; otherwise the entire box is inspected. What is the probability that a
randomly chosen box will be accepted without further inspection if the box
contains
(i) Four defective toys;
(ii) Eight defective toys;
(iii) Twelve defective toys.
13. In a construction firm, there are 240 male and 60 female employees. Six employees
are chosen at random to represent the firm. Find the probability that four of the six
will be males.
Answers
11. 0.0180
13. 0.2478
x
is the mean of X
is the standard deviation of X.
It is important that you note that
(i) the distribution is symmetrical about mean
(ii) mode = mean = median =
(iii) the bell-shape shows that there is a concentration of values around the mean
and there are fewer and fewer observations as the distribution moves away from
the mean.
(iv) the total area under curve is one.
f (x)
(v)
x
a b
Shaded area = P(a x b)
= P(a x b) = P(a x b)
= P(a x b)
Z ~ N (0, 12)
Then Z = (X -
x
Z=a
Shaded area
= P(Z a) = P(Z a) = (a)
P(Z a) = (a)
P(Z a) = 1 – (a)
P(a Z b) = P(a Z b)
= P(a Z b) = P(a Z b)
= (b) – (a)
The statistical table (The normal distribution) called the standard normal curve has two
columns : Z and (z).
x
a
70
Open University of Mauritius – Computational Mathematics
Example
Example
The time taken to complete the production of a toy at a certain factory follows a normal
distribution with mean 56 minutes and standard deviation 10 minutes. Find the
probability that the time taken to complete a randomly chosen toy is
(i) more than 68 minutes
(ii) between 56 and 65 minutes
Solution
Step 1 Identify the variable that follows a normal distribution and denote it by X.
So here, X = time taken to complete the production of a toy
P( X 68 )
= P(X 68)
68 – 56
= P(Z ) p= P(Z 1.2)
10
1.20 0.8849
Hence P(Z 1.2) = 1 – (1.2)
=1 – 0.8849 = 0.1151
So there are 11.51% chances that it takes more than 68 minutes to produce a
toy.
= P(56 X 65)
56−𝑚𝑒𝑎𝑛 65−𝑚𝑒𝑎𝑛
= P(𝑆𝑡𝑑.𝑑𝑒𝑣𝑖𝑎𝑡𝑖𝑜𝑛 < 𝑍 < )
𝑆𝑡𝑑.𝑑𝑒𝑣𝑖𝑎𝑡𝑖𝑜𝑛
56−56 65−56
= P( <𝑍< )
10 10
= P(0 Z 0.9)
= (0.9) – (0)
Example
The random variable X is normally distributed with mean and variance 2. Given that
P(X 58.39) = 0.0217 and P(X 41.82) = 0.0287, find and .
58.39 –
= –1(0.9783)
use table
58.39 –
= 2.02
72
Open University of Mauritius – Computational Mathematics
41.82 –
= –1 (0.0287)
–1(a) = – –1(1 – a)
if a is less than 0.5
= ––1(1 – 0.0287)
= – –1 (0.9713)
41.82 –
= – 1.90
58.89 – = 2.02
–
41.82 – = – 1.90
16.57 = 3.92
16.57
= = 4.227
3.92
Suppose that in a village 100 people are selected at random. In this village 20% of the
people are known to be left-handed. Find the probability that there will be at least 30
left-handed in the random sample of 100 villagers.
If we define X as the number of people who are left-handed among the 100, then
probability of obtaining at least 30 people who are left-handed is written as P(X
30), where X ~ B(100, 20%).
X R B(n, p)
np 5
nq 5
X R N(np, npq)
after
1
P(X a) P(X a + )
continuity 2
correction 1
P(X a) P(X a – )
2
1
P(X a) P(X a – )
2
1
P(X a) P(X a + )
2
In a village, 20% of people are left-handed. Find the probability that there will be at least
30 left-handed in a random sample of 100 villagers.
Solution
np = 100 0.2 = 20 5
np = 100 0.8 = 80 5
P(X 29.5)
29.5 – mean
= P( Z )
Std. deviation
= P(Z 2.375)
= 1 – (2.3745)
(2.375) = 0.9912
If 30% of biscuits produced by a factory is known to contain peanuts, find the probability
that in a random sample of 100 biscuits, there will be 33 or more but less than 37 biscuits
containing peanuts.
Solution
np = 100 0.3 = 30 5
np = 100 0.7 = 70 5
continuity correction
standardize
= P (0.55 Z 1.42)
= (1.42) – (0.55)
= 0.9222 – 0.7088
= 0.2134
X ~ Po()
15
X ~ N( , )
Example
At certain factory, machine breakdowns occur at an average of 3 per day. Assuming that
breakdowns occur at a constant rate, randomly in time and independently of one another,
calculate the probability that in a seven-day week, more than 27 breakdowns occur.
Solution
Therefore, X ~ Po(21)
= 21 15
continuity correction
= P(X 27.5)
P = P(Z 1.42)
=1 – Φ (1.42)
= 1 – 0.9222
= 0.0778
A company hires out cars on a daily basis. The mean number of cars hired per day is 20.
Using the normal approximation, find
(a) the probability that
(i) less than 5 cars will be hired
(ii) exactly 20 cars will be hired
(b) on how many days the company will have to turn customers away?
Solution
= 20 15
= P(Z – 3.466)
= ( – 3.466)
= 1 – (3.466)
use interpolation
(3.466) = 0.999766
= P(–0.1118 Z 0.1118)
= (0.1118) – (–0.1118)
= 1 – (0.1118)
= 2 (0.1118) –1
(0.1118) = 0.5445
Φ (z) is the integral of the standardized normal distribution from - ∞ to z (in other
words, the area under the curve to the left of z). It gives the probability of a normal
random variable not being more than z standard deviations above its mean.
Values of z of particular importance:
z Φ (z)
1.645 0.9500 Lower limit of right 5% tail
1.960 0.9750 Lower limit of right 2.5% tail
2.326 0.9900 Lower limit of right 1% tail
2.576 0.9950 Lower limit of right 0.5% tail
3.090 0.9990 Lower limit of right 0.1% tail
3.291 0.9995 Lower limit of right 0.05% tail
z 0.00 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 0.09
0.0 0.5000 0.5040 0.5080 0.5120 0.5160 0.5199 0.5239 0.5279 0.5319 0.5359
0.1 0.5398 0.5438 0.5478 0.5517 0.5557 0.5596 0.5636 0.5675 0.5714 0.5753
0.2 0.5793 0.5832 0.5871 0.5910 0.5948 0.5987 0.6026 0.6064 0.6103 0.6141
0.3 0.6179 0.6217 0.6255 0.6293 0.6331 0.6368 0.6406 0.6443 0.6480 0.6517
0.4 0.6554 0.6591 0.6628 0.6664 0.6700 0.6736 0.6772 0.6808 0.6844 0.6879
0.5 0.6915 0.6950 0.6985 0.7019 0.7054 0.7088 0.7123 0.7157 0.7190 0.7224
0.6 0.7257 0.7291 0.7324 0.7357 0.7389 0.7422 0.7454 0.7486 0.7517 0.7549
0.7 0.7580 0.7611 0.7642 0.7673 0.7704 0.7734 0.7764 0.7794 0.7823 0.7852
0.8 0.7881 0.7910 0.7939 0.7967 0.7995 0.8023 0.8051 0.8078 0.8106 0.8133
0.9 0.8159 0.8186 0.8212 0.8238 0.8264 0.8289 0.8315 0.8340 0.8365 0.8389
1.0 0.8413 0.8438 0.8461 0.8485 0.8508 0.8531 0.8554 0.8577 0.8599 0.8621
1.1 0.8643 0.8665 0.8686 0.8708 0.8729 0.8749 0.8770 0.8790 0.8810 0.8830
1.2 0.8849 0.8869 0.8888 0.8907 0.8925 0.8944 0.8962 0.8980 0.8997 0.9015
1.3 0.9032 0.9049 0.9066 0.9082 0.9099 0.9115 0.9131 0.9147 0.9162 0.9177
1.4 0.9192 0.9207 0.9222 0.9236 0.9251 0.9265 0.9279 0.9292 0.9306 0.9319
1.5 0.9332 0.9345 0.9357 0.9370 0.9382 0.9394 0.9406 0.9418 0.9429 0.9441
1.6 0.9452 0.9463 0.9474 0.9484 0.9495 0.9505 0.9515 0.9525 0.9535 0.9545
1.7 0.9554 0.9564 0.9573 0.9582 0.9591 0.9599 0.9608 0.9616 0.9625 0.9633
1.8 0.9641 0.9649 0.9656 0.9664 0.9671 0.9678 0.9686 0.9693 0.9699 0.9706
1.9 0.9713 0.9719 0.9726 0.9732 0.9738 0.9744 0.9750 0.9756 0.9761 0.9767
2.0 0.9772 0.9778 0.9783 0.9788 0.9793 0.9798 0.9803 0.9808 0.9812 0.9817
2.1 0.9821 0.9826 0.9830 0.9834 0.9838 0.9842 0.9846 0.9850 0.9854 0.9857
2.2 0.9861 0.9864 0.9868 0.9871 0.9875 0.9878 0.9881 0.9884 0.9887 0.9890
2.3 0.9893 0.9896 0.9898 0.9901 0.9904 0.9906 0.9909 0.9911 0.9913 0.9916
2.4 0.9918 0.9920 0.9922 0.9925 0.9927 0.9929 0.9931 0.9932 0.9934 0.9936
2.5 0.9938 0.9940 0.9941 0.9943 0.9945 0.9946 0.9948 0.9949 0.9951 0.9952
2.6 0.9953 0.9955 0.9956 0.9957 0.9959 0.9960 0.9961 0.9962 0.9963 0.9964
2.7 0.9965 0.9966 0.9967 0.9968 0.9969 0.9970 0.9971 0.9972 0.9973 0.9974
2.8 0.9974 0.9975 0.9976 0.9977 0.9977 0.9978 0.9979 0.9979 0.9980 0.9981
2.9 0.9981 0.9982 0.9982 0.9983 0.9984 0.9984 0.9985 0.9985 0.9986 0.9986
3.0 0.9987 0.9987 0.9987 0.9988 0.9988 0.9989 0.9989 0.9989 0.9990 0.9990
3.1 0.9990 0.9991 0.9991 0.9991 0.9992 0.9992 0.9992 0.9992 0.9993 0.9993
3.2 0.9993 0.9993 0.9994 0.9994 0.9994 0.9994 0.9994 0.9995 0.9995 0.9995
3.3 0.9995 0.9995 0.9995 0.9996 0.9996 0.9996 0.9996 0.9996 0.9996 0.9997
3.4 0.9997 0.9997 0.9997 0.9997 0.9997 0.9997 0.9997 0.9997 0.9997 0.9998
3.5 0.9998 0.9998 0.9998 0.9998 0.9998 0.9998 0.9998 0.9998 0.9998 0.9998
3.6 0.9998 0.9998 0.9999
2
UNIT STRUCTURE
1 5.1
5.2
5.3
Introduction
Learning Outcomes
Correlation
5.4 Activity 1
5.5 Regression
5.6 Activity 2
5.1 Introduction
In this Unit, you will learn how to establish relationship between variables. Moreover,
we you will learn how to develop regression models.
5.3 Correlation
Very often we hear people talking about correlation between two variables. For example, there is a
positive correlation between IQ of a person and the marks that the person obtains for an exam
(this means persons with higher IQ tend to score higher marks and people with lower IQ tend to
score lower marks); there is a negative correlation between savings and expenditure (this means the
more you spend, the less you will be able to save). In statistics we use correlation to denote
association between two quantitative variables that have a linear relationship such that one variable
increases or decreases by a fixed amount for a unit increase or decrease in the other. When one
variable increases as the other increases the correlation is positive; when one decreases as the
other increases it is negative. Complete absence of correlation is represented by zero. It is
important to note that we can’t deduce any cause and effect relationship from correlation.
If we use the letters X and Y to represent the two variables (e.g. IQ = X and Exam marks = Y),
then for every person we shall have a pair of values (x = IQ of person, y = exam marks of the
person). When we plot the coordinates (x, y) for all the persons, the diagram obtained is called a
scatter diagram. We plot the X-scores on the x-axis and Y-scores on the y-axis. A single dot
represents the data of one person.
The scatter diagrams give an idea about the correlation as shown in the diagrams below.
Open University of Mauritius – Computational Mathematics
81
y y y
x x x
(a) Positive correlation (b) Strong positive (c) Perfect positive
between x and y correlation correlation between
between x and y x and y
y y y
x x x
(d) Negative correlation (e) Strong negative (f) Perfect negative
between x and y correlation between x correlation between x
and y and y
x x
(g) No correlation (h) Non linear relationship
between x and y between x and y
Correlation Coefficient
On top of the scatter diagram, we can also mathematically compute the degree of
linear association between two variables; this measure of correlation is called the
correlation coefficient. Such coefficients measure the strength of the correlation.
The coefficient is also a good indicator of whether the correlation is strong or
weak. The value of these coefficients usually ranges from -1.00 to +1.00. A
positive coefficient indicates that two variables systematically vary in the same
direction: as one variable increases, the other variable tends to increase. The
closer the coefficient is to +1.00, the stronger is the positive association. A
negative coefficient indicates that two variables systematically vary in opposite
directions: as one variable increases, the other variable tends to decrease. The closer
the coefficient is to -1.00, the stronger is the negative association. A coefficient
close to zero indicates that no systematic co-variation exists between the two
variables. There are different correlation coefficients that have been developed.
They apply to different data types and conditions.
First assumption:
The two variables should be measured at the interval or ratio level (i.e., they are
continuous). Examples of such variables include time taken to complete a task
(measured in minutes), intelligence (measured using IQ score), exam
performance (measured from 0 to 100), and weight (measured in kg). Variables
like gender (male or female), and type of banks are neither interval nor ratio
variables.
Second assumption:
There must be a linear relationship between the two variables. Scatter diagrams
can help to visually check for linearity. If the relationship displayed on the scatter
diagram is not linear, then it is recommended to run a non-parametric equivalent
to Pearson’s correlation or transform the data (one example of transformation
would be the use logarithm; for instance, one may decide to plot lnx against xy
instead of x against y in order to obtain a linear relationship).
Open University of Mauritius – Computational Mathematics
83
Third assumption:
There should be no significant outliers. Outliers are simply single data points within
your data that do not follow the usual pattern (they are often extremely large values or
extremely small values). The following scatter diagrams highlight the potential impact
of outliers:
r = 0.4 r = 0.7
The presence of outlier produces a lower coefficient of r = 0.4 as the outlier tends
to bend the line (called the line of best fit). The removal of the outlier shows that
there is quite a strong correlation (r = 0.7) between the variables. This shows
that Pearson’s correlation coefficient is sensitive to outliers, which can have a
very large effect on the line of best fit and the value of the coefficient, leading to
very different conclusions regarding your data. Therefore, it is best if there are
no outliers or they are kept to a minimum. Box-and-whisker’s plot can be good
indicators of the presence or absence of outliers.
Fourth assumption:
The variables should be approximately normally distributed. In order to assess
the statistical significance of the Pearson correlation, you need to have bivariate
normality, but this assumption is difficult to assess, so a simpler method is more
commonly used. This is known as the Shapiro-Wilk test of normality. This
assumption is vital for small samples. It is considered to be robust for large
samples (that is 30 or more pairs of data). If the variables are not normally
distributed but take values that can be ranked (ordinal data) then we should use
non-parametric Spearman’s rho correlation coefficient. Kendall’s Tau is another
non-parametric correlation and it should be used rather than Spearman’s rho
when you have a small set of data with large number of tied ranks.
Cramer’s V and
Nominal Contingency
Coefficient**
Coefficient of Determination
The coefficient of determination is the square of the correlation coefficient (r2).
r2 quantifies the proportion of the variance of one variable “explained” (in a
statistical sense, not a causal sense) by the other.
For example, if r =0.9, then r2 = 0.81. r2 = 0.81 = 81% indicate that 81% of the
variability in one variable is explained by the other.
n xy – xy
r=
[n(x2) – (x)2][n(y2) – (y)2]
where
n = sample size
xy = Multiply x by y and then sum all the products
Σx = Sum all the x scores
Σy = Sum all the y scores
Σx2 = Square each x and then sum
Σy2 = Square each y and then sum
(Σx)2 = Square the sum of all x
(Σy)2 = Square the sum of all y
Example
Suppose that we would like to calculate the correlation between the marks
obtained by 10 students in an English test and a Mathematics test. Calculate the
Pearson correlation coefficient and interpret it (assuming that all the assumptions
hold). The table below gives the marks obtained by the students.
Marks in
40 42 45 55 68 70 80 92 95 98
English
Marks in
60 64 71 76 83 85 89 90 91 93
Mathematics
Solution
n xy – xy
r=
[n(x2) – (x)2][n(y2) – (y)2]
10(57216) – (685)(802)
r= = 0.957
[10(51431) – (685)2][10(65578) – (802)2]
6d2
r=1–
n(n2 – 1)
where n is the number of pairs of ranks. d is the difference between the pair of
ranks.
Step 3 Calculate the difference in the ranks e.g. d1 = rank of first value of
X – rank of the first value of Y
Suppose that we would like to calculate the correlation between the marks
obtained by 7 students (represented by A, B, C, D, E, F and G) in an English test
and a Mathematics test. Calculate the Spearman correlation coefficient and
interpret it. The table below gives the marks obtained by the students.
Solution
89
Open University of Mauritius - Computational Mathematics
Step 2 Calculate the ranks of X and of Y (e.g. Student B who obtained 90 marks (the
highest mark) in English would be given a rank of 1 for English). Calculate
d and d2.
Note.
(1) Students A and E have both obtained 55 marks in the Mathematics test. So they
have the same ranks for Y: (4 + 5)/2 = 4.5.
Suppose that we have to compare a pair of observations (xi, yi) and (xj, yj). We refer to
the pair as being “concordant” if xi < xj if and only if yi < yj. Otherwise, the pair is
discordant.
Let C = total number of concordant pairs and Let D = total number of discordant pairs.
C–D 4C
Kendall’s tau, t = = – 1 –1 t 1
½n(n – 1) n(n – 1)
Example
2 Judges rank 8 pieces of artworks labelled as A, B, ..., H. Their ranks are given below:
Artwork A B C D E F G H
Solution
For the artwork A, first Judge gave rank = 1 and the second judge gave rank 3. We count
the number of ranks of second judge to the right that are greater than 3: there are 5 such
ranks.
For the artwork B, first Judge gave rank = 2 and the second judge gave rank 4. We count
the number of ranks of second judge to the right that are greater than 4: there are 4 such
ranks.
For the artwork C, first Judge gave rank = 3 and the second judge gave rank 1. We count
the number of ranks of second judge to the right that are greater than 1: there are 5 such
ranks.
For the artwork D, first Judge gave rank = 4 and the second judge gave rank 2. We count
the number of ranks of second judge to the right that are greater than 2: there are 4 such
ranks.
1. A random sample of 10 children was timed in the task of writing the letters of the
alphabet first with their right hand and then with their left hand. Is there a
significant correlation between the two sets of times below? Use a 5% level of
significance and assume that the time to complete the task for ‘right hands’ and
for ‘left hands’ are both normally distributed.
Children 1 2 3 4 5 6 7 8 9 10
2. Ten pairs of identical twins have the following birth weights (kg):
1 2 3 4 5 6 7 8 9 10
Weight 1st born 3.95 3.41 3.73 4.13 3.48 4.28 3.98 4.18 4.04 3.73
(kg) 2nd born 3.93 3.35 3.72 4.18 3.44 4.15 3.89 4.20 4.00 3.72
3. The height (cm) and weight (kg) of 12 babies were recorded at the time of the
birth.
Height (x) 44 41 43 40 41 37 38 36 44 43 35 40
Weight (y) 3.5 2.8 3.2 2.7 2.9 2.5 2.8 2.6 3.6 2.6 2.4 2.9
Contestant
A B C D E F G H I J
Judge 1 10 13 8 7 3 4 15 6 17 18
Judge 2 5 4 6 5 7 8 3 7 2 2
Calculate Spearman’s rs and test the hypothesis that the marks of the judges are
uncorrelated against a suitable one-sided alternative.
5. From a large number of families living in a rural area each having a youngest child
aged between 5 and 7 years, a researcher selected a random sample of six families
and measured the IQ of the youngest child. The researcher also recorded the total
number of children in each family and drew up the following table:
The researcher calculated the value of Pearson’s r for these data to be – 0.875, and
concluded that the cause of lower IQ in larger families is a direct result of the
parents having to divide their attention between a larger number of children.
Answers
2. Choose 0.985 since scatter diagram indicates very high positive correlation.
3. (ii) r = 0.7927, t = 4.11, t0.025, 10 = 2.23. Correlation is significantly different from
zero.
(iii) x = 43 and y = 2.6 as it is lower on the scatter diagram.
4. rs = –0.2673; critical value of rs is 0.564; reject H0 and conclude that the rankings
are uncorrelated and accept H1 that high ranks of Judge 1 are associated with low
ranks of Judge 2.
5. rs = –0.7429
When we have several independent variables (i.e. the dependent variable is affected by
several independent variables), we obtain a multiple linear regression equation that we
can write as Y= b0 + b1X1 + b2X2.... + bkXk.
In this manual, we will deal with a simple regression equation (i.e. we will have only
one independent variable): Y = a + bX.
a and b would be calculated using data from random sample derived from the population.
Very often we refer to a simple regression model which we write with a random error
term : Y = + X + ; and are population parameters.
Except in the case when the correlation between X an Y is 1 or -1, all the points plotted
on the scatter diagram won’t lie on the line. Thus, for any point x that doesn’t lie on the
line, we shall have two values of y: one that lies on the line (called the estimated value
of y which we often denote by ŷ), and one from the point plotted on the scatter diagram
(called the observed value of y).
The difference between the observed and predicted value is referred to as the residual:
y - ŷ = e.
Observed value of Y = ŷ
Estimated value of Y = ŷ
obtained from the equation of
the regression line
Assumptions
It is assumed that e1, e2, e3, ......, en are independent. It is also assumed that each e is
normally distributed with mean zero and variance σ2.
It is assumed that there is a random sample of n pairs of observations, (X1 , Y1), (X2 ,
Y2), ..., (Xn , Yn)
For each value of X, the population of Ys have normal distribution with mean
µY = α + X.
The population of Y’s has a constant standard deviation (which is the same for every
value of X).
n xy – x y
Step 2 b =
n x2 – (x)2
x y
Step 3 x- = ;ӯ =
n
n
Step 4 a = ӯ – bx-
For a random sample of 10 students, the marks obtained in English (x) and marks
obtained in Mathematics (y) were recorded. Write the regression equation that can be
used to predict y. Predict value of y for x = 30.
x y
1 44
5 56
15 62
25 68
35 71
45 74
55 82
65 87
75 90
85 95
Solution
x y x2 y2 xy
1 44 1 1936 44
5 56 25 3136 280
15 62 225 3844 930
25 68 625 4624 1700
35 71 1225 5041 2485
45 74 2025 5476 3330
55 82 3025 6724 4510
65 87 4225 7569 5655
75 90 5625 8100 6750
85 95 7225 9025 8075
2 2
Σ x = 406 Σ y = 729 Σ x = 24226 Σ y =55475 Σ xy = 33759
n xy – x y 10(33759) – (406)(729)
b= = = 0.538
n x2 – (x)2 10(24226) – (406)2
x 406
x- = = = 40.6
n 10
y 729
ӯ = = = 72.9
Open University of Mauritius - Computational Mathematics
96
n 20
97
Open University of Mauritius - Computational Mathematics
a = ӯ – bx- = 72.9 – (0.538) (40.6) = 51.057
y = a + bx = 51.057 + 0.538x
We can interpret the coefficient of x as the rate of increase of y with respect to x is 0.538.
That is, for every unit increase in x, y increases by 0.538 unit.
Note that we can use the regression equation to forecast y for values of x in the range 1
to 85 as the regression equation may not be valid outside this range. X = 30 is within this
range.
n xy – xy
r=
[n(x2) – (x)2][n(y2) – (y)2]
10(33759) – (406)(729)
r= = 0.98
[10(24226) – (406)2] [10(55475) – (729)2]
R2 = 0.982 = 0.96=96%. This means that this regression model accounts for 96% of
variances in Y (i.e. 96% of variability in Y is explained by linear regression on X).
1. The following table shows the masses of a certain chemical substance which
dissolved in a given mass of water at various temperatures.
Tempetature(˚C) 10 20 30 40 50 60 70 80 90
Mass (g) 4.5 4.6 5.0 5.6 5.9 6.3 6.4 6.7 7.4
Plot a scatter diagram and calculate, to 3 significant figures, the coefficients of the
equation of the regression line. Plot the regression line on the scatter diagram and
verify that it passes through the point given by the mean values of temperature and
mass. Estimate mass for a temperature of 56˚C.
Speed (X km h–1) 1.5 2.0 3.2 4.3 5.5 6.6 8.4 8.8 9.7
Force (Y newtons) 96 95 109 112 122 133 138 156 154
3. A study was made of the amount of converted sugar in a certain process at various
temperatures. The coded data are as follows:
Find the least squares linear regression equation which could be used to predict
the amount of converted sugar given the temperature.
5. In an experiment to find the Young modulus for a brass wire the following 11 pairs
of values of x (suspended mass in kg) and y (length of wire in mm – 700 mm) are
obtained. The equation connecting x and y is assumed to take the form
y = x. Obtain the least squares estimates for and showing your working
clearly.
y = + x
(i) Determine the least squares estimate of the equation connecting x and y.
(ii) Estimate the mass of the chemical dissolved when the temperature is 60˚C.
Temperature (x˚C) 0 10 20 30 40 50
Mass (y grams) 51.3 51.4 51.9 52.0 52.6 52.8
Assuming that the true value of y is linearly related to the value of x, obtain the
least squares estimate of this relationship.
Employee 1 2 3 4 5 6 7 8 9
Aptitude score, x 9 17 20 19 20 23 16 24 22
Productivity, y 2 25 29 33 43 32 24 33 14
9. A random sample of five families had the following annual incomes and annual
savings in thousands of pounds.
Income 16 22 18 12 12
Savings 1.2 2.4 2.0 1.4 0.6
Draw a scatter diagram. Assuming both income and savings are measured with
negligible measuring error, calculate the coefficients of the equations of the
regression lines of (a) savings on income, (b) income on savings. Draw both lines
on the scatter diagram.
Also calculate Pearson’s r for these data and verify that the value of r2 is equal to
bb (the product of the regression coefficients of the two regression lines).
10. The ages, x years (given to one place of decimals), and heights, y cm (to the nearest
cm), of 10 boys were as follows:
x 6.6 6.8 6.9 7.5 7.8 8.2 10.1 11.4 12.8 13.5
y 119 112 116 123 122 123 135 151 141 141
Given that x2 = 899.80, y2 = 166,091, xy = 12,023.3, calculate the linear
correlation coefficient between x and y and comment upon the result.
Calculate the equation of the regression line of y on x, and use it to estimate the
height of a boy 9.0 years old.
State the value of y given by the regression line when x = 30 and comment upon
your answer.
4. y = 1.1 + 1.09x.
5. y = 1.998 + 0.9948x.
8. y = 7.059 + 1.309x; 20.1, 33.2, 46.3; (a) estimate for x = 20 most reliable,
being nearest centre of data; (b) estimate at x = 30 is least reliable, being
outside the range of data.
102
Open University of Mauritius - Computational Mathematics
UNIT Sets, Relation and
6 Functions
1UNIT
STRUCTURE
6.1 Introduction
6.2 Learning Outcomes
6.3 Sets
6.4 Set Rules
6.5 Activity 1
6.6 Relations
6.7 Activity 2
6.8 Functions
6.9 Activity 3
6.1 Introduction
In this Unit, you will be introduced to Sets. I am sure that you have been
dealing with Sets since primary schools. Thanks God, sets have not changed.
Sets are vital in computing.
6.3 Sets
A Set is a collection of objects that share at least one common characteristic. The objects in the
set are called elements of the set. Sets are usually given names such as Set A, Set B,…
Suppose that there is a Set A that contains even numbers between 1 and 7. It is common to use
curly-braces to write sets. We can write Set A in different ways including:
A = {even numbers between 1 and 7}
A = {2, 4, 6}
103
Open University of Mauritius - Computational Mathematics
Since there are three elements in Set A, we say that cardinal number of set A is 3 or
n(A) = 3. This can be used to write Set A as
It is A common to use the letter x to represent an element.
“:” is used 23 to mean “such that”. Hence we can also write Set A
as
A = { x: x is an even number between 1 and 7}
Z is used to represent the set of all integers. Z + is the set of all positive integers
and Z- is the set of all negative integers. Therefore the statement that m is an
integer can be written as m ∈ Z where ∈ means “is an element of”.
A = {x: x = 2m, m ∈ Z, 1 ≤ m ≤ 3}
Popular Sets
{ } or 𝜙 is called an empty set. This set does not have any element.
Set Notations
∈ means “is an element of ”. For 3 ∈ {1, 2, 3, 4, 5} but 6 ∉ {1, 2, 3, 4, 5}
104
Open University of Mauritius - Computational Mathematics
⊂ means “is a subset of ”. If A = {1,4}; B = {1,7}, C={1, 2, 3, 4, 5}.
A ⊂ C but B ⊄ C
∪ means “union”. Set A union B is written as A ∪ B is a set that contains elements found in
set A as well as those found in set B or those found in both in set A and B.
If A = {1, 2, 3, 4}, B = {1, 2, 5}, then A ∪ B = {1, 2, 3, 4, 5}
𝜉 is used to represent the universal set. This is the set that contains all the elements.
Complement of set A, that we will write as 𝐴̅ or 𝐴′ , is the set that contains elements from the
universal set that are not found in set A.
Set difference of A and B is written as A – B and contains elements of set A that are in set B.
If A = {1, 2, 3, 4}, B = {1, 2, 5}, then A - B = {3, 4} and B – A = {5}
Power set of A, which we write as pow (A), is the set of all subsets of set A. For example, if
A = {1, 2, 3}, pow(A) = {𝜙, {1}, {2}, {3}, {1, 2}, {1,3}, {2,3}, {1, 2, 3}}. There are 8 sets in
pow(A).
(vii) (a) A – B = A ∩ B′
(b) B – A = B ∩ A′
(c) A – B = A ⇔A ∩ B= Φ
(d) (A – B) ∪ B= A ∪ B
(e) (A – B) ∩ B = Φ
(f) A ∩ B ⊆ A and A ∩ B ⊆ B
(g) A ∪ (A ∩ B)= A
(h) A ∩ (A ∪ B)= A
(viii) (a) (A – B) ∪ (B – A) = (A ∪ B) – (A ∩ B)
(b) A ∩ (B – C) = (A ∩ B) – (A ∩ C)
(c) (A ∩ B) ∪ (A – B) = A
(d) A ∪ (B – A) = (A ∪ B)
(ix) (a) 𝜉 ′ = Φ
(b) Φ′ = 𝜉
(c) (A′ ) ′ = A
(d) A ∩ A′ = Φ
(e) A ∪ A′ = 𝜉
(f) A ⊆ B ⇔B′ ⊆ A′
Example
Prove A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C)
Solution
The strategy is to start by with an element x of the set on LHS and prove
that it also exist in the set on the RHS.
Let x ∈ 𝐴 ∩ (𝐵 ∪ 𝐶). This means x ∈ 𝐴 and x ∈ (𝐵 ∪ 𝐶) i.e. x must be in set
A and x must also be in the set B ∪ C. If x is in set B ∪ C then x must either
be in B only or in C only or in both B and C. If x is in B only then x must be
in A ∩ B; and if x is in C only then x must be in A ∩ C. Therefore, x will
either be in A ∩ B or in A ∩ C. Since x is in either A ∩ B or in A ∩ C, x
will be in the union of these two sets: x ∈ (A ∩ B) ∪(A ∩ C). Hence proved.
Example
Prove (A ∩ B) ′ = A′ ∪ B′
Solution
Let x ∈ (A ∩ B) ′. This means x is not in the set A ∩ B. This means x is in
either A or B but not both. If x is in A only then x must be in B′. If x is in B
only then x must be in A′. Therefore, x must either be in A′ or in B′. If x is
either in A′ or in B′, then it must be in A′ ∪ B′. Hence, (A ∩ B) ′ = A′ ∪ B′.
106
Open University of Mauritius - Computational Mathematics
6.5 Activity 1
Prove
(1) (A ∪ B) ′ = A ′ ∩ B ′
(2) A – (B ∩ C) = (A – B) ∩ (A- C)
(3) A – (B ∪ C) = (A – B) ∪ ( A – C)
6.6 Relations
Cartesian Product of Two Sets
Let A and B be two sets, then the Cartesian product of A and B is written as AxB. If x ∈ A and
y ∈ B, then AxB is the set of the ordered pairs (x,y).
For example, if A = {1, 2, 3} and B = {5, 6} then AxB = {(1,5), (2,5), (3,5), (1,6), (2,6), (3,6)}
AxB = {(5,1), (5,2), (5,3), (6,1), (6,2), (6,3)}
If there are p elements in set A and q elements in set B then there are p times q elements in set
AxB.
Relation
A relation, R, from non-empty set A to non-empty set B is defined as a subset of AxB.
The set contains all the first elements in the relation R is called the domain of the relation R.
The set of all the second elements in the relation R is called the range of the relation R.
For example if R = {(2, 5), (3, 10), (4, 17)}, then domain of R = {2, 3, 4} and range of R = {5,
10, 17}.
Properties of Relations
A relation, R, on non-empty set A is defined as a subset of A × A: R ⊆ A × A
For example, let A = {1, 2, 3} then Cartesian product A × A = {(1,1), (1,2), (1,3), (2,1), (2,2),
(2,3), (3,1), (3,2), (3,3)}.
A binary relation R ⊆ A × A is called:
Reflexive if and only if for all x ∈ A, (x, x) ∈ R
Symmetric if and only if for all x, y ∈ A, (x, y) ∈ R ⇒ (y, x) ∈ R. This means both (x, y)
and (y, x) must be present in R if R is symmetric.
Transitive if and only if for all x, y, z ∈ A, (x, y) ∈ R and (y, z) ∈ R ⇒ (x, z) ∈ R. This
means when (x, y) and (y, z) are present in R, then (x, z) must also be present in R if R is
transitive.
If a relation is reflexive, symmetric and transitive, then it is called an equivalence relation.
Example
R is a relation on Z+ (Z+ is the set of positive integers) such that ((a,b),(c,d)) ∈ R if and only
if ad = bc. For example, ((1,2),(2,4)) is an element of R as 1 x 4 = 2 x 2.
Prove that R is an equivalence relation.
Solution
Let’s prove that R is reflexive.
x = (a, b) where a and b are positive integers.
We have to prove that (x, x) in R if R is reflexive.
(x, x) = ((a, b), (a, b)) is included in R because ab = ba. Hence R is reflexive.
107
Open University of Mauritius - Computational Mathematics
Let’s prove that R is symmetric.
x = (a, b) and y = (c, d)
We have to prove that if (x, y) is in R then (y, x) is also in R.
Let (x, y) = ((a, b), (c, d)) be in R. This means ad = bc.
ad = bc means da = bc.
Let’s find if (x, y) is in R.
(x, y) = ((c, d), (a, b)) lies in R as cb = da. Hence R is symmetric.
6.7 Activity 2
Question 1
If R is an equivalence relation on the set A = {1, 2, 3, 4, 5} which is
defined as R = {(a, b): |a-b| is even}. Prove that R is an equivalence
relation.
Question 2
If R is an equivalence relation on the set Z+ which is defined as R = {((a,
b), (c, d)): a + d = b + c}. Prove that R is an equivalence relation.
6.8 Functions
A function, f, maps every element of a set called domain, A, onto elements
of a set called codomain, B. This is written as f: A If a ∈ A and b
∈ B and f(a) = b, the we say that the function f assigns element b of set B
to the element a of set A. b is referred to as the image and a is referred to
as the object.
It is important to note that
(1) the function f assigns an element of set B to every element of set A.
That is every object of domain must have an image in codomain;
(2) The function f assigns a unique element of set B to every element of
set A. This means an object in domain can’t have two images in
codomain;
(3) two different objects of the domain can have the same image;
(4) the set of images is called range of the function; and
(5) range of the function is a subset of the codomain of the function.
Example
For example there is a function f that “adds 5”. Its domain consists of
integers, A = {1, 2, 3, 4}. The codomain consists of integers 0 to 10
inclusive, B = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}.
(a) Find the range of the function f.
108
Open University of Mauritius - Computational Mathematics
(b) Write function f in different forms.
Solution
(a) Since set A is the domain, then, 1, 2, 3, and 4 are the objects of function f.
f(1) = 1 + 5 = 6. This means the image of object “1” is 6.
f(2) = 2 + 5 = 7. This means the image of object “2” is 7.
f(3) = 3 + 5 = 8. This means the image of object “3” is 8.
f(4) = 4 + 5 = 9. This means the image of object “4” is 9.
(b) one way to write the function is to start by taking a general element of the domain
that we can represent by x. Therefore, f maps x onto x + 5 as f adds 5 to x.
f (x) = x + 5, x ∈{1, 2, 3, 4}
Bijective Functions
A function is bijective if it is both injective and surjective. Bijective functions have an
inverse. The inverse of function f(x) is written as f-1(x).
To find f-1(x) proceed as follows:
Step 1. Let y = f(x)
Step 2. Make x the subject of formula.
Step 3. Replace x on the LHS by f-1 (x) and all y on RHS by x.
Example
f is a function from the set of Real numbers of to the set of Real numbers. f(x) = x + 2
(a) Prove that f(x) is an injective function
(b) Prove that f(x) is a surjective function
(c) Find f-1 (x)
Solution
109
Open University of Mauritius - Computational Mathematics
(a) f(x) = f(y) means x + 2 = y + 2. Solving it gives rise to x = y. Hence f(x) is injective
or one-to-one.
(b) Let f(x) = b. This means x + 2 = b. Solving this leads to x = b – 2 which
is a real number.
(c) Let f(x) = x + 2 = y. This means x = y – 2. Hence, f-1(x) = x – 2.
Composite Function
Suppose that f and g are two functions such that range of function g is a subset
of the domain of f(x), then the composite function f(g(x)) or fg(x) or f o g(x)
exists.
g(f(x)) exists if range of f(x) is a subset of the domain of g(x).
Example
Suppose that f and g are functions from the set of Real numbers to the set of
Real numbers. f: RR.
f(x) = x + 5 and g(x) = x2
We can have the composite functions:
fg(x) = x2 + 5
gf(x) = (x + 5)2
ff(x) = f2(x) = x +10
ffg(x) =f2g(x) = x2 + 10
fff (x) = f3(x) = x +15
f4(x) = x + 20
fn(x) = x + 5n
6.9 Activity 3
In the following questions, f and g are functions from set of real numbers to
the set of real numbers.
Question 1
f(x) = 2x – 1 and g(x) = x2 + 1
(a) Prove that f(x) is bijective and g(x) is not bijective.
(b) Find the composite functions (i) fg (ii) gf (iii) ff (iv) gg (v) ffg
Question 2
f(x) = x + 1 and g(x) = 3x - 1
(c) Prove that f(x) and g(x) are bijective.
(d) Find the composite functions (i) fg (ii) gf (iii) ff (iv) gg (v) ffg
110
Open University of Mauritius - Computational Mathematics
UNIT
Graph Theory
7
6UNIT
STRUCTURE
1 7.1
7.2
7.3
7.4
Introduction
Learning Outcomes
Graph
Eulerian Multigraphs
7.5 Hamiltonian Graphs
7.6 Distance in Graphs
7.7 Network Analysis
7.8 Activities
7.1 Introduction
In this Unit, you will be introduced to Graph Theory. This is important when
building networks.
7.3 Graph
Definition 1.
A graph is a finite, nonempty set V, called the vertex set, together with set E, called the edge set,
whose elements e∈E are pairs e = (a, b) with a, b ∈V. We also write G (V, E) to represent a
graph G with the set of vertices V and set of edges E.
Straight lines, arrows, arcs or loops can connect vertices.
A multigraph G(V,E) allows two vertices to be joined by more than one edge. Such edges are
called parallel edges.
Definition 2.
An undirected graph is one in which the edge set consists of unordered pairs. This means (a,
b) and (b, a) are same. Arrows are not used to connect vertices.
Definition 3.
111
Open University of Mauritius - Computational Mathematics
A directed graph or digraph is one in which the edge set consists of ordered pairs. This means
(a, b) and (b, a) are different. We use arrows to join the vertices. A directed edge e = (c, d)
appears as an arrow that starts at c and points towards d and ends at d.
Definition 5.
If the directed edge e = (u, v) is present in a directed graph G(V′,E′) then u is
referred to as a predecessor of v. v is referred to as a successor of u. u is also
called the tail or tail vertex of the edge (u, v), and v is called the tip or tip
vertex.
Complete graphs, Kn
The complete graph Kn is the undirected graph with n vertices whose edge set
includes every possible edge. If one numbers the vertices consecutively the
edge and vertex set are
V = {v1, v2, ..., vn}
E = {(vj , vk ) | 1 ≤ j ≤ (n − 1), (j + 1) ≤ k ≤ n} .
Number of edges = n(n-1)/2
K4 is the undirected graph has 4 vertices and (4)(4-1)/2 = 6 edges as shown
below
Path Graphs Pn
Pn has n vertices and (n-1) edges:
V = {v1, v2, ..., vn}
E = {(vj , vj+1) | 1 ≤ j ≤ n } .
112
Open University of Mauritius - Computational Mathematics
P5 has 5 vertices and (5-1) = 4 edges as shown below:
Example
C3 has 3 edges and 3 vertices:
Definition 6
A bipartite graph G(V,E) is a graph with a non-empty set of edge E and two
non-empty disjoint set of vertices V1 and V2 (so that V = V1 ∪ V2) such that
every edge e = (u, v) connects a vertex from V1 to that of V2.
Example
Suppose that V1 has one vertex (unshaded circles in diagram below) and V2
has three vertices (shaded circles in diagram below), then we obtain the
complete bipartite graph K1,3:
113
Open University of Mauritius - Computational Mathematics
Suppose that V1 has two vertices (unshaded circles in diagram below) and V2 has two vertices
(shaded circles in diagram below), then we obtain the complete bipartite graph K2,2:
Suppose that V1 has two vertices (unshaded circles in diagram below) and V2 has two vertices
(shaded circles in diagram below), then we obtain the complete bipartite graph K2,2:
Example
For I2
V = {00, 01, 11, 10}
E = {(00,01), (00, 10), (10, 11), (01, 11)}
For I3
V = {000, 001, 011, 111, 100, 101, 110, 010}
E = {(000,100), (000, 001), (000, 010), (010, 110), (010, 011), (110, 111), (110, 100), (100,
101), (111, 101), (111,011), (001,101), (001,011)}
114
Open University of Mauritius - Computational Mathematics
Definition 7
The degree of a vertex, written as deg(v), in an undirected graph is the number
of edges that include the vertex v.
Theorem
In an undirected graph G(V, E), the sum of the degree for all vertices is equal
to twice the number of edges.
deg (v1) + deg (v2) + deg (v3) + deg (v4) + … = 2 x number of edges
Theorem
In an undirected graph G(V, E), the sum of the degree for all vertices is equal
to twice the number of edges.
deg (v1) + deg (v2) + deg (v3) + deg (v4) + … = 2 x number of edges
Definition 8
The in-degree of a vertex in a digraph, written as degin(v), is equal to number
of edges having vertex v at their tip and the out-degree of a vertex in a
digraph, written as degin(v), is equal to number of edges having vertex v at
their tip.
Definition 9
Walk
A sequence of edges (e1, e2, e3,…,eL) is a walk in a graph G(V,E) if there is a
sequence of vertices (v0, v1, v2,…,vL) such that ej = (vj-1,vj )∈E.
115
Open University of Mauritius - Computational Mathematics
Note that vertices need not be distinct. If v0 = vL then the walk is a closed
walk.
Length of a Walk
The length of a walk is equal to the number of edges in the sequence.
Trail
A walk in which all the edges ej are distinct is called a trail. In a trail, an edge
should not appear twice. A vertex can appear more than once.
Path
A trail in which the vertices are distinct in the sequence of vertices (v0, v1, v2,…,vL) is called a
path. That is in a path, a vertex should not appear twice.
Cycle
A cycle is a closed trail in which all the vertices are distinct, except for the first and last, which
are identical.
Note that all paths are trails. All trails are walks.
Certain trails are not paths. For instance the walk through the vertices (a, b, c, d, e, b, and f) is a
trail as all the edges are distinct. However, this is not a path because the vertex b is visited twice.
Definition 10
Connected Vertices
Suppose that a and b are two vertices in a graph G(V, E). The two vertices a and b will be said
to be connected if there is a walk described by (v0,...,vL) where v0 = a and vL = b. We also say
that a vertex is connected to itself.
When every pair of vertices is connected, then we will refer to the graph as a connected graph.
Suppose that a and b are two vertices in a directed graph G(V,E). If there is a walk from a to b
then vertex b is said to be accessible or reachable from vertex a. We also say that the vertices
are accessible or reachable from themselves.
116
Open University of Mauritius - Computational Mathematics
Two vertices a and b in a directed graph are said to be strongly connected when the vertex b is
accessible from the vertex a and vertex a is accessible from vertex b. Moreover, we say that a
vertex is strongly connected to itself.
When every pair of vertices of a directed graph is strongly connected, we say that the graph is
strongly connected.
Suppose that when we convert the edges of a directed graph G(V,E) into
undirected ones, the graph becomes a connected undirected graph, then the
directed graph is said to be weakly connected.
Definition 11
Suppose that G(V,E) is a multigraph. A trail in G(V,E) is said to be a
Eulerian Trail if it includes the graph edges exactly once.
An Eulerian Trail that starts and ends at the same vertex is said to be a
Eulerian Tour.
Jungnickel’s Theorem
For a connected multigraph, the following statements are equivalent:
(1) G is Eulerian.
(2) The degree of all the vertex of G is even.
(3) The set of edges of G can be partitioned into cycles.
117
Open University of Mauritius - Computational Mathematics
Euler wanted to know if it is possible to start at any point and come back to
the same point by crossing each of the bridges once only? Of course the
answer is no.
The diagram below shows that if we start at East Island and we wish to come back to the East
Island, it will be impossible to do it without using an edge more than once.
118
Open University of Mauritius - Computational Mathematics
Now we add the arrows to show how it becomes a Eulerian Multigraph. The diagram below
shows that you can start at East Island and return to East Island by crossing all the bridges once
only.
Note that each of the vertex has a degree which is even. The cycles are clear on the diagram.
Hence Eulerian graphs are graphs that have a closed trail that includes every
edge exactly once.
If in Eulerian graphs, every edge is included once, in Hamiltonian graphs all vertices are
included.
Definition
A path that includes all of the graph’s vertices is called a Hamiltonian path in the graph.
A cycle that includes all the vertices of a graph is called a Hamiltonian tour or Hamiltonian
cycle.
Note that in Hamiltonian graphs, there must be at least three vertices else, it will not be
possible to have a cycle.
Theorem
Suppose that G is a graph that has n vertices (n has a value of 3 or more). If the degree of
each of the vertices is at least n/2, then G is a Hamiltonian graph.
119
Open University of Mauritius - Computational Mathematics
Theorem
Suppose that G is a graph that has n vertices (n has a value of 3 or more). If u and v are non-
adjacent vertices in G such that deg(u) + deg (v) ≥ n, then G is a Hamiltonian graph.
Suppose that G is a graph with n vertices. The closure of G, which we will write as [G], is a
graph that is obtained by adding edges until all non-adjacent pairs u and v satisfy the
condition deg(u) + deg (v) ≥ n.
Example
By adding edges, we can make the graph Hamiltonian.
Weighted Graphs
We shall associate a weight, w, to an edge. Weights are real numbers (so w can be negative, zero
or positive). For example, if vertices represent places, the weights can be the distance between
the two vertices. Weights can also be the time to travel between two vertices. Weights can be
profit when using the route from a to b.
Edges can represent roads, pipes, sea-route, cables,…
The weight of a walk is defined as the sum of the weights of the edges including the walk.
Definition
In a weighted graph G(V, E, w) that does not any cycle of negative weight,
we define distance as
d(a,a) = 0 for all vertices
d(a,b) = ∞ if there is no walk from a to b
d(a,b) is the weight of a minimal-weight walk from a to b when such
walk exists.
Network
A network is a graph in which each edge is assigned a distance.
Tree
A tree is a connected graph that does not have a cycle
Planar graph is one in which the edges intersect at the vertices only.
This is a complete graph K4 but it is not a planar graph:
120
Open University of Mauritius - Computational Mathematics
This is a complete graph K4 but it is a planar graph:
Isomorphic Graphs
Isomorphic graphs can be deformed (vertices moved and edges straightened
or bent) to make the other.
Incidence Matrix
In the incidence matrix of a graph, the elements represent the number
of edges connecting the vertices represented by the row and column of the
matrix.
Isomorphic
Graphs are isomorphic if one can be deformed to make the other.
The vertices can be moved and the edges straightened or bent to do this.
7.7 Network Analysis
Kruskal’s algorithm:
Step 1. Choose the shortest edge. In case there are several edges having the minimum weight,
just choose anyone of them.
Step 2. Choose the next shortest edge (it is not necessary that this edge be joined to the already
chosen edge.
Step 3. Choose the next shortest edge that does not create a cycle and add it.
121
Open University of Mauritius - Computational Mathematics
Step 4. Repeat Step 3 until all the vertices are connected.
Example
Find the minimum spanning tree for the network:
Step 1. We choose the shortest edge. Here we have BC and CE. We can choose anyone of them.
Let’s choose CE.
Step 2. Let’s choose the next shortest edge. Here it will be BC.
Step 3. Choose the next shortest edge (that should not form a cycle; it may or may not be
connected to the sub-graph obtained in step 2).
Repeat Step 3.
Prim’s Algorithm
122
Open University of Mauritius - Computational Mathematics
Step 1. Choose a vertex.
Step 2. Choose the shortest edge from this vertex to any other vertex that is
connected directly to it.
Step 3. Choose the nearest vertex not yet in the solution and which does not
form a cycle.
Step 4. Repeat Step 3 until all the vertices are connected.
123
Open University of Mauritius - Computational Mathematics
the table is
A B C D E F
A - 4 4 - - -
B 4 - 2 - - -
C 4 2 - 3 2 6
D - - 3 - - 3
E - - 2 - - 3
F - - 6 3 3 -
Step 2. Choose a column and cross its row. Let’s say we choose Column D. We will delete row
D.
Step 3. Choose the smallest number in column D and circle it. In case there is more than one,
choose one at random. Here we circle “3” which is in row C.
Step 4. Delete the row containing the number you have circled in Step 3. So we will delete row
C. We have now deleted rows D and C. We will choose the smallest value in Column D and C.
Here we choose “2” from row B. We circle it. We will delete row B
We have now deleted rows D, C and B. We will choose the smallest value in
Column D, C and B. Here we choose “2” from row E. We circle it.
We shall number the columns we are working with.
We will delete row E. Since the rows D, C, B and E have been deleted, we
will choose the smallest number in these columns. It is “3” in row F. We circle
it.
124
Open University of Mauritius - Computational Mathematics
We will delete row F. Since the rows D, C, B, E and F have been deleted, we
will choose the smallest number in these columns. It is “4” in row A. We circle
it.
125
Open University of Mauritius - Computational Mathematics
A 1 0
To implement the algorithm, 0 we proceed as follows:
Step 1. Assign the starting point a permanent label of zero and the ordering
label of one.
Step 2. Consider the vertices connected to the starting vertex. Label the vertices directly
connected to the starting vertex by giving them a working label equal to the
weight of the connecting B edge.
Step 3. Select the vertex 5 that has the minimum weight. Make its permanent label
become equal to its working label. Make its ordering label 2.
Vertex Ordering Label Permanent Label Step 4. Repeat Step 2 with the vertex
B 4 6 that was last given a permanent label
Working Label (Temporary) (identified in Step 3) until the
10 7 6 destination node has a permanent label.
Each time a permanent label is
assigned the ordering label is increased by one.
Step 5. Connect the destination to the start by working backwards. Always choose an edge for
which the difference in the permanent labels, found at the two end points of the edge, is equal to
weight of the edge.
Example
In the road network, the weight represents the length, in km, of the respective road. Find the
shortest route from A to J as well as its length.
Step 2. Since B and C can be reached directly from A, we will label them with
a working label of 5 and 12 respectively:
126
Open University of Mauritius - Computational Mathematics
A 1 0
Step 3. 0 Since vertex B has the smallest working label, we
will update its ordering label to 2 and permanent label to 5. C
is unchanged at this stage.
C
12
Step 4. Since B just got its permanent label, we will start with it. We can reach
C and F directly from B.
The working label of C will be equal to permanent
B 2 5
label of B plus the weight of the edge connecting B to C = 5
5
+ 6 = 11. Since vertex C already had a label 12, we will add
the working label 11 as it is smaller than 12. We will not add a working label
if it is larger than the existing one.
The working label of F will be equal to permanent label of B plus the weight
of the edge connecting B to F = 5 + 2 = 7:
C
12 11
Since the edge connecting B to F has the smallest weight 2, we will update
ordering label of F as 3 and give it its permanent label of 7.
F
7
Step 5. We will start with vertex F now. This will be repeated till vertex J gets
a permanent label:
F 3 7
7
127
Open University of Mauritius - Computational Mathematics
Always choose an edge for which the difference in the permanent labels, found at the two end
points of the edge, is equal to weight of the edge. For example from J, we will have to choose H
(because 22 – 15 = 7 = weight on edge connecting H to J). We can’t choose G (because 22 – 14
= 8 ≠ weight on edge connecting H to G = 9).
Example
What is the length of the shortest tour that covers all the edges in the given network. State the
suitable route.
128
Open University of Mauritius - Computational Mathematics
Step 1. Identify the vertices having an odd degree. They are A, C, D, and
E.
Step 2. Since there are 4 different vertices, we can have 3 pairings. Starting
with A, we can have the edge AC, AD and AE. If we take AC then we will
pair it with DE. When we take AD, we will pair it with CE. When we take
AE, we will pair it with CD.
AC and DE: 6 + 14 = 20
AD and CE: 11 + 6 = 17
AE and CD: 12 + 8 = 20
The pair having the smallest sum of weights is AD and CE.
7.8 Activities
Question 1
The following is a road network with the weight being the length in km.
(b) State the shortest route from S to H as well as the shortest distance.
129
Open University of Mauritius - Computational Mathematics
Question 2
Graph G has vertices P, Q, R, S, T, U, V, and W.
(i) Starting at P, use Prim’s algorithm to find the minimum spanning tree for G.
(ii) Use Kruskal’s algorithm to build the minimum spanning tree.
Draw the minimum spanning tree using vertices of G.
Question 3
The diagram shows a network of canals. After an oil spill, an expert wishes to inspect all the
canals. The expert will travel along each canal at least once.
(a) Using the Route Inspection algorithm, find the length of the shortest route that the expert
can take. State the canals that must be traversed twice.
(b) How many times would the vertex F appear in the Expert’s route?
(c) If the expert decides to start at the vertex H but can end at any place. Find the finishing
place so that the length of the route is shortest.
130
Open University of Mauritius - Computational Mathematics
Question 4
The graph is a network of roads with the weights equal to the length of the
road.
(a) Using Dijkstra’s algorithm, calculate the shortest distance from
A to I as well as state the shortest route.
(b) John decides to travel along each road at least one before ending
his journey at A. Find the shortest route Sam can take.
Question 5
Question 6
(a) An archaeologist found the above old train track. She wants to travel
from A to F. Use Dijkstra’s algorithm to find the shortest path she can
take.
(b) Using Prim’s algorithm and starting at G, find the minimum spanning
tree. State the length of the minimum spanning tree.
131
Open University of Mauritius - Computational Mathematics
Solution
Question 1
(a)
Question 2
(a) e.g. P Q S P
(b) No because vertex Q appears more than once.
(c) (i) PS, ST, SV; QS, QR; RU, TW
(ii) ST SV PS QS (not QT) QR (not PQ) (not TV) RU TW
Question 3
(a) A(BC)E + H(F)G = 15 + 13 = 28*
A(BDF)H + E(F)G = 30 + 7 = 37 A(BDF)G + E(F)H = 21 + 16 = 37
Repeated routes: AB, BC, CE, HF, FG Length: 214 + 28* = 242 (km)
(b) 4
(c) EG (7) is the shortest link between two odd nodes excluding H
Repeat EG (7) since this is the shortest path excluding H
We finish at A
Length of route = 214 + 7 = 221 (km)
132
Open University of Mauritius - Computational Mathematics
Question 4
Route ADGHI: 48 km
Question 5
(a) Kruskal starts with shortest edge while Prim’s start with any vertex. It is not
necessary to verify for cycles using Prim. Prim adds vertices to the tree while
Kruskal adds edges. Prim can be used with data given in a matrix form.
(ii) CF, DE, DF, not CD, not EF, DG, not FG, not EG, AC, not AD, AB.
133
Open University of Mauritius - Computational Mathematics
Question 6
(a)
(b) Prim starting at G: GF, GH, FJ, DG, JK, EK, BE, AB, CD or GF, GH, FJ, DG, CD, JK,
EK, BE, AB
80 km.
134
Open University of Mauritius - Computational Mathematics
UNIT
Randomness
8
7UNIT
STRUCTURE
6 8.1
8.2
8.3
Introduction
Learning Outcomes
Randomness
1
8.4 Generators of Random Numbers
8.5 Test of Randomness
8.6 Activities
8.1 Introduction
In this Unit, you will be introduced to random numbers. This is important in
cryptography as well as when carrying out sampling, simulations and property
testing.
8.3 Randomness
I am sure you have all generated random numbers, as you must have tossed coins or thrown dice.
Since several thousand years people have been using dice or tossing coins. People have always
accepted that throwing fair dice and tossing fair coins generate random numbers.
The sequence of random numbers generated must be statistically independent and identically
distributed (IID).
Microsoft Excel
I am sure that you must know people who play Lotto and use Excel Function
RANDBETWEEN(1,40) to generate a random number. Using it six times will generate six
random numbers.
135
Open University of Mauritius - Computational Mathematics
Random Number Table
You can also use Random Number Tables. In most the random number tables,
the random numbers are presented in groups of 5 in order to increase the
readability. In fact the first row in the following table was generated as follows:
1 3 9 6 2 7 0 9 9 2 6 5 1 7 2…
Thus if I want four 1-digit random numbers, I may take 1, 3, 9, and 6.
If I want five 2-digit random numbers, I may take 13, 96, 27, 09, and 92.
If I want two 3-digit random numbers, I may take 139 and 627.
136
Open University of Mauritius - Computational Mathematics
The results are generated in a table. They are 2, 15, 7, 9, 3, and 22.
Example
If we take m = 8, a = c =3 and x0 = 2
The sequence of random number generated is
x0 = 2
x1 = (ax0+c) mod m = (3 x 2 + 3) mod 8 = 1
x2 = (ax1+c) mod m = (3 x 1 + 3) mod 8 = 6
137
Open University of Mauritius - Computational Mathematics
x3 = (ax2+c) mod m = (3 x 6 + 3) mod 8 = 5
x4 = (ax3+c) mod m = (3 x 5 + 3) mod 8 = 2
Blum-Blum-Shub Generator
The Blum-Blum-Shub Generator (BBS) is commonly used in cryptography.
A Blum integer has two prime number as its factors such that each factor can
be written as 4t + 3 where t is an integer. 77 is a Blum integer as its factors are
11 and 7. 11 can be written as 4(2) + 3 and 7 can be written as 4(1) + 3.
Examples of Blum integers are
21, 33, 57, 69, 77, 93, 129, 133, 141, 161, 177, 201, 209, 213, 217, 237, 249,
253, 301, 309, 321, 329, 341, 381, 393, 413, 417, 437, 453, 469, 473, 489, 497,
501, 517, 537, 553, 573, 581, 589, 597, 633, 649, 669, 681, 713, 717, 721, 737,
749, 753, 781, 789,…
In order to generate random numbers, it starts by selecting two prime numbers
p and q, such that the product of p and q is a Blum integer: m = pq
Choose s between 1 and m-1.
Starting with x0 = s compute the sequence by using the formula
xn+1 = xn2 mod m
Finally the sequence of bits is created using bn = xn mod 2.
Example
p 7
q 19
m m = 7 x 19 =133 m is a Blum integer
Choose s = 100 (between 1 and 133 – 1 = 132)
s 100 1002 = 10000
x0 10000 mod 133 = 25 252 = 625 b0 = 625 mod 2 = 1
x1 625 mod 133 = 93 2
93 = 8649 b1 = 8649 mod 2 = 1
x2 8649 mod 133 = 4 2
4 = 16 b2 = 16 mod 2 = 0
x3 16 mod 133 = 16 2
16 = 256 b3 = 256 mod 2 = 0
x4 2
256 mod 133 = 123 123 = 15129 b4 = 15129 mod 2 = 1
Since in the field of Computing, you will be dealing with binary data, we will
use Wald-Wolfowitz Runs Test to test if runs of binary numbers are random or
not.
A run is defined as a sequence of the same digit. Each time that the value of the
digit changes, a new run begins.
Note that
The first run is 111
The second run is 00
The third run is 1
The fourth run is 0000
I would advise you to carry out the Run test using EXCEL.
Note that if n1 and n2 are not large then we will use a run test table to obtain the critical value
of r.
Example.
Suppose that we have 20 runs with 18 zeroes and 22 ones. Are the runs random?
Run's Test Formula used in Excel
n1 = number of zeroes 18 B3
n2 = number of ones 22 B4
n = n 1 + n2 40 B5
r = number of runs 20 B6
mean, μ 20.8 ((2*B3*B4)/B5) + 1
Variance, σ2 9.5446 ((2*B3*B4)*(2*B3*B4-B3-B4))/(((B3+B4)^2)*(B3+B4-1))
Standard deviation σ 3.0894 SQRT(B8)
Z 0.2589 ABS(B6-B7)/B9
p-value 0.7956 2*(1-NORMSDIST(B10))
Significance level of test 0.05 5%
Critical value of Z 1.9599 NORMSINV(1-B12/2)
Accept H0? YES IF(B11<B12,"NO","YES")
We have taken a screen shot from the Excel workbook for you:
139
Open University of Mauritius - Computational Mathematics
Example
Suppose that we have 10 runs with n1 = 17 zeroes and n2 = 9 ones. Are the runs
random?
Here we will have to use the random number table to find the number of runs
that would allow us to accept H 0.
From Table below
140
Open University of Mauritius - Computational Mathematics
We choose the following row with n1 = 17, n2 = 9. This shows that the number
of runs that we must have to accept H0 ranges from 8 to 19. Since we got 10
runs, we accept H0 at 5% level of significance (two-tailed).
For other values of n1 and n2, the critical values of r are (5% level of
significance-two-tailed):
8.6 Activity
Question 1.
141
Open University of Mauritius - Computational Mathematics
Generate five random numbers using LCG with seed = 1073 and parameters a = 35, b = 528
and m = 2547.
Answer: 2425, 1352, 2002, 1829, and 868.
Question 2.
(a) Show that 781 is a Blum number.
(b) Using Blum-Blum-Shub Generator (BBS) with p =11, q = 71, and seed
=15, generate 5 binary digits.
Answer: 11010
p 11
q 71
m 781
s 15 225
x0 225 50625 1
x1 85 7225 1
x2 196 38416 0
x3 147 21609 1
x4 522 272484 0
Question 3.
(a) Show that 5293 is Blum number.
(b) Using Blum-Blum-Shub Generator (BBS) with p =67, q = 79, and seed
=127, generate 5 binary digits.
Answer: 01100
p 67
q 79
m 5293
s 127 16129
x0 250 62500 0
x1 123 15129 1
x2 4543 20638849 1
x3 1442 2079364 0
x4 4508 20322064 0
Question 4
Suppose that we have 40 runs with 35 zeroes and 25 ones. Are the runs random
at 5% level of significance?
Answer: No
142
Open University of Mauritius - Computational Mathematics
143
Open University of Mauritius - Computational Mathematics