Course Overview
Modules:
Matrices and Solving System of Linear Equations
Vectors, Distance and Angle between vectors, Linear Independence and Dependence
Matrix Decompositions
Vector Calculus
Gradient Descent Algorithms, Challenges in optimization in ML
Optimization in Machine Learning (PCA, SVM)
Why Study Vectors and Matrices?
Vectors are fundamental in machine learning (ML).
Used throughout the entire workflow, from data representation to model training and prediction.
Uses of Vectors in ML:
Linear Algebra
Linear algebra is the study of vectors and rules to manipulate vectors.
Vectors are not only geometric vectors (points in 2D/3D space) but any objects that can be added together and multiplied by scalar values to produce another object of the same kind.
Deals with vectors in the space Rn
Systems of Linear Equations
Form a central part of linear algebra.
Many problems can be formulated as systems of linear equations.
Tools of linear algebra can be used to solve such problems.
Uses analytical techniques and numerical methods to solve the systems of linear equations.
Motivating Problem for Studying Linear System of Equations
A company produces products N<em>1,N</em>2,…N<em>n for which resources R</em>1,R<em>2,…R</em>m are required.
To produce a unit of product N<em>i, a</em>ij units of resource Rj are needed, where 1≤i≤n,1≤j≤m.
Find an optimal production plan where x<em>i units of product N</em>i are produced if a total b<em>j units of resource R</em>j are available, and no resources are left over.
Formulation
If we produce x<em>1,x</em>2,…x<em>n units of the products N</em>1,N<em>2…N</em>n, we need a total of a<em>1ix</em>1+a<em>2ix</em>2+…+a<em>nix</em>n units of resource Rj.
Equation: a<em>1ix</em>1+a<em>2ix</em>2+…+a<em>nix</em>n=bi
Set up the following set of linear equations in n unknowns, x<em>1,x</em>2…xn.
a<em>11x</em>1+a<em>21x</em>2+⋅⋅⋅+a<em>n1x</em>n=b1
⋮
a<em>1mx</em>1+a<em>2mx</em>2+⋅⋅⋅+a<em>nmx</em>n=bm
A linear system has zero, one, or infinitely many solutions.
System of Linear Equations
A linear system of m equations in n unknowns x<em>1,…,x</em>n is a set of equations of the form:
a<em>11x</em>1+a<em>12x</em>2+…+a<em>1nx</em>n=b1
a<em>21x</em>1+a<em>22x</em>2+…+a<em>2nx</em>n=b2
⋮
a<em>m1x</em>1+a<em>m2x</em>2+…+a<em>mnx</em>n=bm
The system is called linear because each variable xi appears in the first power only.
a<em>11,…,a</em>mn are given numbers, called the coefficients of the system.
b<em>1,…,b</em>m on the right are also given numbers.
If all the bj are zero, then the system is called a homogeneous system.
If at least one bj is not zero, then the system is called a non-homogeneous system.
Augmented Matrix
Solving System of Equations
Eliminate variables and solve.
Add a multiple of one equation to the other.
Consider the matrix form of the system of transformed equations for which solutions could be obtained essentially by inspection.
Preserve solutions of the original system of equations.
Elementary transformations performed on the coefficient matrix should also be performed on the constant vector.
Perform all elementary row transformations on the augmented matrix of the linear system.
Solving System of Linear Equations with Two Variables and Their Geometrical Interpretation
Unique Solution:
System:
x+y=5
2x−y=4
Rewrite:
y=−x+5
y=2x−4
Lines have slopes -1 and 2, and y-intercepts 5 and -4.
They intersect at a point, the solution: x=3,y=2
No Solution:
System:
Rewrite:
y=2x+3
y=2x+1
Lines have slope 2, and y-intercepts 3 and 1. They are parallel.
No point of intersection. No solution.
Many Solutions:
System:
Each equation can be written as y=2x−3.
The graph of each equation is a line with slope 2 and y-intercept -3.
Any point on the line is a solution. Many solutions.
Three Possibilities for System of Linear Equations
A system of linear equations has
no solution, or
exactly one solution, or
infinitely many solutions.
A system of linear equations is said to be consistent if it has either one solution or infinitely many solutions;
A system is inconsistent if it has no solution
Matrices
Definition: A matrix is a rectangular array of numbers. The numbers in the array are called the elements of the matrix.
Matrices are usually denoted by capital letters.
Examples:
A=[2amp;3 7amp;5]
B=[1amp;3amp;5amp;6 0amp;5amp;8amp;3 2amp;9amp;12amp;1]
C=[7 −1 5]
Rows and Columns: Matrices consist of rows and columns. Rows are labeled from the top of the matrix, columns from the left.
How to Represent a System of Equations in Matrix Form
System of equations:
x<em>1+x</em>2+x3=2
2x<em>1+3x</em>2+x3=3
x<em>1−x</em>2−2x3=−6
Matrix of coefficients: [1amp;1amp;1 2amp;3amp;1 1amp;−1amp;−2]
Augmented matrix: [1amp;1amp;1amp;2 2amp;3amp;1amp;3 1amp;−1amp;−2amp;−6]
If A=[1amp;1amp;1 2amp;3amp;1 1amp;−1amp;−2] and B=[2 3 −6], then the above system of equations can be written in matrix form as AX=B, where X=[x<em>1 x</em>2 x3]
Example - Solving a System of Equations
Solve the system of equations:
x<em>1−2x</em>2+x3=0
5x<em>1−2x</em>2−8x3=8
−5x3=10
Augmented Matrix:
[1amp;−2amp;1amp;0 5amp;−2amp;−8amp;8 1amp;2amp;−5amp;10]
Elementary row operations:
−5⋅[equation1]+[equation2]=[newequation2]
[1amp;−2amp;1amp;0 0amp;8amp;−13amp;8 1amp;2amp;−5amp;10]
−1⋅[equation1]+[equation3]=[newequation3]
[1amp;−2amp;1amp;0 0amp;8amp;−13amp;8 0amp;4amp;−6amp;10]
⋮
−4⋅[equation3]+[equation2]=[newequation2]
[1amp;−2amp;1amp;0 0amp;0amp;11amp;−32 0amp;4amp;−6amp;10]
⋮
−1⋅[equation3]+[equation1]=[newequation1]
[0amp;1amp;0amp;−1 0amp;0amp;1amp;−2 0amp;0amp;0amp;0]
Echelon Form and Reduced Row Echelon Form
A rectangular matrix is in echelon form (or row echelon form) if it has the following three properties:
All nonzero rows are above any rows of all zeros.
Each leading entry of a row is in a column to the right of the leading entry of the row above it.
All entries in a column below a leading entry are zeros.
If a matrix in echelon form satisfies the following additional conditions, then it is in reduced echelon form (or reduced row echelon form):
Elementary Row Operations
Elementary Row Operations
Interchange two rows of a matrix.
Multiply the elements of a row by a nonzero constant.
Add a multiple of the elements of one row to the corresponding elements of another row.
Systems of equations that are related through elementary transformations are called equivalent systems. Matrices that are related through elementary row operations are called row equivalent matrices. The symbol ∼ is used to indicate equivalence in both cases.
Gauss-Jordan Elimination Method - Example
Solve the system of equations:
x<em>1−2x</em>2+4x3=12
−2x<em>1−x</em>2+5x3=18
−x<em>1+3x</em>2−3x3=−8
Solution:
Start with the augmented matrix and use the first row to create zeros in the first column.
[1amp;−2amp;4amp;12 −2amp;−1amp;5amp;18 −1amp;3amp;−3amp;−8]∼[1amp;−2amp;4amp;12 0amp;−5amp;13amp;42 0amp;1amp;1amp;4]
Next multiply row 2 by −51 to make the (2,2) element 1. (This corresponds to making the coefficient of x2 in the second equation 1.)
∼[1amp;−2amp;4amp;12 0amp;1amp;−513amp;−542 0amp;1amp;1amp;4]
Create zeros in the second column as follows. (This corresponds to using the second equation to eliminate x2 from the first and third equations.)
∼[1amp;0amp;−56amp;−524 0amp;1amp;−513amp;−542 0amp;0amp;518amp;562]
Multiply row 3 by 185. (This corresponds to making the coefficient of x3 in the third equation 1.)
∼[1amp;0amp;−56amp;−524 0amp;1amp;−513amp;−542 0amp;0amp;1amp;931]
Finally, create zeros in the third column. (This corresponds to using the third equation to eliminate x3 from the first and second equations.)
∼[1amp;0amp;0amp;−32 0amp;1amp;0amp;−91 0amp;0amp;1amp;931]
This matrix corresponds to the system
x1=−32
x2=−91
x3=931
The solution is x<em>1=−32,x</em>2=−91,x3=931.
System of Equations with No Solution
Solve the system of equations if possible:
x<em>1+x</em>2+5x3=3
x<em>2+3x</em>3=−1
x<em>1+2x</em>2+8x3=3
Solution:
Starting with the augmented matrix we get
[1amp;1amp;5amp;3 0amp;1amp;3amp;−1 1amp;2amp;8amp;3]∼[1amp;1amp;5amp;3 0amp;1amp;3amp;−1 0amp;1amp;3amp;0]∼[1amp;0amp;2amp;4 0amp;1amp;3amp;−1 0amp;0amp;0amp;1]
The last row of this reduced echelon form gives the equation
0x<em>1+0x</em>2+0x3=1
This equation cannot be satisfied for any values of x<em>1,x</em>2, and x3. Thus the system has no solution. (This information was in fact available from the next-to-last matrix.)
System of Equations with Infinite Number of Solutions
Note that in the final matrix which is reduced echelon form 2nd and 3rd column do not have pivot elements. Those columns correspond to the independent variables. That is x<em>2 and x</em>3 are independent variables. Hence the solutions are x<em>4=2,x</em>2=r,x<em>3=s and x</em>1=−2−2x<em>2+x</em>3 where r and s are any real numbers.
Homogenous System
Solve
x<em>1−2x</em>2+4x3=0
2x<em>1−x</em>2+5x3=0
−x<em>1+3x</em>2−3x3=0
[1amp;−2amp;4 2amp;−1amp;5 −1amp;3amp;−3]
x<em>1=0,x</em>2=0 and x3=0 is the only solution.
Practice Problems
The augmented matrix of a linear system has been reduced by row operations to the form shown. In each case, continue the appropriate row operations and describe the solution set of the original system.
Practice Problems
Find an equation involving g, h, and k that makes this augmented matrix correspond to a consistent system:
[0amp;2amp;−4amp;7amp;g 3amp;1amp;−5amp;0amp;h −2amp;4amp;−9amp;5amp;k]
Do the three planes x<em>1+2x</em>2+x<em>3=4,x</em>2−x<em>3=1, and x</em>1+3x2=0 have at least one common point of intersection? Explain.
Gaussian Elimination Method
You don’t have to compute Reduced Echelon form to solve the system of linear equations. Instead it is enough to find the Echelon form. This method is called Gaussian Elimination method. HW: Follow this method for the previous examples to solve the system of linear equations.
One More Example:
Consider the following system where we seek all solutions for some a∈R:
−2x<em>1+4x</em>2−2x<em>3−x</em>4+4x5=−3
4x<em>1−8x</em>2+3x<em>3−3x</em>4+x5=2
x<em>1−2x</em>2+x<em>3−x</em>4+x5=0
−x<em>1+2x</em>2−3x<em>4+4x</em>5=a
Let us consider the augmented matrix
[−2amp;4amp;−2amp;−1amp;4amp;−3 4amp;−8amp;3amp;−3amp;1amp;2 1amp;−2amp;1amp;−1amp;1amp;0 −1amp;2amp;0amp;−3amp;4amp;a]
∼[1amp;−2amp;0amp;0amp;3amp;1 0amp;0amp;−1amp;1amp;−3amp;2 0amp;0amp;0amp;−2amp;2amp;−1−3 0amp;0amp;0amp;0amp;0amp;a+1]
Now multiply the second row by -1 and the third row by 3−1 to get the augmented matrix in its final form, known as the row-echelon form. These equations are equivalent to the original set of equations:
x<em>1−2x</em>2+x<em>3−x</em>4+x5=0
x<em>3−x</em>4+3x5=−2
x<em>4−2x</em>5=1
0=a+1
The preceding set of equations cannot be solved when
a=−1.
The last equation is consistent only for a=−1 i.e when rank of the coefficient matrix is same the rank of augmented matrix then the system has solution.
In REF of a matrix, the leading entry is called as the pivot element and columns containing pivot elements are called as pivot columns. The corresponding variables are called pivot variables.
The variables corresponding to non pivot columns are called as free variables.
Consider
x<em>1−2x</em>2+x<em>3−x</em>4+x5=0
x<em>3−x</em>4+3x5=−2
x<em>4−2x</em>5=1
Let x<em>5=t and x</em>2=s
Then x<em>4=1+2t Then, we get x</em>3=−1−tand x1=2+2s+2t
Thus, solution is (2+2s+2t,s,−1−t,1+2t,t),∀t,s∈R
The system is inconsistent if the rank of the coefficient matrix is less than the rank of augmented matrix.
The system is consistent if the rank of the coefficient matrix is same as the rank of augmented matrix.
For the consistent system, if there are no free variables, the solution is unique.
For the consistent system, if there are free variables, there are infinitely many solutions.
Gaussian Elimination and Gauss Jordan
Repeated use of elementary row operations done to convert a matrix to upper triangular form is called Gaussian elimination.
Consider the system of equations Ax=b where A is a n × n matrix.
If A is invertible, it means that A−1 exists such that AA−1=A−1A=In
In such a case the row-reduced echelon form of A is In, i.e every column is a pivot column where the pivot is 1.
The process of converting A to In that we have discussed above is called the Gauss-Jordan method.
Gaussian Elimination and Gauss Jordan
In Gaussian Elimination we use multiples of the first row to eliminate the entries in the first column below the first row.
Then we use multiples of the second row to eliminate entries in the second column below the second row and so on until we get an upper-triangular matrix.
This Gauss Jordan process is shown diagramatically in the next slide.
Then we take multiples of the last row to eliminate non-zero entries in the last column above the last entry, followed by multiples of the last but one row to eliminate non-zero entries in the last but one column and so on. This gives us a diagonal matrix.
Calculating Inverse
Can the Gauss Jordan procedure calculate the inverse of a matrix?
For example, let A be a n × n matrix whose inverse A−1 exists. We would like to compute its inverse using Gauss Jordan procedure. Is this possible?
Yes we can compute the inverse in the following way: we simply set up n linear systems of the form Ax=e<em>i,1≤i≤n where e</em>i - is the i th canonical basis vector and find their solutions x. Each solution vector constitutes a column in A−1. Why is this true?
Find the Inverse of A if it Exists
A=[1amp;−1amp;−2 2amp;−3amp;−5 −1amp;3amp;5]
Solution
Applying the method of Gauss-Jordan elimination we get
[A:I]=[1amp;−1amp;−2amp;1amp;0amp;0 2amp;−3amp;−5amp;0amp;1amp;0 −1amp;3amp;5amp;0amp;0amp;1]
∼[1amp;−1amp;−2amp;1amp;0amp;0 0amp;−1amp;−1amp;−2amp;1amp;0 0amp;2amp;3amp;1amp;0amp;1]
∼[1amp;−1amp;−2amp;1amp;0amp;0 0amp;1amp;1amp;2amp;−1amp;0 0amp;0amp;1amp;−3amp;2amp;1]
∼[1amp;0amp;0amp;0amp;5amp;−3amp;−1 0amp;1amp;0amp;0amp;−1amp;−3amp;2amp;1 0amp;0amp;1amp;1amp;−3amp;2amp;1]
Hence inverse of A = \begin{bmatrix} 0 & 5 & -3 & -1\ 0 & -1 & -3 & 2 & 1 \1 & -3 & 2 & 1 \end{bmatrix}
Find the Inverse of A if it Exists
Since the LHS 3x3 matrix can not be brought to I3 Inverse of A does not exist.