Bagdasar - Concise Computer Mathematics Tutorials On Theory and Problems
Bagdasar - Concise Computer Mathematics Tutorials On Theory and Problems
Ovidiu Bagdasar
Concise Computer
Mathematics
Tutorials on Theory
and Problems
SpringerBriefs in Computer Science
Series Editors
Stan Zdonik
Peng Ning
Shashi Shekhar
Jonathan Katz
Xindong Wu
Lakhmi C. Jain
David Padua
Xuemin Shen
Borko Furht
V. S. Subrahmanian
Martial Hebert
Katsushi Ikeuchi
Bruno Siciliano
Concise Computer
Mathematics
Tutorials on Theory and Problems
123
Ovidiu Bagdasar
University of Derby
Derby
UK
v
Preface
Through the ages, mathematics has established itself as ‘‘the door and key to the
sciences’’ (in the words of Roger Bacon, 1214-1294) and since antiquity it rep-
resented one of the key areas of interest for human knowledge. However, Euclid is
said (following Proclus) to have replied to King Ptolemy’s request for an easier
way of learning mathematics that ‘‘there is no Royal Road to geometry’’. To most
students’ despair, Mathematics still seems to be the tumbling stone for anyone
trying to understand the world around us. Computer Science students make no
exception as they need to master some key areas of mathematics.
This book has its origins in the delivery of a Computational Mathematics
module to a body of undergraduate Computing students. The aim of the module
was to deliver an easily accessible, self-contained introduction to the basic notions
of Mathematics necessary for their degree. The variety of Computing programmes
delivered (Computer Science, Computer Games Programming, Computer Forensic
Investigation, Computer Networks and Security, Information Technology) posed a
real challenge when developing the syllabus for Computational Mathematics. This
book reflects the need to quickly introduce students, from a variety of educational
backgrounds, to a number of essential mathematical concepts.
The material is divided into four units: Discrete Mathematics (Sets, Relations,
Functions), Logic (Boolean Types, Truth tables, proofs), Linear Algebra (Vectors,
Matrices and Graphics) and Special topics (Graph Theory, Number Theory, Basic
elements of Calculus). Each teaching unit was used in conjunction with specifi-
cally designed computer-based tests available through the whole semester.
The module was a success as the students engaged well with their work and
improved both the attitude towards their studies and their problem solving skills.
The flexibility offered by the computer-based tests was highly praised in the
feedback gathered from the students.
vii
viii Preface
Teaching
Each chapter is covered in two hours of lectures and two hours of tutorial.
Assessment
The assessment is based on computer tests and consists of two parts, each worth
50 % of the final mark.
Part II: Two hours summative test with questions from all subjects.
Acknowledgments
First of all, I would like to thank my family for bearing with a part-time husband
and father during my first year as a Lecturer. My appreciation goes to my mentors:
Richard and Nick—for their excellent guidance and tremendous support through
my first steps as an Academic, Peter and Stuart—for being by my side in every
step of the way. Finally to all my colleagues at the University of Derby.
ix
Contents
3 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.1 Brief Theoretical Background . . . . . . . . . . . . . . . . . . . . . . . 19
3.2 Essential Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
3.3 Supplementary Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
3.4 Problem Answers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
xi
xii Contents
11 Elements of Calculus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
11.1 Brief Theoretical Background . . . . . . . . . . . . . . . . . . . . . . . 89
11.2 Essential Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
11.3 Supplementary Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
11.4 Problem Answers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
Chapter 1
Sets and Numbers
Abstract Sets are defined as collections of objects of the same kind and are among
the fundamental notions in many Mathematical subjects, including Algebra and Cal-
culus. Operations involving sets play a key role in many applications and sets of
numbers have been created for solving numerous problems inspired from real life.
In this chapter we present some of the key concepts in the theory of sets such as
basic set operations, Venn diagrams, set cardinals and motivations for the number
systems.
c ∈ B, c ∈ A, A ⊂ B
P(A) = {∅, {a}, {b}, {a, b}},
A × B = {(a, a), (a, b), (a, c), (b, a), (b, b), (b, c)}.
Set Operations
Venn Diagrams
Set and operations can be represented by Venn diagrams like in Fig. 1.1. The universe
U corresponding to two sets (Fig. 1.1a) is divided into four distinct regions, which
can be related to the previously defined set operations.
For example, in the above diagrams for two sets (Fig. 1.1a), A ∩ B represents
region 3, A ∪ B regions 1, 2 and 3, A \ B region 1, AB regions 1 and 2, while Ac
regions 2 and 4. Venn diagrams are also used to represent operations involving three
sets (Fig. 1.1b) or more.
Fig. 1.1 Venn diagrams for a two sets and b three sets
1.1 Brief Theoretical Background 3
A = {0, 1, 2, 3} (enumeration)
B = {n ∈ N : 3 ≤ n ≤ 100} (ellipsis)
C = {x = n 2 : n ∈ N} (formula)
Most people know the natural numbers 0, 1, 2, 3, ..., but other number sets exist. The
German mathematician Leopold Kronecker (1850s) was quoted as having said “God
made natural numbers; all else is the work of man”.
His conclusion was based on the fact that starting with the set of natural numbers,
further number sets can be generated by using basic operations (such as subtraction
or division of natural numbers), and also by trying to define sets which accommodate
the solutions of simple equations.
Polynomials
1. x −1 =0⇒ x =1∈N
2. x +1 =0⇒ x = −1 ∈ N, x ∈Z
3. 4x − 1 =0⇒ x = 1/4
√ ∈ Z, x ∈Q
4. 2x 2 − 1 =0⇒ x = √2 ∈ Q, x ∈R
5. x2 + 1 =0⇒ x = −1 = i ∈ R, x ∈C
N Z Q R C.
E 1.1. What is the power set P(A) (set of all subsets) for A = {a, b, c}?
E 1.2. Find the cartesian product of sets A = {1, 2, 3, 6} and B = {a, b, c} (all
pairs whose first component is in A, and second component in B).
Find the sets and corresponding regions in the Venn diagram Fig. 1.1b
A∪ B A∪C B ∪C
A∩ B A∩C B ∩C
A \ (A ∩ C) B \ (A ∪ C).
E 1.5. (a) List the elements of the sets (enumerate or give a formula).
(i) {x ∈ N+ : x is a multiple of 4}
(ii) {x ∈ Z : −2 ≤ x ≤ 3}
(b) List the elements of the following sets (enumerate or give a formula).
A = {x ∈ N+ : x is prime, x ≤ 45}
B = {x ∈ N+ : x is even}
C = {x ∈ N+ : x is odd}
D = {x ∈ N+ : x is a multiple of 6}
Are any of the above sets A, B, C or D subsets of one of the other sets?
(c) Determine which of the following sets are equal
E = {0, 1, 2, 3}
F = {x ∈ N : x 2 < 13}
G = {x ∈ N : (x 2 + 3) < 2}
E 1.8. Show that the following set identities are true, using Venn diagrams.
(i) A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C) (distributivity of ∩)
(ii) A ∪ (B ∩ C) = (A ∪ B) ∩ (A ∪ C) (distributivity of ∪)
(iii) (A ∩ B)c = Ac ∪ B c (de Morgan law for ∩)
(iv) (A ∪ B)c = Ac ∩ B c (de Morgan law for ∪).
Essential Problems
E 1.1. P(A) = {∅, {a}, {b}, {c}, {a, b}, {a, c}, {b, c}, {a, b, c}}.
E 1.2. A × B = {(1, a), (1, b), (1, c), (2, a), (2, b), (2, c), (3, a), (3, b), (3, c),
(6, a), (6, b), (6, c)}.
A∪B = {‘r ’, ‘e’, ‘s’, ‘t’, ‘l’, ‘a’, ‘x’}; A ∪ C = {‘r ’, ‘e’, ‘s’, ‘t’, ‘l’, ‘u’, ‘m’, ‘b’};
B ∪C = {‘r ’, ‘e’, ‘l’, ‘a’, ‘x’, ‘s’, ‘u’, ‘m’, ‘b’}; A ∩ B = {‘r ’, ‘e’};
A∩C = {‘r ’, ‘e’, ‘s’};
B ∩C = {‘r ’, ‘e’, ‘l’}; A \ (A ∩ C) = {‘s’, ‘t’}; B \ (A ∪ C) = {‘a’, ‘x’}.
E 1.6. (i) yes; (ii) nothing; The inclusion can be true or false.
We may have the following situations:
• If A = {2n : n ∈ N+ }, B = {2n + 1 : n ∈ N+ } and C = N then A ⊂ C, B ⊂ C and
A ∩ B = ∅ (A and B have no common elements).
• If A = {2n : n ∈ N+ }, B = {4n : n ∈ N+ } and C = N then A ⊂ C, B ⊂ C and
A ∩ B = ∅ but B ⊂ A (B is included in A).
E 1.7. Let U = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} and A = {0, 1, 2, 3, 4, 5},
B = {4, 5, 6, 7}.
E 1.8. The expressions correspond to the same regions of the Venn diagrams.
8 1 Sets and Numbers
Supplementary Problems
(a) A × B × C = {(1, a, a), (1, a, b), (1, a, c), (1, b, a), (1, b, b), (1, b, c), (1, c, a),
(1, c, b), (1, c, c), (2, a, a), (2, a, b), (2, a, c), (2, b, a), (2, b, b),
(2, b, c), (2, c, a), (2, c, b), (2, c, c), (3, a, a), (3, a, b), (3, a, c),
(3, b, a), (3, b, b), (3, b, c), (3, c, a), (3, c, b), (3, c, c)};
S 1.2. You may use the Venn diagrams to show that both sides determine the same region.
Otherwise, we can use the following argument.
A = {2, 3, 4, 5, 6}
B = {1, 3, 4, 5, 7, 8, 9, 10}
Representation
R = {(1, a), (1, b), (2, e), (3, b), (3, c), (4, c)}, (2.1)
In this relation we can see that (1, a) ∈ R (or 1Ra), while (1, c) ∈ R.
At the same time, no element in X is related to d ∈ Y .
Classification of Relations
Operations on Relations
R = {(1, a), (1, b), (2, e), (3, b), (3, c), (4, c)},
S = {(1, b), (2, a), (3, d), (4, c)},
Example:
Consider the set X = {1, 2, 3, 4} and the relations R = {(1, 2), (1, 1), (1, 3), (2, 4),
(3, 2)} and S = {(1, 4), (1, 3), (2, 3), (3, 1), (4, 1)}. Find S ◦ R.
Solution: As (1, 2) ∈ R and (2, 3) ∈ S, one has (1, 3) ∈ S ◦ R.
Similarly we can proceed with the others:
• (1, 1) ∈ R and (1, 4) ∈ S ⇒ (1, 4) ∈ S ◦ R
• (1, 1) ∈ R and (1, 3) ∈ S ⇒ (1, 3) ∈ S ◦ R
• (1, 3) ∈ R and (3, 1) ∈ S ⇒ (1, 1) ∈ S ◦ R
• (2, 4) ∈ R and (4, 1) ∈ S ⇒ (2, 1) ∈ S ◦ R
• (3, 2) ∈ R and (2, 3) ∈ S ⇒ (3, 3) ∈ S ◦ R
This finally gives S ◦ R = {(1, 3), (1, 4), (1, 1), (2, 1), (3, 3)}.
Examples:
1. X: all people in the world; xRy: x is a blood relative of y.
The relation is reflexive, symmetric, transitive (equivalence) and total.
2. X = N; xRy if x ≤ y.
The relation is reflexive, antisymmetric, transitive and total.
3. X = N; xRy if x > y
The relation is not reflexive, not antisymmetric, but transitive and total.
12 2 Relations and Databases
Each entry has four attributes, therefore this is a 4-ary database. The ID and Name
attributes can uniquely identify the entries. The surname or the programme cannot
uniquely identify the entries on their own, but they form a key when combined.
Remark: In the context of keys one can better understand why students or employees
of big companies are given an ID number!
E 2.1. Let C be all characters and Y = {“apple”, “pie”}. Describe the relation
APPEARS ⊂ C × Y
R ⊂ X × Y = {(1, A), (1, C), (2, A), (3, D), (4, D)}
S ⊂ Y × Y = {(E, A), (E, B), (B, D), (C, F), (A, F)}.
(A R) B = A (R B).
E 2.7. For each of the relations given below, decide whether or not it is:
(a) many-one; (b) one-many; (c) one-one; (d) onto.
14 2 Relations and Databases
S 2.1. Let X and Y be sets of cardinalities m and n respectively. What is the minimum
cardinality of relation R ⊂ X × Y ? What is the maximal one ?
S 2.2. For A1 , A2 ⊂ X, B1 , B2 ⊂ Y sets and R, S ⊂ X × Y relations prove that
S 2.3. Let STUDENTS be the set of students in a college, COURSES be the set
of courses the college runs, and SESSIONS be the set of sessions (such as: June
21, a.m.) at which exam papers are taken. (Students may take more than one course,
and a course may have more than one exam paper.) Relations TAKING and EXAM
are defined as:
Let F be the set of female students, and C the set of computing courses.
(i) Express in English each of the following:
(a) C EXAM
(b) EXAM(C)
(c) EXAM ◦ TAKING
(d) EXAM −1 ◦ EXAM
(e) EXAM ◦ (TAKING C)
(ii) Using F, C, TAKING and EXAM and operations on relations, express
(a) Relation (s, c) where s is a female student taking computing course c.
(b) The set of courses with no female students.
(c) The set of exam sessions when the student ‘A107X’ has a paper to sit.
S 2.4. HOBBIES is a relation which is defined below:
S 2.6. Prove whether the following binary relations are equivalences. If the relation
is not an equivalence relation, state why it fails to be one.
(i) X = Z : a ∼ b if ab > 0.
(ii) X = R : a ∼ b if a − b is rational.
(iii) X = R : a ∼ b if a ≥ b.
(iv) X = C : a ∼ b if |a| = |b|.
16 2 Relations and Databases
Essential Problems
E 2.1. APPEARS =
C Y
‘a’ “apple”
‘p’ “apple”
‘l’ “apple”
‘e’ “apple”
‘p’ “pie”
‘i’ “pie”
‘e’ “pie”
E 2.2. (i)
1 ‘a’
1 ‘b’
2 ‘d’
3 ‘b’
4 ‘b’
(A R) B = A (R B) = {(a, b) ∈ R : a ∈ A, b ∈ B}.
Supplementary Problems
S 2.1. min = 0; max = mn.
S 2.2. One just needs to use the definitions of ∩, ∪, , and of the image of a
subset, and the double inclusion to prove the pairs of sets are equal.
S 2.3. (i) Express in English each of the following:
(a) C EXAM =(c, d): there is a paper in computing c in the exam session d
(b) EXAM(C) = the sessions d having computing exams
(c) EXAM ◦ TAKING = (s, d) the students s taking an exam in session d
(d) EXAM −1 ◦EXAM = (c, e) the pairs of courses c,e having a common session
(e) EXAM ◦ (TAKING C) = (s, d) the students s taking computing exam in
session d.
(ii)
(a) F TAKING C;
(b) TAKING(STUDENTS \ F);
(c) EXAM(TAKING( ‘A107X’)).
S 2.4. The answer is
(ii) X = R : a ∼ b if a − b is rational.
Yes: reflexive, symmetric and transitive.
(iii) X = R : a ∼ b if a ≥ b.
No: reflexive, antisymmetric and transitive.
Abstract Functions are very often the central objects of investigation in most fields
of modern mathematics. There are many ways to describe or to represent a function.
Functions can be defined by a formula or algorithm that indicates how to compute the
output for the given input. Sometimes they are given by a picture (called the graph
of the function), or by a table of values. In this chapter functions are introduced as
relations which link every input from a given set to a unique output from another set.
We then present some basic properties, examples and operations involving functions,
along with applications based on set numbers, data structures and polynomials.
• Function: Special type of relation s.t. each element has a unique image.
• Function elements: X -domain, Y -codomain, y = R(x) ∈ Y - image of x.
x1 , x2 ∈ X : x1 = x2 ⇒ f (x1 ) = f (x2 )
(Example: f : R → R, f (x) = −2x + 1)
x1 , x2 ∈ R : x1 ≤ x2 ⇒ f (x1 ) ≤ f (x2 )
(Example: f : R → R, f (x) = 2x + 1)
Applications
• Theory of cardinals:
(1) Two sets have same cardinal if there is a 1–1 function between X ∼ Y
(2) Finite sets: have same cardinal is the same number of elements
(3) Infinite sets: N ∼ Z ∼ Q (countable), R (not countable).
• Datatype (set, together with the basic defining functions) string:
(1) Sets: C set of all characters, S set of all (ordered) sequences of characters
(2) Notation: ‘a’ - character, “string” - string
3.1 Brief Theoretical Background 21
Composition of Functions
2P = 4x + 2y + 2
• addition:
P + Q = 3x 2 + 2x y + 6x + y − 2
• multiplication
P Q = (2x + y + 1)(3x 2 + 2x y + 4x − 3)
= 6x 3 + 7x 2 y + 11x 2 + 2x y 2 + 6x y − 2x − 3y − 3.
E 3.2. Which of the following are true? If false or invalid explain why.
3.2 Essential Problems 23
(a) ‘a’ <c ‘A’; (b) ‘2’ <c ‘Q’; (c) 3 =c ‘3’.
x 2 ± 2x y + y 2 = (x ± y)2 ;
x 2 − y 2 = (x + y)(x − y);
x 3 ± y 3 = (x ± y)(x 2 ∓ 2x y + y 2 ).
S 3.6. Prove that every function f : R → R can be written as the sum of two
functions g, h : R → R, such that g is even and h is odd.
3.4 Problem Answers 25
Essential Problems
E 3.1. ASC(‘A’) = 65, ASC(‘ p’) = 112, therefore we have 97 and 144.
E 3.2. (a) false; (b) true; (c) invalid.
E 3.3. (a) true; (b) invalid; (c) false; (d) invalid.
E 3.4. (a) 3; (b) 6; (c) invalid; (d) ‘H’; (e) “RINCE”; (f) “PRINCEHal”;
(g) invalid; (h) “alice”.
E 3.5. ‘1’, 9.
E 3.6. (a) 68 + 100 = 168; (b) invalid; (c) “H”; (d) STR(65) invalid;
(e) “ouise”; (f) “T”; (g) 7; (h) “og” ; (i) “o”; (j) FIRST(" ") - invalid - the function is
only defined for non-empty strings; (k) “ f ”+s " "= “ f ”.
E 3.7. (a) “push”; (b) any 6 character string; (c) " "; (d) ASC(‘m’) = 109, so
v = ‘m’; (e) w ∈ N is not a string, therefore L E N (w) is invalid.
E 3.8. (a)
(i) f ◦ f = x 4 − 2x 2 ;
(ii) g ◦ f = 2(x 2 − 1)2 + (x 2 − 1) + 1 = 2x 4 − 3x 2 + 2;
(iii) f ◦ h = (3x − 2)2 − 1;
(iv) h ◦ f = 3(x 2 − 1) − 2 = 3x 2 − 5;
(v) g ◦ h = 2(3x − 2)2 + (3x − 2) + 1 = 18x 2 − 9x + 7.
(b)
Supplementary Problems
√
S 3.1. (a) f (x) = x 2 : If X = R, then R + ⊂ Y ; (b) f (x) = x: X ⊂ R + ;
(c) X = [2, 4] and f (x) = x + 2: [4, 6] ⊂ Y .
S 3.2. The solution is: domain s ∈ S \ {“ ”} and 97 ≤N ASC(F I RST (s)) ≤N 122,
codomain: t = AD D F I RST (C H R(ASC(F I RST (s)) −N 32), R E ST (s)).
Remark: five other functions ASC, C H R, F I RST, R E ST, AD D F I RST have all
been used to make the function C A P I T AL_C O N V E RT .
S 3.3. (a) bijective; (b) neither; (c) neither; (d) surjective; (e) bijective; (f) bijective;
(g) bijective; (h) bijective. N, 2N and 3N have the same cardinal.
S 3.4. Functions (iii) and (iv) are well defined. The others are not.
26 3 Functions
1
g(x) = [ f (x) + f (−x)] (even)
2
1
h(x) = [ f (x) − f (−x)] (odd).
2
Chapter 4
Boolean Algebra, Logic and Quantifiers
Abstract Boolean algebra was introduced in 1854 by George Boole and has been
very important for the development of computer science. It operates with variables
which have the truth values true and false (sometimes denoted 1 and 0 respectively).
In this chapter the main operations of Boolean algebra (conjunction (AND, ∧),
disjunction (OR, ∨) and negation (NOT, ¬)) are defined, and statements involving
logical variables are studied with the aid of truth tables and Venn diagrams. Useful
formulae involving logical variables are then discussed (De Morgan’s laws), along
with the existential and universal quantifiers and their negation.
Boolean Values: B = {tr ue, f alse} (sometimes the set {0, 1} is used instead).
Boolean Operations
These operations are usually represented using truth tables like below
p q ¬p p ∨ q p ∧ q p ⇒ q p ⇔ q
T T F T T T T
T F F T F F F
F T T T F T F
F F T F F T T
Definitions
• De Morgan’s Laws
¬( p ∧ q) = ¬ p ∨ ¬q
¬( p ∨ q) = ¬ p ∧ ¬q
• Distributive Law
p ∧ (q ∨ r ) = ( p ∧ q) ∨ ( p ∧ r )
p ∨ (q ∧ r ) = ( p ∨ q) ∧ ( p ∨ r )
4.1 Brief Theoretical Background 29
• Associative Law
p ∧ (q ∧ r ) = ( p ∧ q) ∧ ( p ∧ r )
p ∨ (q ∨ r ) = ( p ∨ q) ∨ ( p ∨ r )
(iii) Construct a truth table for (p ∧ q)∨r and for (p ∨r) ∧ (q ∨r) hence show that
these two statements are logically equivalent.
(iv) Check whether (p ∨ q)∧¬r and (p ∧¬r)∨(q ∧¬r) are equivalent.
E 4.3. For x ∈ R, suppose that p, q and r are the propositions given below:
p: x = −4
q: x = +4
r: x 2 = 16
E 4.4. Decide which of the sentences below, are universally true, which are univer-
sally false, and which are neither. Then write the predicates below in symbolic form:
(i) (x + 3)2 > 8, x ∈ N; (ii) 2x = 9, x ∈ N.
E 4.5. Check (using truth tables) which statements are logically equivalent
(i) (a ∧ b) ∨ b and a ∧ b
(ii) (a ∧ b) ∨ a and a
(iii) (¬a ∧ b ∧ c) ∨ ((a ∧ b) ∨ c) and b ∧ c
(iv) a ⇒ b and ¬b ⇒ ¬a.
E 4.6. Below, y is a variable of type Nat, c is of type Char and s and t are of type
Str. Represent the following conditions formally, using only standard functions of
the data types Nat, Char, Str and ∧, ∨, ¬, ⇒, ⇔ .
(i)y is either less than 3, or greater than 6 but less than 10. y is not seven.
(ii)The first character of s is ‘b’ and the second character of s is ‘a’.
(iii)If s starts with ‘c’ then t starts with ‘c’.
(iv) s and t have similar starting characters, but their second characters are distinct.
(v) c is an upper case vowel, and the first two characters of t are the same if and
only if the first two characters of s are the same.
(vi) s is the string “fred” or y has the value 16, but not both.
E 4.7. Use quantifiers to express formally the following predicates:
(i) There is a natural number whose square is greater than 7
(ii) Whatever real number x, x 2 = −(x 2 + 1) is false.
E 4.8. Write in English the negations of the following statements
(i) All dogs bark;
(ii) Some birds fly;
(iii) No cat likes to swim;
(iv) No computer science student does not know mathematics.
E 4.9. Find the negation of the following statements and evaluate their truth values:
(i) ∀ x ∈ R [ x 2 − 6x + 10 ≥ 0]; (ii) ∀ x ∈ R [ x 2 ≥ x];
(iii) ∃ x ∈ N+ [ x 2 + 2x − 2 ≤ 0]; (iv) ∃ x ∈ Q [ x 2 = 3].
Essential Problems
E 4.1. John is either not six feet tall, or he weighs less than 200 pounds.
E 4.2. In each case, one needs to build the table for 2 and 3 variables.
The final expressions are called H or G(to avoid wide tables).
p ¬p q ¬p ∧ q H
1 0 1 0 1
1 0 0 0 1
0 1 1 1 0
0 1 0 0 1
p q r ¬q p ∨¬q H
1 1 1 0 1 1
1 1 0 0 1 0
1 0 1 1 1 1
1 0 0 1 1 0
0 1 1 0 0 0
0 1 0 0 0 0
0 0 1 1 1 1
0 0 0 1 1 0
(iii) Let G=(p ∧ q)∨r and H=(p ∨r)∧(q ∨r). The truth table for G and H is
p q r p ∧ q p ∨r q ∨r G H
1 1 1 1 1 1 1 1
1 1 0 1 1 1 1 1
1 0 1 0 1 1 1 1
1 0 0 0 1 0 0 0
0 1 1 0 1 1 1 1
0 1 0 0 0 1 0 0
0 0 1 0 1 1 1 1
0 0 0 0 0 0 0 0
p q r ¬r p ∨ q p ∧¬r q ∧¬r G H
1 1 1 0 1 0 0 0 0
1 1 0 1 1 1 1 1 1
1 0 1 0 1 0 0 0 0
1 0 0 1 1 1 0 1 1
0 1 1 0 1 0 0 0 0
0 1 0 1 1 0 1 1 1
0 0 1 0 0 0 0 0 0
0 0 0 1 0 0 0 0 0
S 4.6. (i) For all strings s, the propositions “the string is not void” and “the string’s
length is at least one” are equivalent. True.
(ii) Every string s has a first character ‘c’.
False, as it doesn’t apply for the empty string s=“ ”.
(iii) Every string s is either empty, or has a first character ‘c’. True.
Chapter 5
Normal Forms, Proof and Argument
Equivalent way of writing the truth table, first using ∧, then using ∨.
Example 1: Find the d.n.f of ¬(¬ p ∧ q) (Fig. 5.1).
Step 1: Truth table
p ¬p q ¬q ¬ p ∧ q ¬(¬ p ∧ q)
1 0 1 0 0 1
1 0 0 1 0 1
0 1 1 0 1 0
0 1 0 1 0 1
Conjunctive normal form (c.n.f.) combines the basic literals, first using ∨, then
using ∧.
Algorithm for finding the c.n.f of a formula H:
Observation 1: The expressions d.n.f(H) and c.n.f(H) have the same truth value
(maybe less evident for c.n.f, where which is basically equivalent to ¬(¬ H)) as they
are just different ways of writing H .
p q ¬p H ¬H
1 1 0 0 1
1 0 0 0 1
0 1 1 1 0
0 0 1 0 1
= (¬ p ∨ ¬q) ∧ (¬ p ∨ q) ∧ ( p ∨ q)
d.n. f (¬H ) = ( p ∧ q ∧ ¬r ) ∨ ( p ∧ ¬q ∧ r ) ∨ (¬ p ∧ q ∧ r ) ∨ (¬ p ∧ q ∧ ¬r )
∨ (¬ p ∧ ¬q ∧ ¬r )
c.n. f (H ) = (¬ p ∧ ¬q ∧ r ) ∨ (¬ p ∧ q ∧ ¬r ) ∨ ( p ∧ ¬q ∧ ¬r )
∨ ( p ∧ ¬q ∧ r ) ∨ ( p ∧ q ∧ r )
Deduction Rules
Rules defining a valid argument from a fallacious argument.
When the conjunction of all the assumptions implies the conclusion (this can be
checked using truth tables), the argument is valid.
p q p⇒q ¬q ¬p
1 1
1 0 0
1 0 0 1 0
0 1 1 0 1
0 0 1 0 1
Valid Fallacious
Modus Ponens Converse error
p ⇒ q; p p ⇒ q; q
q p
Modus Tollens Inverse error
p ⇒ q; ¬q p ⇒ q; ¬ p
¬p ¬q
38 5 Normal Forms, Proof and Argument
Proof by Contradiction
This argument is based on Modus Tollens.
√
Example. Prove that 2 is not rational (fraction).
√
Proof. Assume that 2 is rational. Then √ there are two natural numbers p, q s.t they
have no common divisors and qp = 2, therefore p 2 = 2q 2 . Because p and q are
natural numbers, p 2 is a multiple of 2, so p itself is a multiple of 2 ( p = 2 p1 ). In
this case, (2 p1 )2 = 2q 2 , which gives 2 p12 = q 2 . Using the same argument as before,
q = 2q1 . We have just proved that 2 is a common divisor of p and q, which is a
contradiction.
p ¬p q ¬q H
1 0 1 0 1
1 0 0 1 0
0 1 1 0 0
0 1 0 1 1
5.2 Essential Questions 39
E 5.4. Find d.n.f(G) and c.n.f(G) for formula G in the truth table below and identify
the corresponding regions in the Venn diagram.
E 5.5. Use truth tables to prove the arguments Modus Ponens, Modus Tollens, Inverse
Error and Converse Error.
E 5.6. Prove that if the product ab is even, then either a or b has to be even.
E 5.7. In a box there are 3 blue balls, 5 red balls and 7 yellow balls. Calculate the
minimum number of balls needed to be drawn from the box before
(i) a pair of the same color can be made;
(ii) pairs of each color are made.
S 5.4. Use the deduction rules discussed before to prove which of the following
arguments are valid and which are fallacious (use truth tables).
S 5.7. Prove that if six distinct numbers are selected from {1, 2, . . . , 9}, then some
two of these numbers sum to 10.
Essential Problems
p ¬p q ¬q ¬ p ∧ q ¬ p ∨ q G H
1 0 1 0 0 1 1 0
1 0 0 1 0 0 1 1
0 1 1 0 1 1 0 0
0 1 0 1 0 1 1 0
5.4 Problem Answers 41
E 5.2. We first need to find the truth table for the expressions
A = p ∨ (q ∧ r ), B = ¬(( p ∧ q) ∨ r ) and C = p ⇔ (q ∧ r ) and their negations.
p q r q ∧ r p ∧ q ( p ∧ q) ∨ r A B C ¬A ¬B ¬C
1 1 1 1 1 1 1 0 1 0 1 0
1 1 0 0 1 1 1 0 0 0 1 1
1 0 1 0 0 1 1 0 0 0 1 1
1 0 0 0 0 0 1 1 0 0 0 1
0 1 1 1 0 1 1 0 0 0 1 1
0 1 0 0 0 0 0 1 1 1 0 0
0 0 1 0 0 1 0 0 1 1 1 0
0 0 0 0 0 0 0 1 1 1 0 0
d.n.f(A) = ( p ∧ q ∧ r ) ∨ ( p ∧ q ∧ ¬r ) ∨ ( p ∧ ¬q ∧ r ) ∨ ( p ∧ ¬q ∧ ¬r )
∨ (¬ p ∧ q ∧ r ).
c.n.f(A) = ¬d.n.f(¬A) = ( p ∨ ¬q ∨ r ) ∧ ( p ∨ q ∨ ¬r ) ∧ ( p ∨ q ∨ r ).
d.n.f(B) = ( p ∧ ¬q ∧ ¬r ) ∨ (¬ p ∧ q ∧ ¬r ) ∨ (¬ p ∧ ¬q ∧ ¬r ) and
c.n.f(B) = (¬ p ∨ ¬q ∨ ¬r ) ∧ (¬ p ∨ ¬q ∨ r ) ∧ (¬ p ∨ q ∨ ¬r ) ∧ ( p ∨ ¬q ∨ ¬r )
∧ ( p ∨ q ∨ ¬r ).
d.n.f(C) = ( p ∧ q ∧ r ) ∨ (¬ p ∧ q ∧ ¬r ) ∨ (¬ p ∧ ¬q ∧ r ) ∨ (¬ p ∧ ¬q ∧ ¬r ).
c.n.f(C) = (¬ p ∨ ¬q ∨ ¬r ) ∧ (¬ p ∨ q ∨ ¬r ) ∧ (¬ p ∨ q ∨ r ) ∧ ( p ∨ ¬q ∨ ¬r ).
d.n.f(G) = ( p ∧ q ∧ ¬r ) ∨ (¬ p ∧ q ∧ ¬r ) ∨ (¬ p ∧ ¬q ∧ r ) ∨ (¬ p ∧ ¬q ∧ ¬r ).
c.n.f(G) = (¬ p ∨ ¬q ∨ r ) ∧ (¬ p ∨ q ∨ ¬r ) ∧ (¬ p ∨ q ∨ r ) ∧ ( p ∨ ¬q ∨ ¬r ).
p q p⇒q ¬q ¬ p
1 1 1 0 0
1 0 0 1 0
0 1 1 0 1
0 0 1 1 1
p q p ⇒q ¬q ¬p
1 1
1 0 0
1 0 0 1 0
0 1
1 0 1
0 0 1 1 1
The argument is fallacious, because of line 3 (true does not imply false)!
The proof for Inverse error is similar and left for the reader.
E 5.6. Suppose that none of a or b is even, therefore there exist c, d ∈ Z s.t. a = 2c+1
and b = 2d + 1, whose product is ab = (2c + 1)(2d + 1) = 4cd + 2c + 2d + 1.
As the latter number is odd, and there was no error in the proof, the only problem
seems to have been the initial assumption. This proves that either a or b is even.
E 5.7. (i) For this to happen one can split the balls into 3 holes containing balls of
the same colour. We surely have a repetition if we extract 4 balls.
(ii) In worst case scenario all the balls of two colours have been extracted, but
just one of the remaining colour. The minimum number of balls is then
7 + 5 + 2 = 16.
Supplementary Problems
(i) Defining p: “apple is ripe” and q: “apple is sweet” the proposition becomes
p ⇒ q; p
q (Modus Ponens, true)
(ii) For p: “go to the pub”, q: “finish my revision” and r: “do well in the exam” we
have
p ⇒ ¬q; ¬q ⇒ ¬r ; p
p ⇒ ¬r (true)
5.4 Problem Answers 43
¬q ⇒ p; ¬ p ⇒ q
¬q ∨ ¬ p (false)
(iv) For p: “Sam is studying maths”, q: “Sam is studying economics” and r: “Sam is
required to take logic” the argument is written as
p ∨ q; p ⇒ r
q ∨ ¬r (false)
p ⇒ q; q
p (Converse Error, false)
S 5.6. Suppose this proposition is false. This conditional statement being false means
there exist numbers a and b for which a, b ∈ Z is true but a 2 − 4b = 3 is false. Thus
there exist integers a, b ∈ Z for which a 2 − 4b = 3, or equivalently a 2 = 4b + 3
(odd). This shows that a is odd, so there is c ∈ Z s.t. a = 2c + 1. From the equation
we obtain that a 2 = (2c + 1)2 = 4c2 + 4c + 1 = 4b + 3, which can be written as
c2 + c − b = 21 .
S 5.7. Since six numbers have to be selected, the Pigeonhole Principle guarantees that
at least two of them are selected from one of the five sets {1, 9}, {2, 8}, {3, 7}, {4, 6},
{5, 5}, and therefore their sum is 10.
Chapter 6
Vectors and Complex Numbers
Abstract A vector is a geometric object that has magnitude (or length) and direction
and can be added to other vectors or multiplied by a scalar. Vectors play an important
role in many branches of science, such as physics or engineering. They allow us
to represent the position of objects in two, three or more dimensions and to store
complex data having multiple components, such as velocity, temperature, pressure,
etc. In this chapter we define vectors and their basic operations, such as addition,
multiplication by a scalar, dot and cross products, together with some direct applica-
tions. The complex numbers in algebraic (vectors having one real and one imaginary
component in the Argand diagram) and polar (vectors having radius and argument)
form of are then presented, along with some of key operations and results.
In this section are presented notions about vectors and complex numbers.
Vectors
−
→ −→
a , a , AB, a, â
a = (a1 , a2 , a3 ), a = (ax , a y , az ), a = [ax , a y , az ]
• Equality: Two vectors are equal if they have same modulus and direction.
• Zero vector: 0 = (0, 0, 0) ∈ R3 (3D) or 0 = (0, 0) ∈ R2 (2D)
• Unit vectors: a. Sometimes denoted by â.
• Addition:
−→ −→ −→
– AB + BC = AC (triangle rule for geometric vectors)
– Let a = (a1 , a2 , a3 ) and b = (b1 , b2 , b3 ) be two vectors. Their sum is
a + b = (a1 + b1 , a2 + b2 , a3 + b3 ).
• Subtraction: a − b = a + (−1)b.
• Polygon addition rule: Let A, B, C, D be points in plane (space). Then
−→ −→ −→ −→
AB + BC + C D + D A = 0. (same is true for a polygon A1 , . . . , An )
Centre of Mass
a · b = a1 · b1 + a2 · b2 + a3 · b3
= ab cos θ
√
a = a · a = a12 + a22 + a32
a·b
cos θ =
ab
θ = π/2 ⇔ cos θ = 0 ⇔ a · b = 0
a = aâ
i × j = k; j × i = −k
j × k = i; k × j = −i
k × i = j; i × k = −j
i×i=j×j=k×k =0
a = (a1 , a2 , a3 ) = a1 i + a2 j + a3 k.
b = (b1 , b2 , b3 ) = b1 i + b2 j + b3 k.
a × b = (a1 i + a2 j + a3 k) × (b1 i + b2 j + b3 k)
= (a2 b3 − a3 b2 )i − (a1 b3 − a3 b1 )j + (a1 b2 − a2 b1 )k
S = a × b
a × b
sin θ =
ab
θ = 0 ⇔ sin θ = 0 ⇔ a × b = 0
Complex Numbers
A complex number√can be expressed in the form a + bi, where a and b are real
numbers and i = −1 is the imaginary number representing the solution of the
equation x 2 + 1 = 0 (the notation j is used in Engineering) (Fig. 6.1).
Notation
z = a + bi, a, b ∈ R (algebraicform)
z = re iθ
= r (cos θ + i sin θ ) r, θ ∈ R (polar form)
a = (z) = r cos θ (real part)
b = (z) = r sin θ (imaginary part)
r = |z| = a 2 + b2 (modulus)
θ ∈ [0, 2π ) (argument)
Modulus Property
z1 + z2 = z1 + z2
z1 z2 = z1 z2
z 1 /z 2 = z 1 /z 2
1
(z) = (z + z),
2
1
(z) = (z − z)
2i
50 6 Vectors and Complex Numbers
• Substraction:
z 1 z 2 = (a + bi)(c + di)
= ac + adi + bci + bdi 2
= (ac − bd) + (ad + bc)i
z1 a + bi (a + bi)(c − di)
= =
z2 c + di (c + di)(c − di)
ac + bd bc − ad
= 2 + 2 i
c +d 2 c + d2
(1) z 1 + z 2 = 4 − 2i;
(2) z 1 − z 2 = 2 + 6i;
(3) z 1 z 2 = 11 − 10i;
√
(4) |z 1 | = 32 + 22 = 13;
5 14
(5) z 1 /z 2 = − + i.
17 17
De Moivre’s formula
For the natural number n ≥ 2 and z = r eiθ = (cos θ + i sin θ ) we have
E 6.1. Decide which of the following are vector quantities: Velocity, mass, acceleration,
weight, area, temperature, force, potential energy, volume.
E 6.2. In a system of vectors , a force of 10 newtons is represented by a line 5cm
long. Find the magnitude of the force vector represented in the system by a line 2cm
long.
E 6.4. (i) Evaluate the dot products of the following pairs of vectors:
(a) p = 2i − 3j + k, q = 3i + 4j − 3k
(b) m = 2i − 3j + 5k, l = 3i + 2j − 2k
(c) v = i + 2j + 2k, u = −2i − j + 2k
(ii) Use the definition of the dot product and your answers to part (i) to deter-
mine the angles between the pairs of vectors in part (i).
(iii) For each pair in (i), find a vector perpendicular on both vectors.
(a) p = 2i − j + k, q = 3i + 4j − k
(b) a = i + 2j − 3k, b = −2i + 4j + k
(c) r = i + 2j − 3k, s = 2i + j + 3k.
S 6.6. Answer same questions as in S 6.5. (i)–(iii), when masses 1, 2, 3 and 4 kg are
attached to A, B, C and D, respectively.
S 6.7. Compute the following expressions:
(i) (1 + i) + (3 − 4i); (ii) 1+i
1−i ; (iii) i
2012 ; (iv) i 2013 ; (v) i 2014 ; (vi) (1 + i)2013 .
Essential Problems
E 6.1. Vectors: velocity, acceleration, force.
E 6.2. 4 newtons. √ √ √ √
E 6.3. (i) a = 29; b = 21; c = 18; d = 13;
(ii) û = √1 (i − 2j + 4k); v̂ = √2 (0.5i + 2j − k); ŵ = √1 (i − 2j);
21 21 5
(iii) c ⊥ u: x = −2; c ⊥ v: x = −2; c ⊥ w: x=2.
E 6.4. (i) (a) p · q = −9; (b) m · l = −10; (c) v · u = 0.
(ii) (a) cos θp,q = √ −9
√ ; (b) cos θm,l = √ −10
√ ; (c) cos θv,u = 0.
14 34 38 17
(iii) In each case we have to find a vector a = (x, y, z) s.t.
(a) a · p = a · q = 0. Solution: a = (t, 9/5t, 17/10t), t ∈ R.
(b) a · m = a · l = 0. Solution: a = (t, −7/2t, −16/13t), t ∈ R.
(c) a · v = a · u = 0. Solution: a = (t, −t, 1/2t), t ∈ R.
E 6.5. (a) p×q = −3i +5j+11k; (b) a ×b = 14i +5j+8k; (c) r ×s = 9i −9j−3k.
√
E 6.6. (1) 5 − i; (2) −1 + 7i; (3) 18 + i; (4) 13; (5) (−6 + 17i)/25; (6)
−1 − i; (7) −6 + 17i; (8) 25; (9) −46 + 9i; (10) 119 − 12i.
Supplementary Problems
−→ −→ −→ −→ −→
S 6.1. (i) AC; (ii) AD; (iii) AC; (iv) B D; (v) D B.
−→ −→ −→ −→ −→
S 6.2. AB = b − a; BC = a + b; C D = a − 3b; AC = 2b; B D = 2a − 2b.
−→ −→ −→ −→
S 6.3. (i) AB = (6, 2);(ii) AC = (9, 11); (iii) AD = (7, 1); (iv) B D = (1, −1).
−→ −→
S 6.4. The two diagonals are perpendicular if the dot product is zero, i.e. AC · B D = 0.
−→ −→
However, in this case the dot product is AC · B D = 9 · 1 + 11 · (−1) = −2 = 0,
which shows that the two vectors are not perpendicular. The cosine of the angle can
obtained from the formula
−2 −1
cos θ−
→ −→ = √
AC, B D
√ =√ .
202 2 101
S 6.5. (i) Using the formula for the centre of mass one obtains
−→ −→ −→ −−→
−−→ O A + O B + OC + O D
OG = ,
4
therefore G(6, 5).
(ii) The centres are G A = ( 22
3 , 3 ), G B = ( 3 , 5), G C = (5, 3 ), G D =
19 19 8
3 , 6).
( 16
54 6 Vectors and Complex Numbers
(iv) Let n ≥ 4 be a natural number and let the polygon A1 (a1 , b1 ), . . . , An (an , bn )
have the center of mass G. For the polygons Ai , i = 1, . . . , n (obtained
by deleting the i-th vertex from the original polygon) having centre of
mass G i the following property holds: the centre of mass G 0 of the points
G 1 , . . . , G n coincides with the center of mass G.
S 6.6. In this case the weighted formula for the center of mass yields
1(2, 1) + 2(5, 5) + 3(9, 12) + 4(8, 2) 71 55
Gw = )= , .
4 4 4
√
S 6.7. (i) 5 − 3i; (ii) i; (iii) 1; (iv) i; (v) −1; (vi) 1 + i = 2eiπ/4 therefore
√ 2013 i 2013π √ 5π
(1 + i)2013 = 2 e 4 = 2 2013 e i(126·2π + 4 )
√ 5π 5π √
= 2 2013 (cos + i sin ) = 2 2013 (−1/2 − i/2).
4 4
S 6.8. Applying the normal quadratic formula one obtains the solutions
√ √
(i) z 1,2 = −4± 2·1
42 −4·2
= −2 ± 2 ∈ R (both solutions are real).
√ √
(ii) z 1,2 = −2± 2·1
22 −4·4
= −1 ± 3i ∈ C \ R (both solutions are complex).
√
−2± 22 −4·5
(iii) z 1,2 = 2·1 √ = −1 ± 2i ∈ C \ R (both solutions are complex).
−(1−4i)± (1−4i) −4i·(4i−1)
2 √
(iv) z 1,2 = 2·i = 21 (4 + i) ± 4i − 1 .
b1,2 = 1/a1,2 .
S 6.10. Let z = a + bi. By amplification with z + 1 one obtains
Matrix Notation
Special Matrices
• The zero matrix: all its elements are zero. The zero 2 × 2 matrix is
00
0=
00
• Diagonal matrix: Square, elements outside the main diagonal are zero.
⎡ ⎤
−1 0 0
−1 0
A= , B = ⎣ 0 3 0⎦ , . . .
0 2
0 07
ab
• Inverse (2 × 2 matrix): The inverse of matrix A = is
cd
−1 1 d −b
A =
|A| −c a
2x + 3y = 13
3x + 4y = 18
The solution is
x −1 4 −3 13 2
= x = A b = (−1) =
y −3 2 18 3
E 7.2. Indicate whether the following statements are true or false, for the matrices
below
531
(a) A = , (b) B = 5 3 1 ,
213
12 32
(c) C = 10/2 6/2 1 , (d) D = , (e) E = .
23 21
53
E 7.5. Find the determinant of the matrix , and find its inverse.
42
Use the result to solve the pair of simultaneous equations
5x + 3y = 19
4x + 2y = 14
Compute (i) AB; (ii) AC; (iii) CA. Show that AC = CA, therefore matrix
multiplication is generally not commutative.
What is the connection between the results for parts (ii) and (iii) above?
S 7.2. Consider the matrices defined below
⎡ ⎤ ⎡ ⎤
23 4 2
C = ⎣4 2⎦ and D = ⎣3 1⎦.
31 2 3
What does this suggest about the multiplication by the identity matrix?
S 7.4. Evaluate the result of the operations
(i) AT ; (ii) AAT ; (iii) AT A; (iv) AA and
531
(v) AT AT for the matrix A = . In general, if A is an m × n matrix, what
213
can you say about the size of matrices AAT and AT A?
S 7.5. Given the following matrices
⎡ ⎤
1
01 232
⎣ ⎦
A= 531 , B= 2 , C= , D= .
23 521
3
7.3 Supplementary Questions 61
State the size of the following products and compute the ones that exist.
(i) AB; (ii) BA; (iii) CD; (iv) DB; (v) DC; (vi) BD; (vii) A2 ; (viii) C2 .
S 7.8. State the reason why the inverse matrix method cannot be applied to the
system
4x + 6y = 12
2x + 3y = 14
Essential Problems
E 7.1. (a) 2 × 3; (b) 3 × 2; (c) 1 × 2; (d) 3 × 1.
E 7.2. (a) F; (b) F; (c) T; (d) F; (e) F.
542 4 1 −2 10 6 2
E 7.3. (i) A + C = ; (ii) A − B = ; (iii) 2A = ;
445 −2 −2 1 4 26
⎡ ⎤
14
0 −3 −3 3 3 −1
(iv) −3C = ; (v) A − 2B + 4C = ; (vi) BT = ⎣2 3⎦;
−6 −9 −6 27 7
32
(vii) operation not defined.
E 7.4. (i) row matrix: 13 21 ; (ii) row matrix: 16 22 19 ;
62 7 Matrices and Applications
⎡ ⎤
5 10 20
16
(iii) column matrix: ; (iv) square matrix: ⎣3 6 12⎦ .
13
1 2 4
−1 1.5
E 7.5. det A = −2; A−1 = ; x = 2; y = 3.
2 −2.5
⎡ ⎤ ⎡ ⎤ ⎡ ⎤
19 20 24 11 16 12 5 2 5
E 7.6. (i) AB = ⎣12 10 17⎦ ; (ii) AC = ⎣17 11 7 ⎦ ; (iii) CA = ⎣22 11 15⎦.
11 11 17 12 10 7 32 18 13
Supplementary problems
S 7.1. The results are the following
⎡ ⎤
66
⎣ ⎦ 665 665
(i) A + B = 6 3 ; (ii) A + B =
T T
; (iii) (A + B) =
T
.
634 634
54
One can see that AT + BT = (A + B)T , therefore the transpose can be applied at
any stage when adding matrices.
S 7.3. By doing the multiplication one can check that AI = IA = A, which is valid
for any square matrix A and the corresponding identity matrix.
The operations defined in (iv) and (v) are not compatible. For a matrix A of size
m × n, the size of matrix AAT is m × m while the size of matrix AT A is n × n. Also,
one may note that these two matrices are symmetric.
Matrix Representation
• Lines: defined
by two points and represented by a 2 × 2 matrix.
3 −1 3 −1
The matrix represents a line through points and .
2 4 2 4
• Polygons: Represented
by a 2 × n matrix.
3 −1 1 3 −1 1
The matrix represents the triangle , and .
2 4 1 2 4 1
Transformation of Lines
Linear Transformations in 2D
α 0 ∗ x∗ α 0 x αx
T = ; X = ∗ = TX = = .
0β y 0β y βy
Rotation: The line from (0, 0) to the point (x, y), is rotated by an angle θ .
By convention anticlockwise movement is considered positive.
We say that (x, y) has rotated about the origin to (x ∗ , y ∗ ).
cos θ − sin θ
T = .
sin θ cos θ
Reflections
• in the X axis: changes the sign of the y co-ordinate
1 0 1 0 x x
T = ; X∗ = T X = =
0 −1 0 −1 y −y
01 ∗ 01 x y
T = ; X = TX = =
10 10 y x
0 −1 0 −1 x −y
T = ; X∗ = T X = =
−1 0 −1 0 y −x
68 8 Matrix Applications in Computer Graphics
Translations, rotations, scalings or shears are very often combined to generate more
complex transformations. In the language of matrices, this translates into computing
the product of the matrices corresponding to each individual transformation.
If the point X is subject to two consecutive transformations T1 and T2 , then the
composed transformation T = T2 T1 generates the new point
X ∗ = T2 (T1 X ) = (T2 T1 )X = T X.
30
Example: The point (3, 2) is transformed by the scaling , then reflected in Y
02
axis and finally rotated by 45◦ . Find the coordinates of the new point.
Solution: Using the notations
30 −1 0 cos 45◦ − sin 45◦ 1 cos 1 −1
T1 = , T2 = , T3 = = √ ,
02 0 1 sin 45◦ cos 45◦ 2 sin 1 1
E 8.1. A straight line joins the points (3, 2) and (4, 5).
4 2
Describe the transformed line produced by the matrix T = .
3 −1
8.2 Essential Questions 69
E 8.5. Consider the 2D unit square having coordinates (0, 0), (1, 0), (0, 1), (1, 1).
Determine the new co-ordinates of the figure after the transformations:
(1) Translation of vector (1, 2);
(2) horizontal scaling of factor 2;
(3) vertical scaling of factor 3;
(4) mixed scaling of factors 3 and 4;
(5) Rotation of angle π/6;
(6) Rotation of angle 90◦ ;
(7) Reflection in the X axis;
(8) Reflection in the Y axis;
(9) Reflection in the y = x line;
(10) Reflection in the y = −x line.
E 8.6. Point (2, 3) is reflected in Y axis, then reflected in y = x, and then rotated by
90◦ . Find the co-ordinates of the final point.
S 8.1. Show that any rotation matrix R has the property R T = R −1 (i.e. the transpose
of a rotation matrix is equal to its inverse).
S 8.2. Let R be the rotation matrix about the origin through angle θ .
(a) State the rotation matrix S for a clockwise rotation through an angle θ .
(b) Calculate R −1 using the result of problem S 8.1. above.
(c) What can be concluded from parts (a) and (b) above.
S 8.3. Write down transformation matrices which will:
70 8 Matrix Applications in Computer Graphics
(a) scale vertical lines by a factor of 5 and leave horizontal lines unchanged.
(b) scale horizontal lines by a factor of 4 and vertical lines by a factor 0.25.
(c) Use the above matrices to find the new co-ordinates of the points (2, 1) and
(−2, −1), performing each transformation separately.
S 8.4. Point A(2, −1) is reflected in X axis, then rotated by 90◦ and finally reflected
in y = −x. Find the co-ordinates of the final point.
S 8.5. Find the coordinates of the unit square defined in E 8.5., subject to the shear
transformations
given by the matrices:
13 10 12 23
(a) T = ; (b) T = ; (c) T = ; (d) T = .
01 21 31 45
Essential Problems
34 4 2 34 16 26
E.8.1 The first line is . The transformed line is = .
25 3 −1 2 5 7 7
30 50
E 8.2. (a) T = ; (b) T = .
01 02
√
1 cos 45◦ − sin 45◦ 3 2
E 8.3. The new point is given by: T = = √ .
3 sin 45◦ cos 45◦ 1 2 2
Supplementary Problems
cos θ − sin θ
S 8.1. The transformation matrix for a rotation of angle θ is R(θ ) = ,
sin θ cos θ
whose inverse is the rotation of angle −θ , which satisfies
cos(−θ ) − sin(−θ ) cos θ sin θ
R(−θ ) = = = R(θ )T ,
sin(−θ ) cos(−θ ) − sin θ cos θ
72 8 Matrix Applications in Computer Graphics
1 0 0 −1 0 −1
T1 = , T2 = , T3 =
0 −1 1 0 −1 0
Abstract Graphs are mathematical structures used to model and visualize relations
between certain objects. One of the first formulations of a graph theory problem was
the famous Konigsberg Problem solved by Leonhard Euler. He proposed a model
which reduced the problem to a schematic diagram and then concluded that the graph
needed to satisfy some general conditions for the problem to be solved affirmatively.
His studies highlighted the importance of understanding graphs and their properties,
which later lead to the creation of Graph Theory as a distinct mathematical discipline.
In this chapter we first introduce graphs through some illustrative examples and then
describe the basic elements of graphs, as well some important graph properties.
We then present special types of graphs like trees or networks, together with some
specific techniques, problems and algorithms.
Special Graphs
• directed: Some edges have a direction.
• connected: It is possible to reach any node from any node
• complete: Simple, undirected, arcs between all nodes (Notation: K n )
• planar: It can be drawn so that the arcs do not cross
• simple: A graph with no loops or multiple arcs
• tree: Simple graph with no cycles
9.1 Brief Theoretical Background 75
• spanning tree (for a connected, undirected graph): subgraph that is a tree and
connects all the vertices together.
• network: A graph with weighted arcs (could be distance, cost, time).
Adjacency matrix: For a graph G with n vertices this is a n × n matrix s.t.
• non-diagonal entry ai j : number of edges from vertex i to vertex j
• diagonal entry aii : number of edges from vertex i to itself taken once for directed
graphs or twice for undirected graphs
Example: For the graph depicted in the previous page we have
1 2 3 4 5 6
1 2 1 0 0 1 0
2 1 0 1 0 1 0
3 0 1 0 1 0 0
4 0 0 1 0 1 1
5 1 1 0 1 0 0
6 0 0 0 1 0 0
For tree t in (a) below, R O OT (t) = 6, L E F T (t) is tree (b) while R I G H T (t) = 2.
For t and r trees in BT R E E(X ) and s ∈ X one can define the function:
• MAKE: BT R E E(X ) × X × BT R E E(X ) → BT R E E(X ); (t, s, r ) → u
This output u is a tree with left branch t, root s and right branch r .
76 9 Elements of Graph Theory
Network problems
Networks can be represented using diagrams or a distance matrix.
a b c d e
a 0 1 1 0 1
(i) b 1 0 1 1 1
c 1 1 0 0 0
d 0 1 0 0 1
e 1 1 0 1 0
a b c d e
a 0 1 0 0 1
(ii) b 1 0 1 1 0
c 0 1 1 1 0
d 0 1 1 0 1
e 1 0 0 1 1
a b c d e
a 0 1 0 0 1
(iii) b 0 0 0 0 0
c 0 0 0 0 0
d 0 0 0 0 1
e 0 0 0 0 0
(b) Which if any of the graphs in E 9.2. have the following properties: con-
nected, complete, directed, undirected, contain a cycle, contain a loop, is
a tree, contains a vertex which is even, contains a vertex which is odd?
E 9.4. In a group of people John likes Mary, Brian and Emma; Brian likes Mary and
Sue; Mary likes John and Sue; Emma likes Mary, John and Brian; Sue likes nobody.
Draw a graph showing who likes who.
E 9.5. Given the trees p and q from BTREE (BIRDS) defined below
A B C D E F G
A – 10 5 4 3 – –
B 10 – 8 9 7 – 2
C 5 8 – – 5 – –
D 4 9 – – 10 6 4
E 3 7 5 10 – 8 9
F – – – 6 8 – 11
G – 2 – 4 9 11 –
Essential problems
E 9.1. Each arc contributes with 2 to the sum of degrees, therefore this sum should
be twice the number of arcs.
E 9.2. Draw the vertices {a, b, c, d, e} and directed segments from x to y if (x, y) = 1
in each of the adjacency matrices.
E 9.3. We write down the directed segments corresponding to each matrix
(i) G 1 = {(a, b), (a, c), (a, e), (b, a), (b, c), (b, d), (b, e), (c, a), (c, b), (d, b),
(d, e), (e, a), (e, b), (e, d)};
(ii) G 2 = {(a, b), (a, e), (b, a), (b, c), (b, d), (c, b), (c, c), (c, d)(d, b), (d, c),
(d, e)(e, a), (e, d), (e, e)};
(iii) G 3 = {(a, b), (a, e), (d, e)}.
E 9.4. The adjacency matrix is
to draw a segment. This step is repeated with the addition of any new node and in
the end one obtains exactly n − 1 edges.
S 9.2. In a complete graph each vertex is connected to all the others. This means that
in total we have n(n − 1) edges. As using this formula
each node was counted twice,
the total number of edges has to be n(n − 1)/2 or n2 .
S 9.3. Let G be any finite simple graph with n = 2 vertices. The maximal degree of
any vertex in G is less than equal to n − 1. Also, if our graph G is not connected,
then the maximal degree is strictly less than n − 1.
Case 1: Assume that G is connected. We can not have a vertex of degree 0 in G, so
the set of vertex degrees is a subset of S = {1, 2, , n − 1}. Since the graph G has n
vertices, by pigeon-hole principle we can find two vertices of the same degree in G.
where p1 < p2 < ... < pk are primes and ai are positive integers.
ϕ( p) = p − 1
ϕ(mn) = ϕ(m)ϕ(n).
Modular Arithmetic
System of arithmetic for integers (clock arithmetic), where numbers “wrap around”
upon reaching a certain value called modulus.
Caesar Cypher
• Alphabet: A = {A, . . . , Z } so n = 26 (or numbers 0.25).
• m and c are single characters
• encrypt key e ∈ {0, . . . , 25}
• encrypt equation: c = f (e, m) = m + e (mod 26)
• decrypt equation: m = g(d, c) = c + d (mod 26) ( f = g)
• clearly d + e = 0 (mod 26) (both need to be kept secret!)
• Method:
plaintext : A, B, C, D, . . .
cypher text : D, E, F, G, . . .
This is an efficient algorithm which uses the properties of large primes, as well as
Euler’s totient function to produce encryption and decryption key.
The RSA algorithm involves: Key generation, Encryption, Decryption.
John sends his public key (n, e) to Ana and keeps the private key secret. Ana then
sends message M to John. She first turns M into an integer m s.t. 0 ≤ m < n by
using a padding scheme (agreed-upon reversible protocol). She then computes the
cyphertext corresponding to
c = m e (mod n).
m = cd (mod n).
E 10.6. Find the ϕ(n) function for the numbers n = 11, 21, 24, 36, 49, 81, 100.
E 10.7. Code the message “NOBLI EXS” using a Caesar cipher of key e = 16.
86 10 Elements of Number Theory and Cryptography
S 10.9. Find the ϕ(n) function for the numbers n = 19, 31, 28, 48, 144, 169, 1001.
S 10.10. Find the RSA key d for the public key e = 5, for n = 65.
Essential Problems
E 10.1. (3, 4, 5), (5, 12, 13), (7, 24, 25), ( 8, 15, 17), ( 9, 40, 41).
E 10.2. The factorisations are
96 = 25 · 31 ; 144 = 24 · 32 ; 286 = 2 · 11 · 13; 777 = 3 · 7 · 37; 1001 = 7 · 11 · 13.
E 10.3. The greatest common divisors are
gcd(96, 144) = 24 · 3 = 48; gcd(1001, 777) = 7; gcd(1001, 286) = 11 · 13 = 143.
E 10.4. The least common multiples are
lcm(96, 144) = 25 · 32 = 288; lcm(1001, 777) = 3 · 7 · 11 · 13 · 37 = 111111;
lcm(1001, 286) = 2 · 7 · 11 · 13 = 2002.
E 10.5. The modulo operations give the following results:
10.4 Problem Answers 87
E 10.6. One has to factorise the numbers and apply the multiplicity of ϕ(n).
ϕ(11) = 10;
ϕ(21) = ϕ(3 · 7) = ϕ(3) · ϕ(7) = 2 · 6 = 12;
ϕ(24) = ϕ(23 · 3) = ϕ(23 ) · ϕ(3) = 4 · 2 = 8;
ϕ(36) = ϕ(22 · 32 ) = ϕ(22 ) · ϕ(32 ) = 2 · 6 = 12;
ϕ(49) = ϕ(72 ) = 49(1 − 1/7) = 42;
ϕ(81) = ϕ(34 ) = 81(1 − 1/3) = 54;
ϕ(100) = ϕ(22 · 52 ) = ϕ(22 ) · ϕ(52 ) = 2 · 20 = 40.
Supplementary Problems
4 = 2 + 2; 6 = 3 + 3; 8 = 3 + 5; 10 = 3 + 7; 12 = 5 + 7; 14 = 3 + 11;
18 = 5 + 13; 20 = 3 + 17; . . . ; 96 = 7 + 89; 98 = 19 + 79; 100 = 3 + 97.
(3, 5), (5, 7), (11, 13), (17, 19), (29, 31), (41, 43), (59, 61), (71, 73), (101, 103).
S 10.4. The first five Mersenne primes are 3, 7, 31, 127, 8191.
S 10.5. The prime factorisations are
gcd(1440, 968) = 23 = 8;
gcd(1002, 703) = 1;
gcd(2261, 1547) = 7 · 17 = 119;
gcd(779, 1763) = 41.
lim f (x) = L ,
x→ p
Continuous Functions
A function f : R → R is continuous if
• for every point x and convergent sequence xn → x we have f (xn ) → f (x).
• the graph is a single unbroken curve with no "holes" or "jumps".
The intermediate value theorem: If f is continuous on [a, b] and f (a) f (b) < 0
then there is c ∈ [a, b] s.t. f (c) = 0.
Examples: Polynomials, exp, sin, cos are all continuous functions.
The cubic in Fig. 11.1a crosses line y = 0 between −2 and 0, changing sign.
Signum (has the values ±1) (Fig. 11.1b) changes sign but is not continuous.
The Derivative
f (x + h) − f (x)
f (x) = lim
h→0 h
Let the function f defined on [a, b]. The definite integral denoted by
b
f (x) d x
a
Remark: The integral may not exist in general (for example, functions which have
singularities, such as f : [0, 1] → R, f (x) = 1/x), but it does exist when the
function f defined on [a, b] is continuous!
Fundamental theorem of calculus (FTC): If f is a continuous real-valued function
defined on [a, b] and a function F : [a, b] → R s.t. F (x) = f (x), then the definite
integral of f over [a, b] is
b
f (x) d x = F(b) − F(a)
a
E 11.2. Prove that f (x) = 2x 2 + 2x − 5 has a root in [1, 2] and [−3, −2].
E 11.3. Prove that the cubic f (x) = 2x 3 + 2x 2 − 3 has a root x0 ∈ [0, 1].
E 11.4. Differentiate the functions: (1) f (x) = 2x + 1; (2) f (x) = 2x 2 + 3.
E 11.5. Integrate: (1) f (x) = 1; (2) f (x) = 2x + 3; (3) f (x) = 2x 2 + 3.
2
E 11.6. Evaluate 0 f (x)d x for f (x) = x 2 + 2 using the FTC.
E 11.7. Find the area between the curves f (x) = −x 2 + 6x − 2, g(x) = 2x + 1.
11.3 Supplementary Problems 93
2n 2n
(1) xn = ; (2) xn = (−1)n ;
n−4 n!
√ √
(3) xn = n 2 − 5n; (4) xn = n + 1 − n.
S 11.2. How many roots does the cubic f (x) = 8x 3 + 12x 2 − 2x − 3 have?
S 11.3. Prove that f (x) = x 2 − 3 cos π2 x + 2 has a root x0 ∈ [0, 1].
S 11.4. Differentiate the function f (x) = 2x 3 + 7x + 3.
S 11.5. Integrate: (1) f (x) = 2x + 7 cos(x) + 3 sin(x); (2) f (x) = 2x 3 + 1.
Essential problems
E 11.1. (1) 0; (2) 0; (3) 0; (4) 0; (5) 1; (6) 23/99; (7) 423/990.
E 11.2. f (1) f (2) = (−1)7 < 0; f (−3) f (−2) = (7)(−1) < 0.
E 11.3. f (0) f (1) = (−3)1 < 0.
E 11.4. (1) f (x) = 2; (2) f (x) = 4x.
E 11.5. (1) f (x)d x = x + C; (2) f (x)d x = x 2 + 3x + C; (3) f (x)d x =
2x 3
3 + 3x + C.
3
E 11.6. F(x) = f (x)d x = x3 + 2x + C. The integral is therefore given by
2
f (x)d x = F(2) − F(0) = 8/3 + 4 + C − C = 20/3.
0
Supplementary problems
S 11.1. (1) 2; (2) 0; (3) ∞; (4) 0.
S 11.2. f (−2) = −11; f (−1) = 3; f (0) = −3; f (1) = 15. We have f (−2) f (−1)
< 0, f (−1) f (0) < 0 and f (0) f (1) < 0.
S 11.3. f (0) f (1) = (−1)3 < 0.
S 11.4. f (x) = 6x 2 + 7.
S 11.5. (1) f (x)d x = x 2 + 7 sin(x) − 3 cos(x); (2) f (x)d x = x 4 /2 + C.
√
S 11.6. (a) 45.00; (b) 125/6 = √ 20.83; (c) x1 = 1/6(15 − 65) = 1.15, √x2 =
√ 1/6(15+ 65)
1/6(15 + 65); (d) √ (−10(x − 1)(x − 4) + x(x − 5))d x = 651865 ∼
1/6(15− 65)
29.1137.
Chapter 12
Elementary Numerical Methods
Abstract Very often in real applications, one has to solve some complicated
equations, where a formula for the result is either impossible to obtain, or it is
too complicated for any practical use. In this case one has to rely on a wide range of
numerical methods, which very often represent approximations to the real results.
These methods are very important in practice and usually offer both an algorithm
generating increasingly exact approximations and an approximation for the error. In
this chapter we shall discuss the Lagrange polynomial for interpolation data given
by a table of values, basic iterative methods used for the numerical integration of
real functions and some iterative methods for root finding.
In this section we present the basic basic notions regarding polynomial interpolation,
numerical integration and root finding algorithms.
Polynomial Interpolation
When working with data on given by (x, y) coordinates, it is often required to find
a curve passing through multiple points. Polynomials are usually the first choice for
such a curve, as they are smooth, easy to work with and have a formula. The basic
idea of the Lagrange polynomial is to fit a minimum degree polynomial to a set of
points.
Lagrange Polynomial
For n ≥ 2 and a set of points P1 (x1 , y1 ), P2 (x2 , y2 ), . . . , Pn (xn , yn ) s.t. x1 < x2 <
· · · < xn one can find a polynomial function L(x) of degree n − 1 passing through
the points P1 , . . . , Pn (i.e. L(x1 ) = y1 , L(x2 ) = y2 , . . . , L(xn ) = yn ).
Examples: Given the points P1 (1, 2), P2 (2, 5) and P3 (3, 3) we can:
1. Find a polynomial passing through point P1 .
Solution: This could be any polynomial L(x) for which L(1) = 2. The polynomial
of minimum degree is the constant polynomial L(x) = 2.
2. Find a polynomial passing through points P1 and P2 .
Solution: The interpolating polynomial is:
x −2 x −1
L(x) = 2 · +5·
1−2 2−1
= −2(x − 2) + 5(x − 1) = 3x − 1.
x −2 x −3 x −1 x −3 x −1 x −2
L(x) = 1 · · +5· · +3· ·
1−2 1−3 2−1 2−3 3−1 3−2
= −3x 2 + 13x − 9.
which satisfy
1, x = x j
L j (x) =
0, x ∈ {x1 , . . . , xn } \ {x j }.
The degree of the polynomial is justified by the fact that a polynomial of degree n − 1
depends on n coefficients, equal to the number of available points.
Numerical Integration
The problem of finding the area between the graph of the function f : [a, b] → R
b
and the horizontal axes was linked in Chap. 11 to evaluating the integral a f (x)d x.
However, in real applications the functions to be integrated are very complicated or
the function might be known at some discrete points of the interval [a, b]. In such
cases, the area is approximated by numerical integration methods.
12.1 Brief Theoretical Background 97
Fig. 12.1 Approximations for f (x) = x 2 sin x using (a) N = 1; (b) N = 4 intervals
Trapezium rule
The graph of function f : [a, b] → R is approximated by a linear function (Fig. 12.1)
b f (a) + f (b)
f (x) d x ≈ (b − a)
a 2
h
b N
I = f (x) d x ≈ TN = ( f (xk−1 ) + f (xk ))
a 2
k=1
b−a
= ( f (x0 ) + 2 f (x1 ) + 2 f (x2 ) + . . . + 2 f (x N −1 ) + f (x N )).
2N
Error bound: The absolute error E TN of this approximation is bounded by
(b − a)h 2 (b − a)3
E TN = |I − TN | ≤ M= M (M = max | f (ξ )|).
12 12N 2 ξ ∈[a,b]
Number of intervals needed: If the desired accuracy is ε (say 0.01) the number of
intervals needed satisfies the inequality
(b − a)3 M
N≥ .
12ε
98 12 Elementary Numerical methods
2
Example: Evaluate the integral 0 f (x)d x for f (x) = x 2 + 2 using the trapezium
rule for N = 2, 4 intervals. What is the minimum value of N which ensures an
accuracy of ε = 0.01?
Solution: When N = 2 we have h = 2/2 = 1 and the formula gives
1 1
T2 = ( f (0) + 2 f (1) + f (2)) = (2 + 2 · 3 + 6) = 7.
2 2
When N = 4 we have h = 2/4 = 1/2 and the formula gives
1 1 3
T4 = ( f (0) + 2 f + 2 f (1) + 2 f + f (2))
4 2 2
1 9 17
= (2 + 2 + 2 · 3 + 2 + 6) = 27/4.
4 4 4
x3
The antiderivative of f is F(x) = f (x)d x = 3 + 2x + C therefore
2
I = f (x)d x = F(2) − F(0) = 8/3 + 4 + C − C = 20/3.
0
2·12
For N = 2, h = (b − a)/N = 1, so E B2 = 12 · 2 = 1/3.
2
For N = 4, h = (b − a)/N = 0.5, so E B2 = 2·0.5
12 · 2 = 1/12.
As f (x) = 2 (so M = 2), the number N of intervals required is given by the
formula
(2 − 0)3 · 2
N≥ ∼ 11.53, therefore N = 12.
12 · 0.01
f (x) = x 2 − 4x + 3
f (x) = x 3 − 4x + 3
f (x) = sin(3x) − sin(x)
f (x) = e x − 5 sin(3x) + x 2
The usual starting point is to plot the graph of the function and then guess...
Corollary of the intermediate value theorem If f is continuous on [a, b] and
f (a) f (b) < 0 then there is c ∈ [a, b] s.t. f (c) = 0.
– Compute ck = ak +b 2 .
k
log(1.5) − log(0.002)
n≥ = 9.5507 =⇒ n = 10.
log 2
Newton’s Method
This is an often used method, with good accuracy and having the elements
• Starting point: x0 (the choice of this point is important)
• Iteration:
f (xn )
xn+1 = xn −
f (xn )
2xn2 + 4xn − 1
xn+1 = xn − ,
4xn + 4
Polynomial Interpolation
E 12.1. Find the Lagrange polynomial interpolating the data
x1 = 1 x2 = 2
y1 = 1 y2 = 3
x1 = 1 x2 = 2 x3 = 3
y1 = 1 y2 = 2 y3 = 5
Numerical Integration
2
E 12.3. Evaluate 0 f (x)d x for f (x) = x 2 + 2 using N = 2 or 4 trapeziums.
2
E 12.4. Evaluate the integral 0 f (x)d x for f (x) = x 3 + 4x 2 − 5x − 2 exactly and
by the trapezium rule for 2, 4 and 8 intervals. What can you notice?
1
E 12.5. Evaluate the integral 0 f (x)d x for f (x) = 4x 2 − 5x − 2 exactly and by
the trapezium rule for N = 2, 4, 8. What is the error in each case?
E 12.6. Evaluate the composite trapezium approximation for the integral
π/2
x 2 cos xdx
0
Root Finding
E 12.7. (Existence of roots)
(a) Find the number of roots for the cubic f (x) = 8x 3 + 12x 2 − 2x − 3.
(b) Prove that f (x) = x 2 − 3 cos π2 x + 2 has a root x0 ∈ [0, 1].
E 12.8. (The bisection algorithm) (a) Apply 4 iterations of the bisection algorithm
(c0 , c1 , c2 , c3 ) to the function
starting from the points (a) x0 = −1; (b) x0 = 2 and find the exact roots.
102 12 Elementary Numerical methods
x1 = 2 x2 = 3
y1 = 1 y2 = 5
x1 = 1 x2 = 3 x3 = 4,
y1 = −5 y2 = −1 y3 = 10,
1
S 12.3. Evaluate the integral −1 f (x)d x for f (x) = x 2 − x + 1 exactly and by
using the trapezium rule for N = 2, 4, 8. Which value of N ensures an accuracy of
0.01? π
S 12.4. Evaluate the integral 0 f (x)d x for f (x) = sin x exactly and by using the
trapezium rule for N = 2, 4, 8. How many intervals N are required for ensuring an
accuracy of 0.01? But for an accuracy of 0.0001?
S 12.5. (Limitations of the bisection algorithm) Apply a few iterations of the bisection
algorithm on the interval [0, 2] to
1
(i) f (x) = ; (ii) g(x) = x 3 − x 2 − x + 1.
x −1
Essential Problems
x −2 x −1
L(x) = 1 · +3· = −(x − 2) + 3(x − 1) = 2x − 1.
1−2 2−1
x −2 x −3 x −1 x −3 x −1 x −2
L(x) = 1 · · +2· · +5· ·
1−2 1−3 2−1 2−3 3−1 3−2
= x 2 − 2x + 2.
12.4 Problem Answers 103
1 1
T2 = ( f (0) + 2 f (1) + f (2)) = (2 + 2 · 3 + 6) = 7.
2 2
When N = 4 we have h = 2/4 = 1/2, and the approximation
1 1 3
T4 = f (0) + 2 f + 2 f (1) + 2 f + f (2)
4 2 2
1 9 17
= 2 + 2 + 2 · 3 + 2 + 6 = 27/4.
4 4 4
6xn2 + xn − 2
xn+1 = xn −
12xn + 1
The analysis suggests that the roots are 1/2 and −2/3 (Table 12.1).
104 12 Elementary Numerical methods
Supplementary Problems
S 12.1. The interpolating polynomial is:
x −3 x −2
L(x) = 1 · +5·
2−3 3−2
= −(x − 3) + 5(x − 2) = 4x − 7.
x −3 x −4 x −1 x −4 x −1 x −3
L(x) = −5 · · + −1 · · + 10 · ·
1−3 1−4 3−1 3−4 4−1 4−3
= 3x 2 − 10x + 2.
1
S 12.3. The exact integral is −1 x 2 − x + 1d x = 83 ∼ 2.666. The approximations
are T2 = 3; T4 = 2.75; T8 = 2.687. The number of required intervals for a 0.01
accuracy is N = 12.
2
S 12.4. The exact integral is 0 sin xd x = − cos x|π0 = 2. The approximations are
T2 = 1.570; T4 = 1.896; T8 = 1.974. N = 17 intervals for a 0.01 accuracy and
N = 161 intervals for 0.0001.
S 12.5. (i) The function changes sign on [0, 2] but the approximations converge to
an asymptote. The method is not reliable because the function is not continuous on
the interval [0, 2].
(ii) The change of sign test is not relevant f (0) f (2) = 3, therefore the method
cannot be applied. The method is not able to pick the root x = 1 (g(1) = 0).
Further Reading
1. Lipschutz, S.: Schaum’s Outline of Theory and Problems of Set Theory and Related Topics,
2nd edn. McGraw-Hill, New York (1998)
2. Lipschutz, S., Lipson, M.: Schaum’s Outline of Discrete Mathematics, 3rd edn. McGraw-Hill,
New Year (2007)
3. Haggerty, R.: Discrete Mathematics for Computing. Addison Wesley, New York (2002)
4. Stroud, K.A., Dexter, J.B.: Foundation Mathematics. Macmillan, London (2009)
5. Tunnicliffe, W.R.: Mathematics for Programmers. Prentice Hall, Englewood Cliffs (1991)
6. Grassmann, W.K., Tremblay, J.P.: Logic and Discrete Mathematics: A Computer Science Per-
spective. Prentice Hall, Englewood Cliffs (1996)
7. Kelly, J.: The Essence of Logic. Prentice Hall, Englewood Cliffs (1997)
8. Neville, D.: The Essence of Discrete Mathematics. Prentice Hall, Englewood Cliffs (1997)
9. Lang, S.: Algebra. Graduate Texts in Mathematics 211, revised 3rd edn. Springer, New York
(2002)
10. Lipschutz, S.: Schaum’s Outline of Theory and Problems of Essential Computer Mathematics.
McGraw-Hill, New York (1982)
11. Marsden, J.E.: Basic Complex Analysis, 2nd edn. W.H. Freeman, New York (1987)
12. Van Verth, J.M., Bishop, L.M.: Essential Mathematics for Games and Interactive Applications:
A Programmer’s Guide, 2nd edn. Elsevier Science, Amsterdam (2008)
13. Wunsch, D.A.: Complex Variables with Applications, 3rd edn. Pearson, Boston (2005)
14. Burton, D.M.: Elementary Number Theory, 7th edn. McGraw-Hill, New York (2011)
15. Churchhouse, R.: Codes and Ciphers. Cambridge University Press, Cambridge (2002)
16. Dangerfeld, J.: Decision 1 for AQA. Pearson Longman, Boston (2005)
17. Goodaire, E.G., Parmenter, M.M.: Discrete Mathematics with Graph Theory. Prentice Hall,
Englewood Cliffs (1998)
18. Hill, R.: A First Course in Coding Theory. Oxford University Press, Oxford (1997)
19. Rivest, R., Shamir, A., Adleman, L.: A method for obtaining digital signatures and public-key
cryptosystems. Commun. ACM 21(2), 120–126 (1978)
20. Spivak, M.: Calculus, 4th edn. Publish or Perish, Houston (2008)
21. Stewart, J.: Calculus. Brooks/Cole, Pacific Grove (2003)
A Deduction rules, 37
Adjacency matrix, graph, 75 Disjunctive normal form, d.n.f, 35
Associative Law, 29 Distributive Law, 29
Domain, 9
B
Bisection method, root finding, 99 E
Boolean values, 27 Edges, graph, 74
Encryption, 84
Euler’s totient function, 82
C
Caesar cypher, 84
F
Cartesian product, 1
Finite set, 3
Centre of mass, 46
Function, 19
Co-domain, 9
Function, bijective, 20
Complete, graph, 74
Function, composition, 21
Complex numbers, 3, 49
Function, continuous, 90
Complex numbers, algebraic, 49
Function, derivative, 91
Complex numbers, conjugate, 49
Function, even, 20
Complex numbers, modulus, 49
Function, injective, 20
Complex numbers, operations, 50
Function, integral, 92
Complex numbers, polar, 49
Function, limit, 90
Conjunctive normal form, c.n.f, 36
Function, odd, 20
Connected, graph, 74
Function, surjective, 20
Contradiction, 28
Fundamental theorem of calculus, 92
Converse error, 37
Cost matrix, network, 75
Cycle, graph, 74 G
Greatest common divisor, 82
D
Database, 12 I
Datatype string, 21 Infinite set, 3
De Moivre’s formula, 50 Integers, 3
De Morgan’s Law, 29 Interpolation, Lagrange polynomial, 96
Decryption, 84 Inverse error, 37
K Prime number, 81
Key, 12 Private key, 84
Kruskal’s algorithm, 75 Proof by contradiction, 38
Proposition, 28
Public key, 84
L
Least common multiple, 82
Linear system of equations, 58 Q
Logical operations, and, 27 Quantifiers, existential, 29
Logical operations, equivalent, 27 Quantifiers, negation, 29
Logical operations, implies, 27 Quantifiers, universal, 29
Logical operations, not, 27
Logical operations, or, 27
Loops, graph, 74 R
Rational numbers, 3
Real numbers, 3
M Reflections, transformation, 68
Many-one, 10 Relations, 9
Matrix, 55 Relations, antisymmetric, 11
Matrix, column, 56 Relations, composition, 11
Matrix, diagonal, 57 Relations, equivalence, 11
Matrix, identity, 57 Relations, image, 10
Matrix, inverse, 58 Relations, intersection, 10
Matrix, row, 56 Relations, inverse, 10
Matrix, square, 56 Relations, reflexive, 11
Matrix, transformation, 66 Relations, symmetric, 11
Matrix, transpose, 57 Relations, total, 11
Matrix,multiplication, 57 Relations, transitive, 11
Modulo congruence, 83 Relations, union, 10
Modus ponens, 37 Relatively prime numbers, 82
Modus Tollens, 37 Root of polynomial, 22
Rotation, transformation, 67
RSA algorithm, 84
N
Network, graph, 74
Newton’s method, root finding, 100 S
Number set, 3 Scaling, transformation, 67
Sentence, 28
Sequence, 89
O Sequence, convergent, 89
One-many, 10 Sequence, divergent, 89
One-one, 10 Sequence, limit, 89
Order, graph nodes, 74 Set, 1
Set cardinal, 3
Set inclusion, 1
P Sets, complement, 2
Path, graph, 74 Sets, difference, 2
Pigeonhole principle, 38 Sets, empty, 1
Planar, graph, 74 Sets, intersection, 2
Polynomials, 4 Sets, symmetric difference, 2
Power set, 1 Sets, union, 2
Predicate, 28 Sets, universe, 1
Prim’s algorithm, 75 Shearing, transformation, 68
Prime factorisation, 81 Shortest path, network, 75
Index 109
V
T Vectors, 46
Tautology, 28 Vectors, addition, 46
Trail, graph, 74 Vectors, dot product, 47
Translation, transformation, 67 Vectors, magnitude, 46
Trapezium rule, 97 Vectors, scalar product, 47
Trapezium rule, composite, 97 Vectors, zero, 46
Trapezium rule, error bound, 97 Venn diagram, 2
Tree, graph, 74 Vertices, graph, 74