Basic Math Review for CS4830 Dr. Mihail August 18, 2016 (Dr. Mihail) Math Review for CS4830 August 18, 2016 1 / 35
Sets Definition of a set A set is a collection of distinct objects, considered as an object in its own right. For example, the numbers 2, 4, and 6 are distinct objects when considered separately, but when they are considered collectively they form a single set of size three, written {2, 4, 6}. Sets are one of the most fundamental concepts in mathematics. Have to know symbols : set membership. Example: x R is read x belongs to the set R. : union. Example: X = A B is read: X is the result of A union B, and contains all elements of A and B. : intersection. Example X = A B is read X is the result of A intersect B, and contains elements that are in BOTH A and in B (Dr. Mihail) Math Review for CS4830 August 18, 2016 2 / 35
Number sets Naturals Natural numbers: N (Dr. Mihail) Math Review for CS4830 August 18, 2016 3 / 35
Number sets Naturals Natural numbers: N Examples: 0, 1, 2, 3, 4,... (Dr. Mihail) Math Review for CS4830 August 18, 2016 3 / 35
Number sets Naturals Natural numbers: N Integers Examples: 0, 1, 2, 3, 4,... Integers: Z (Dr. Mihail) Math Review for CS4830 August 18, 2016 3 / 35
Number sets Naturals Natural numbers: N Integers Examples: 0, 1, 2, 3, 4,... Integers: Z Examples:... 4, 3, 2, 1, 0, 1, 2, 3, 4,... (Dr. Mihail) Math Review for CS4830 August 18, 2016 3 / 35
Number sets Naturals Natural numbers: N Integers Examples: 0, 1, 2, 3, 4,... Integers: Z Examples:... 4, 3, 2, 1, 0, 1, 2, 3, 4,... (Dr. Mihail) Math Review for CS4830 August 18, 2016 3 / 35
Number sets Naturals Natural numbers: N Integers Examples: 0, 1, 2, 3, 4,... Integers: Z Examples:... 4, 3, 2, 1, 0, 1, 2, 3, 4,... Rationals Rational numbers: Q (Dr. Mihail) Math Review for CS4830 August 18, 2016 3 / 35
Number sets Naturals Natural numbers: N Integers Examples: 0, 1, 2, 3, 4,... Integers: Z Examples:... 4, 3, 2, 1, 0, 1, 2, 3, 4,... Rationals Rational numbers: Q Examples: 1 2, 2 3, 10 7, 1 3 (Dr. Mihail) Math Review for CS4830 August 18, 2016 3 / 35
Number sets Naturals Natural numbers: N Integers Examples: 0, 1, 2, 3, 4,... Integers: Z Examples:... 4, 3, 2, 1, 0, 1, 2, 3, 4,... Rationals Rational numbers: Q Examples: 1 2, 2 3, 10 7, 1 3 a More generally, rational numbers are ratios of two whole numbers: b, where a, b Z subject to b 0 (Dr. Mihail) Math Review for CS4830 August 18, 2016 3 / 35
Number sets contd. Irrationals Numbers that cannot be expressed as a ratio of two integers No set symbol, often noted as: R Q Examples: π, e, 2 (Dr. Mihail) Math Review for CS4830 August 18, 2016 4 / 35
Number sets contd. Irrationals Numbers that cannot be expressed as a ratio of two integers No set symbol, often noted as: R Q Examples: π, e, 2 Reals Real numbers: R (Dr. Mihail) Math Review for CS4830 August 18, 2016 4 / 35
Number sets contd. Imaginaries Imaginary numbers: I They are numbers that, when squared, result in a negative number Example: 9 = 3i, because (3i) 2 = 9, here i 2 = 1 (Dr. Mihail) Math Review for CS4830 August 18, 2016 5 / 35
Number sets contd. Imaginaries Imaginary numbers: I They are numbers that, when squared, result in a negative number Example: 9 = 3i, because (3i) 2 = 9, here i 2 = 1 Algebraic numbers Algebraic numbers: A Numbers that are roots (solutions) to at least one non-zero polynomial with rational coefficients Example: x in 2x 3 5x + 39 (Dr. Mihail) Math Review for CS4830 August 18, 2016 5 / 35
Number sets contd. Imaginaries Imaginary numbers: I They are numbers that, when squared, result in a negative number Example: 9 = 3i, because (3i) 2 = 9, here i 2 = 1 Algebraic numbers Algebraic numbers: A Numbers that are roots (solutions) to at least one non-zero polynomial with rational coefficients Example: x in 2x 3 5x + 39 What about i Is i also an algebraic number? (Dr. Mihail) Math Review for CS4830 August 18, 2016 5 / 35
Number sets contd. Complex Complex numbers: C They are a combination of a real and an imaginary number Examples 10 2i, 2 + 3i More generally, they have the form x + iy, where x, y R (Dr. Mihail) Math Review for CS4830 August 18, 2016 6 / 35
Number sets contd. Complex Complex numbers: C They are a combination of a real and an imaginary number Examples 10 2i, 2 + 3i More generally, they have the form x + iy, where x, y R (Dr. Mihail) Math Review for CS4830 August 18, 2016 6 / 35
Operations on numbers Venn diagram of number sets (Dr. Mihail) Math Review for CS4830 August 18, 2016 7 / 35
Operations on numbers Common operations Addition: 2 + 3 = 5 Subtraction 2 3 = 1 Multiplication 2 3 = 6 Division 2 3 = 0.(6) Exponentiation 2 3 = 8 (Dr. Mihail) Math Review for CS4830 August 18, 2016 8 / 35
Variables Variable may refer to: In research: a logical set of attributes In mathematics: a symbol that represents a quantity in a mathematical expression In computer science: a symbolic name associated with a value and whose associated value may be changed We shall use all 3 flavors in this course. (Dr. Mihail) Math Review for CS4830 August 18, 2016 9 / 35
Functions What is a function? (Dr. Mihail) Math Review for CS4830 August 18, 2016 10 / 35
Functions Intuition (Dr. Mihail) Math Review for CS4830 August 18, 2016 11 / 35
Functions Intuition useful for computer scientists (Dr. Mihail) Math Review for CS4830 August 18, 2016 12 / 35
Functions Informal definition Think of a function as a process that takes input x and produces output f(x). For example, the function f (x) = x 2, takes an input x (a number) and processes it by squaring it. Plotting a function with a single number as input (Dr. Mihail) Math Review for CS4830 August 18, 2016 13 / 35
Terminology related to functions Terms to absolutely have to know Function input: domain (Dr. Mihail) Math Review for CS4830 August 18, 2016 14 / 35
Terminology related to functions Terms to absolutely have to know Function input: domain Function output: range or more accurately image (Dr. Mihail) Math Review for CS4830 August 18, 2016 14 / 35
Terminology related to functions Terms to absolutely have to know Function input: domain Function output: range or more accurately image When plotting a function with scalar inputs, the X -axis is called the abscissa, the Y -axis is called the ordinate (Dr. Mihail) Math Review for CS4830 August 18, 2016 14 / 35
Terminology related to functions Terms to absolutely have to know Function input: domain Function output: range or more accurately image When plotting a function with scalar inputs, the X -axis is called the abscissa, the Y -axis is called the ordinate The input X, is also referred to as the independent variable or predictor variable, regressor, controlled variable, manipulated variable, explanatory variable, etc. (Dr. Mihail) Math Review for CS4830 August 18, 2016 14 / 35
Terminology related to functions Terms to absolutely have to know Function input: domain Function output: range or more accurately image When plotting a function with scalar inputs, the X -axis is called the abscissa, the Y -axis is called the ordinate The input X, is also referred to as the independent variable or predictor variable, regressor, controlled variable, manipulated variable, explanatory variable, etc. The output Y, is also referred to as the dependent variable or response variable, regressand, measured variable, outcome variable, output variable, etc. (Dr. Mihail) Math Review for CS4830 August 18, 2016 14 / 35
Operations on functions Composition The idea is to process the input through one function, then use the result of that function as the input to the second. This results in a different function. Notation: given two functions f and g, the composition of g and f is written as (g f ) = g(f (x)). Example: if f (x) = 2x + 3, and g(x) = x 2, then (g f ) = g(f (x)) = g(2x + 3) = (2x + 3) 2 = 4x 2 + 12x + 9. (f g) (g f ). (Dr. Mihail) Math Review for CS4830 August 18, 2016 15 / 35
Operations on functions Differentiation/Integration Rates of change and areas under the curve. Derivative of a function f is often noted as f or d dx [f (x)] (Dr. Mihail) Math Review for CS4830 August 18, 2016 16 / 35
Operations on functions Differentiation/Integration Rates of change and areas under the curve. Derivative of a function f is often noted as f or d dx [f (x)] It is important to know if a function is differentiable and where (Dr. Mihail) Math Review for CS4830 August 18, 2016 16 / 35
Operations on functions Differentiation/Integration Rates of change and areas under the curve. Derivative of a function f is often noted as f or d dx [f (x)] It is important to know if a function is differentiable and where Indefinite integral of a function f is written as f (x)dx Definite integral of a function f over an interval [a, b] is written as b a f (x)dx (Dr. Mihail) Math Review for CS4830 August 18, 2016 16 / 35
Operations on functions Differentiation/Integration Rates of change and areas under the curve. Derivative of a function f is often noted as f or d dx [f (x)] It is important to know if a function is differentiable and where Indefinite integral of a function f is written as f (x)dx Definite integral of a function f over an interval [a, b] is written as b a f (x)dx (Dr. Mihail) Math Review for CS4830 August 18, 2016 16 / 35
Analytic/Numerical In Calculus courses you were probably taught analytic solutions to differentiation and integration problems. In the real-world, you will most likely deal with numerical differentiation and integration. More on that later in the course. (Dr. Mihail) Math Review for CS4830 August 18, 2016 17 / 35
Vector and Matrix Algebra Scalars A scalar is a simple quantity, or a number. For example, in x = 1, x is a scalar. (Dr. Mihail) Math Review for CS4830 August 18, 2016 18 / 35
Vector and Matrix Algebra Scalars A scalar is a simple quantity, or a number. For example, in x = 1, x is a scalar. Vectors Going a bit further, a vector is an ordered set of scalars. For example, [2, 3] is a vector. (Dr. Mihail) Math Review for CS4830 August 18, 2016 18 / 35
Vector and Matrix Algebra Scalars A scalar is a simple quantity, or a number. For example, in x = 1, x is a scalar. Vectors Going a bit further, a vector is an ordered set of scalars. For example, [2, 3] is a vector. Vector elements The position of the scalar in the ordered set is referred to as the index. In the example above, the index of the element 2 is 1, since it is the first element in the set. The index of 3 is 2, since it is the second element. (Dr. Mihail) Math Review for CS4830 August 18, 2016 18 / 35
More about vectors Vector dimensionality The number of elements a vector has is referred to as its dimensionality. For example, the vector X = [x 1, x 2, x 3 ] has dimensionality 3, and if x 1, x 2, x 3 R, then it is denoted as X R 3. There can be any number dimensional vectors. For example 6-dimensional vectors R 6. (Dr. Mihail) Math Review for CS4830 August 18, 2016 19 / 35
More about vectors Vector dimensionality The number of elements a vector has is referred to as its dimensionality. For example, the vector X = [x 1, x 2, x 3 ] has dimensionality 3, and if x 1, x 2, x 3 R, then it is denoted as X R 3. There can be any number dimensional vectors. For example 6-dimensional vectors R 6. Vector magnitude A vector s magnitude is the distance (or L2-norm) from the origin of the space it lives in and a point. The magnitude is computed using the Pythagorean theorem (more accurately, a generalization of that known as Euclidian distance) using the following formula and notation: n X = ( xi 2) (1) i=1 (Dr. Mihail) Math Review for CS4830 August 18, 2016 19 / 35
But I thought... That... Vectors area mathematical object with a magnitude and direction, not what you just told us. (Dr. Mihail) Math Review for CS4830 August 18, 2016 20 / 35
But I thought... That... Vectors area mathematical object with a magnitude and direction, not what you just told us. This definition is nothing but a special case of the definition in the previous slide. (Dr. Mihail) Math Review for CS4830 August 18, 2016 20 / 35
But I thought... That... Vectors area mathematical object with a magnitude and direction, not what you just told us. This definition is nothing but a special case of the definition in the previous slide. (Dr. Mihail) Math Review for CS4830 August 18, 2016 20 / 35
But I thought... That... Vectors area mathematical object with a magnitude and direction, not what you just told us. This definition is nothing but a special case of the definition in the previous slide. When the tail and the head are points on 2D plane, how can we compute magnitude? (Dr. Mihail) Math Review for CS4830 August 18, 2016 20 / 35
3D visualization (Dr. Mihail) Math Review for CS4830 August 18, 2016 21 / 35
3D visualization In-class exercise If a = [1, 2, 3], what is a? (Dr. Mihail) Math Review for CS4830 August 18, 2016 21 / 35
Matrices Definition A matrix is a rectangular table of numbers. (Dr. Mihail) Math Review for CS4830 August 18, 2016 22 / 35
Matrices Definition A matrix is a rectangular table of numbers. Example (Dr. Mihail) Math Review for CS4830 August 18, 2016 22 / 35
Matrices Structure in the 2D case (Dr. Mihail) Math Review for CS4830 August 18, 2016 23 / 35
Matrices Rows and Columns One can also think of a matrix as a collection of rows or a collection of columns. Or as a collection of row vectors or column vectors Row/Column vectors 1 X = 2 3 Y = [ 1 2 3 ] X has dimensionality 3x1, and is called a column vector Y has dimensionality 1x3, and is called a row vector (Dr. Mihail) Math Review for CS4830 August 18, 2016 24 / 35
Matrices Collection of column vectors 1 4 Given X 1 = 2 and X 2 = 5, we can form a matrix Z using X 1 and X 2 : 3 6 Collection of row vectors Z = [ ] 1 4 X 1 X 2 = 2 5 3 6 Given X 1 = [ 1 2 3 ] and X 2 = [ 4 5 6 ], we can form a matrix Z using X 1 and X 2 : [ ] [ ] X1 1 2 3 Z = = 4 5 6 X 2 (Dr. Mihail) Math Review for CS4830 August 18, 2016 25 / 35
Indexing Say, Z = [ ] 1 2 3. The matrix is 2 rows by 3 colums (2x3). 4 5 6 (Dr. Mihail) Math Review for CS4830 August 18, 2016 26 / 35
Indexing How can we address an element from a matrix? [ ] 1 2 3 Say, Z =. The matrix is 2 rows by 3 colums (2x3). 4 5 6 (Dr. Mihail) Math Review for CS4830 August 18, 2016 27 / 35
Indexing How can we address an element from a matrix? [ ] 1 2 3 Say, Z =. The matrix is 2 rows by 3 colums (2x3). 4 5 6 Simple Each element has an assigned column and row number. Think of Z as follows: [ ] Z1,1 Z Z = 1,2 Z 1,3 Z 2,1 Z 2,2 Z 2,3 each Z i,j where i {possible rows} and j {possible columns}, where possible rows for Z is the set {1, 2} and the possible columns for Z is the set {1, 2, 3}. (Dr. Mihail) Math Review for CS4830 August 18, 2016 27 / 35
Indexing How can we address an element from a matrix? [ ] 1 2 3 Say, Z =. The matrix is 2 rows by 3 colums (2x3). 4 5 6 Simple Each element has an assigned column and row number. Think of Z as follows: [ ] Z1,1 Z Z = 1,2 Z 1,3 Z 2,1 Z 2,2 Z 2,3 each Z i,j where i {possible rows} and j {possible columns}, where possible rows for Z is the set {1, 2} and the possible columns for Z is the set {1, 2, 3}. Where is 5? Second row, second column: Z 2,2 (Dr. Mihail) Math Review for CS4830 August 18, 2016 27 / 35
Operations on vectors and matrices Addition and subtraction If two matrices have the same dimensions r by c, including vectors and scalars as special cases, they can be added or subtracted by adding or subtracting the elements in the same positions in each matrix. (Dr. Mihail) Math Review for CS4830 August 18, 2016 28 / 35
Operations on vectors and matrices Addition and subtraction If two matrices have the same dimensions r by c, including vectors and scalars as special cases, they can be added or subtracted by adding or subtracting the elements in the same positions in each matrix. If A is r by c, and B is r by c, then for C = A + B, C ij = A ij + B ij, similarly if C = A B, C ij = A ij B ij. (Dr. Mihail) Math Review for CS4830 August 18, 2016 28 / 35
Operations on vectors and matrices Multiplication Matrix multiplication summarizes a set of multiplications and additions. Multiplication of matrix by scalar: simply multiply each element of the matrix by the scalar. [ ] 1 2 3 Example: a = 2 and X =, then Ax or xa is a matrix formed as 4 5 6 [ ] [ ] 2 1 2 2 2 3 2 4 6 follows: = 2 4 2 5 2 6 8 10 12 (Dr. Mihail) Math Review for CS4830 August 18, 2016 29 / 35
Operations on vectors and matrices Multiplication Multiplication of two matrices: The two matrices must be conformable, that is if A is r 1 by c 1 and B is r 2 by c 2, then C = A B is defined when c 1 = r 2 and C is of size r 1 by c 2. C ij is found by multiplying each element of row i of A with each element of column j of B and adding up the multiplied pairs of real numbers. (Dr. Mihail) Math Review for CS4830 August 18, 2016 30 / 35
Operations on vectors and matrices Transposition The transpose of A, written as A T is created by one the following ways: write the rows of A as the columns of A T (Dr. Mihail) Math Review for CS4830 August 18, 2016 31 / 35
Operations on vectors and matrices Transposition The transpose of A, written as A T is created by one the following ways: write the rows of A as the columns of A T write the columns of A as the rows of A T (Dr. Mihail) Math Review for CS4830 August 18, 2016 31 / 35
Operations on vectors and matrices Transposition The transpose of A, written as A T is created by one the following ways: write the rows of A as the columns of A T write the columns of A as the rows of A T Properties: c T = c, if c is a scalar (Dr. Mihail) Math Review for CS4830 August 18, 2016 31 / 35
Operations on vectors and matrices Transposition The transpose of A, written as A T is created by one the following ways: write the rows of A as the columns of A T write the columns of A as the rows of A T Properties: c T = c, if c is a scalar (A T ) T = A (Dr. Mihail) Math Review for CS4830 August 18, 2016 31 / 35
Operations on vectors and matrices Transposition The transpose of A, written as A T is created by one the following ways: write the rows of A as the columns of A T write the columns of A as the rows of A T Properties: c T = c, if c is a scalar (A T ) T = A (A + B) T = A T + B T (Dr. Mihail) Math Review for CS4830 August 18, 2016 31 / 35
Operations on vectors and matrices Transposition The transpose of A, written as A T is created by one the following ways: write the rows of A as the columns of A T write the columns of A as the rows of A T Properties: c T = c, if c is a scalar (A T ) T = A (A + B) T = A T + B T (AB) T = B T A T (Dr. Mihail) Math Review for CS4830 August 18, 2016 31 / 35
Operations on vectors and matrices Transposition The transpose of A, written as A T is created by one the following ways: write the rows of A as the columns of A T write the columns of A as the rows of A T Properties: c T = c, if c is a scalar (A T ) T = A (A + B) T = A T + B T (AB) T = B T A T (ca) T = ca T On vectors Transpose of a row vector results in a column vector. Transpose of a column vector results in a row vector. (Dr. Mihail) Math Review for CS4830 August 18, 2016 31 / 35
Inner and outer products of vectors Given two vectors with the same number of elements, e.g.: a and b both r by 1, we can define the inner and outer products as follows: Inner product a T b = r a i b i (2) The inner product of a vector v with itself v T v is equal to the sums of squares of its elements, so has the property v T v 0. Outer product The outer product results in a matrix, of size r by r. If O = ab T is the outer product matrix, then O ij = a i b j. i=1 (Dr. Mihail) Math Review for CS4830 August 18, 2016 32 / 35
Operations on vectors and matrices Multiplication Elements in the resulting matrix M = A B, M ij = dot(a[i, ], B[, j]), where indicates all possible rows/colummns, and dot is the inner product (results in a scalar). A[i, ] is a row vector, B[, j] is a column vector. (Dr. Mihail) Math Review for CS4830 August 18, 2016 33 / 35
Special matrices Square matrices: have the same number of rows and columns (Dr. Mihail) Math Review for CS4830 August 18, 2016 34 / 35
Special matrices Square matrices: have the same number of rows and columns Diagnoal matrices: square matrices that have all except the elements on the main diagonal equal to 0 (Dr. Mihail) Math Review for CS4830 August 18, 2016 34 / 35
Special matrices Square matrices: have the same number of rows and columns Diagnoal matrices: square matrices that have all except the elements on the main diagonal equal to 0 Symmetric matrices: square matrices that have the same numbers above and below the main diagonal, i.e., a matrix A is symmetric if and only if A ij = Aji. (Dr. Mihail) Math Review for CS4830 August 18, 2016 34 / 35
Special matrices Square matrices: have the same number of rows and columns Diagnoal matrices: square matrices that have all except the elements on the main diagonal equal to 0 Symmetric matrices: square matrices that have the same numbers above and below the main diagonal, i.e., a matrix A is symmetric if and only if A ij = Aji. Identity matrix: diagonal matrix with all 1s on the main diagonal (Dr. Mihail) Math Review for CS4830 August 18, 2016 34 / 35
Trace and determinants of square matrices Trace The trace of a square matrix is the sum of elements in its main diagonal. For a matrix A of size rxr, its trace, denoted as Tr(A) is: Tr(A) = r i=1 A ii Important property: tr(a) = i λ i, where λ i are the eigenvalues of matrix A. Determinant The determinant of a square matrix is a difficult calculation, but serves important purposes in optimization problems. Often, the sign is more important than its exact value. An important property is: det(a) = i λ i (Dr. Mihail) Math Review for CS4830 August 18, 2016 35 / 35