This topic provides some basic mathematical definitions. The topic is intended for readers who do not have a mathematical background or readers who need a “brush-up”.
Absolute Value
The absolute value of a number, z, is written as Abs(z) or |z|. It is calculated by deleting the “minus” in front of the number. This means that | —150| = 150. Mathematically the absolute value of a number, z, is calculated as
In terms of programming it can be written as
min and max
The min value of a set of numbers is written as min{xi,x2,—,x«} and simply means the smallest number in the set. For example, min{7, 3, 11,2,42} = 2. The max value of a set of numbers is written as max{x1,x2,…,x„} and simply means the biggest number in the set. For example, max{7, 3, 11, 2,42} = 42. In terms of programming the max operation can be written as follows, where we assume that N numbers are present in the list and that they are stored in list[]:
Table B.1 Different rational numbers and three different ways of converting to integers
X |
Floor of x |
Ceiling of x |
Round of x |
3.14 |
3 |
4 |
3 |
0.7 |
0 |
1 |
1 |
4.5 |
4 |
5 |
5 |
-3.14 |
-4 |
-3 |
-3 |
-0.7 |
-1 |
0 |
-1 |
-4.5 |
-5 |
-4 |
-4 |
Converting a Rational Number to an Integer
Sometimes we want to convert a rational number into an integer. This can be done in different ways, where the three most common are:
Floor simply rounds a rational number to the nearest smaller integer. For example: Floor of 4.2 = 4. Mathematically it is denoted |_4.2J = 4. In C-programming a build-in function exists: floor().
Ceiling is the opposite of floor and rounds off to the nearest bigger integer. For example: Ceiling of 4.2 = 5. Mathematically it is denoted [4.2] = 5. In C-programming a build-in function exists: ceil().
Round finds the nearest integer, i.e., Round of 4.2 = 4 and Round of 4.7 = 5. In terms of C-code the following expression is often used: int(x + 0.5). That is, we add 0.5 to the number and then typecast it to an integer.
In Table B.1 some examples are provided.
Summation
Say you want to add the first 12 positive integers:
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 = 78 (B.2)
This is no problem writing down, but what if you want to add the first 1024 positive integers? This will be dreadful to write down. Luckily there exists a more compact way of writing this using summation, which is denoted as Σ. Adding the first 1024 positive integers can now be written as
where i is the summation index. Below the summation sign we have i = 1, which means that the first value of i is 1. Above the summation sign we have 1024. This actually means i = 1042, but we virtually always skip i =. Either way, it means that the last value of i is 1042. You can think of i as a counter going from 1 to 1042 in steps of one: 1, 2, 3,4, 5,…, 1040,1041, 1042. What comes after the summation is a function, which is controlled by i and it is the values of this function (for each i ) that are added together. Below, some examples of different summations are given:
Say that you want to sum the pixel values of the first row in an image with width = 200. This is then written as
In general the summation is written as
In terms of C-programming the summation is implemented as a for-loop:
We can also do a summation using more indices than i. For example, if we want to add all pixel values in an image, then we need two indices representing rows and columns. Concretely we would write
where N is the number of columns and M is the number of rows. In terms of C-programming the double summation is implemented as two for-loops:
Fig. B.1 (a) Point representation. (b) Vector representation
Vector
In the 2D coordinate system in Fig. B.1 a point is defined as P(x1 ,y1 ). The same point can be represented as a vector:
A vector is often written as a lowercase letter with an arrow above. It can be interpreted as a line with a slopeand a length. The length of the vector is defined as
We can arrange the vector as a row (as opposed to a column) by taking the transpose of the vector,That is,
or in other words:
Say we have two vectors:We can then calculate the sum of and p2 as
Fig. B.2 (a) Adding two vectors. (b) Subtracting two vectors
Fig. B.3 The angle between two vectors
In the same way we can calculate the difference ofas
These operations can also be interpreted geometrically as illustrated in Fig. B.2.
Two vectors cannot be multiplied but we can calculate the dot product between them. Say we defineThe dot product between them is then defined as
The dot product can also be interpreted geometrically as
whereis the length of vectoris the length of vectorand V is the angle between the vectors, see Fig. B.3. Note that it is always the smallest of the two possible angles that is calculated using Eq. B.16, i.e., 0° < V < 180°. The biggest angle is found as Vbig = 360° — V.
B.6 Matrix
When we have multiple vectors we can represent them as one entity denoted a matrix. For example,can be represented as
A matrix is often denoted by an uppercase letter in boldface, but other representations can also be used.
We say a matrix has a vertical and horizontal dimension, e.g., P has dimension 2 x 2. Note that the dimensions need not be equal. Similar to a vector a matrix can also be transposed by making the columns into rows:
Matrices can be added and subtracted similar to vectors, but they need to have the same dimensions:
Matrices can be multiplied in the following way:
The entry in row one and column one of the output matrix (ae + cf ) is found as the dot product between row one of the left matrix and column one of the right matrix. This principle is then repeated for each entry in the output matrix. This implies that the number of columns in the left matrix has to be equal to the number of rows in the right matrix. On the other hand this also implies that the number of rows in the left matrix and the number of columns in the right matrix need not be the same. For example, a matrix can be multiplied by a vector. The dimensions of the output matrix are equal to the number of rows in the left matrix and the number of columns in the right matrix. Below, some examples are shown:
A matrix of particular interest is the identity matrix, which in the 2D case looks like this:
If the product of two matrices equals the identity matrix, A · B = I, then we say they are each other’s inverse. This is denoted as A-1 = B and B-1 = A, or in other words A · A-1 = A-1 · A = I. For a 2 x 2 matrix the inverse is calculated as
Calculating the inverse for matrices of higher dimensions can be quite complicated.