Math Foundations: Matrices and Linear Equations
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:
Data Representation:
Feature representation: A house can be described by features like (House number, No of Bed rooms, Area in square feet) =
Text as Vectors: Texts are represented as vectors in ML. Techniques like Word2Vec and BERT embeddings convert words/text into vectors.
Distance and Similarity:
Distance between vectors is defined using inner product (dot product).
Used to study the similarity of data.
Linear dependency and Data Redundancy:
Study of linear independent and linear dependent vectors.
If two vectors are linearly dependent, one data is redundant of the other.
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.
Example: Polynomials can also be treated as vectors.
Deals with vectors in the space
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 for which resources are required.
To produce a unit of product , units of resource are needed, where .
Find an optimal production plan where units of product are produced if a total units of resource are available, and no resources are left over.
Formulation
If we produce units of the products , we need a total of units of resource .
Equation:
Set up the following set of linear equations in n unknowns, .
A linear system has zero, one, or infinitely many solutions.
System of Linear Equations
A linear system of m equations in n unknowns is a set of equations of the form:
The system is called linear because each variable appears in the first power only.
are given numbers, called the coefficients of the system.
on the right are also given numbers.
If all the are zero, then the system is called a homogeneous system.
If at least one is not zero, then the system is called a non-homogeneous system.
Augmented Matrix
Matrix Form of the Linear System:
Assume that coefficients are not all zero, so that A is not a zero matrix.
has n components, whereas has m components.
The augmented matrix of the system is:
The dashed vertical line is a reminder that the last column of came from vector .
Matrix is augmented.
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:
Rewrite:
Lines have slopes -1 and 2, and y-intercepts 5 and -4.
They intersect at a point, the solution:
No Solution:
System:
Rewrite:
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 .
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:
Rows and Columns: Matrices consist of rows and columns. Rows are labeled from the top of the matrix, columns from the left.
Example:
Rows:
row 1:
row 2:
Columns:
column 1:
column 2:
column 3:
How to Represent a System of Equations in Matrix Form
System of equations:
Matrix of coefficients:
Augmented matrix:
If and , then the above system of equations can be written in matrix form as , where
Example - Solving a System of Equations
Solve the system of equations:
Augmented Matrix:
Elementary row operations:
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):
The leading entry in each nonzero row is 1.
Each leading 1 is the only nonzero entry in its column.
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:
Solution:
Start with the augmented matrix and use the first row to create zeros in the first column.
This corresponds to using the first equation to eliminate from the second and third equations.
Next multiply row 2 by to make the element 1. (This corresponds to making the coefficient of in the second equation 1.)
Create zeros in the second column as follows. (This corresponds to using the second equation to eliminate from the first and third equations.)
Multiply row 3 by . (This corresponds to making the coefficient of in the third equation 1.)
Finally, create zeros in the third column. (This corresponds to using the third equation to eliminate from the first and second equations.)
This matrix corresponds to the system
The solution is .
System of Equations with No Solution
Solve the system of equations if possible:
Solution:
Starting with the augmented matrix we get
The last row of this reduced echelon form gives the equation
This equation cannot be satisfied for any values of , and . 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 and are independent variables. Hence the solutions are and where r and s are any real numbers.
Homogenous System
Solve
and 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:
Do the three planes , and 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 :
Let us consider the augmented matrix
Now multiply the second row by -1 and the third row by 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:
The preceding set of equations cannot be solved when
.
The last equation is consistent only for 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
Let and
Then Then, we get and
Thus, solution is
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 where A is a n × n matrix.
If A is invertible, it means that exists such that
In such a case the row-reduced echelon form of A is , i.e every column is a pivot column where the pivot is 1.
The process of converting A to 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 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 where - is the i th canonical basis vector and find their solutions x. Each solution vector constitutes a column in . Why is this true?
Find the Inverse of A if it Exists
Solution
Applying the method of Gauss-Jordan elimination we get
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 Inverse of A does not exist.