A simplified guide on how to prep up on Mathematics for Artificial Intelligence, Machine Learning and Data Science: Linear Algebra (Important Pointers only)
Module - I : Linear Algebra
I. Vector and its properties.
A mathematical entity with magnitude and direction denoted as or
Types of Vectors : Zero Vector (magnitude ->0, no direction) , Unit Vector (magnitude ->1, directional), Position Vector (position of a point relative to its origin) , Equal Vectors (same magnitude and same direction) , Opposite Vectors (same magnitude but opposite direction).
Vector operations:
1. Addition and Subtraction
- Vector Addition:
u + v = ( u 1 u 2 ) + ( v 1 v 2 ) = ( u 1 + v 1 u 2 + v 2 ) - Vector Subtraction:
u − v = ( u 1 u 2 ) − ( v 1 v 2 ) = ( u 1 − v 1 u 2 − v 2 )
2. Scalar Multiplication
- Multiplying a vector by a scalar
k v = k ( v 1 v 2 ) = ( k v 1 k v 2 )
3. Dot Product (Scalar Product)
- The dot product of two vectors is a scalar.
u ⋅ v = u 1 v 1 + u 2 v 2 + ⋯ + u n v n - The dot product can also be expressed in terms of the magnitudes of the vectors and the angle between them:
u ⋅ v = ∥ u ∥ ∥ v ∥ cos θ
4. Cross Product (Vector Product)
The cross product is only defined in three-dimensional space.
Vector Properties:
- Commutativity of Addition:
u + v = v + u - Associativity of Addition:
u + ( v + w ) = ( u + v ) + w - Distributivity:
k ( u + v ) = k u + k v - Zero Vector:
v + 0 = v - Negative Vector:
v + ( − v ) = 0
II. Vector Spaces and Subspaces.
A collection of vectors that can be added together and multiplied by scalars (real or complex numbers) and still remain within the set.
Denoted as over a field
Important Axioms:
Subspaces:
A subset
- Zero Vector:
.0 ∈ W \mathbf{0} \in W - Closed under Addition: For all
,u , v ∈ W \mathbf{u}, \mathbf{v} \in W .u + v ∈ W - Closed under Scalar Multiplication: For all
anda ∈ F a \in F ,v ∈ W .a v ∈ W
If
Eg: The zero subspace:
Properties of Subspaces:
- Intersection: The intersection of two subspaces of
is also a subspace ofV V .V V - Sum: The sum of two subspaces
andW 1 W_1 , defined asW 2 W_2 , is also a subspace ofW 1 + W 2 = { u + v ∣ u ∈ W 1 , v ∈ W 2 } W_1 + W_2 = \{ \mathbf{u} + \mathbf{v} \mid \mathbf{u} \in W_1, \mathbf{v} \in W_2 \} .V V - Span: The span of a set of vectors in
is the smallest subspace ofV V that contains all those vectors.V V
Spanning Set:
A set of vectors
Basis:
A basis of a vector space
Dimension:
The dimension of a vector space
III. Matrices.
A rectangular array of numbers, symbols, or expressions arranged in rows and columns, denoted by
For example, a
Types of Matrices:
- Square Matrix: A matrix with the same number of rows and columns (
).m = n - Row Matrix: A matrix with a single row (
).1 × n - Column Matrix: A matrix with a single column (
).m × 1 - Zero Matrix: A matrix in which all elements are zero.
- Identity Matrix: A square matrix with ones on the main diagonal and zeros elsewhere.
- Diagonal Matrix: A square matrix in which all off-diagonal elements are zero.
- Symmetric Matrix: A square matrix that is equal to its transpose (
).A = A T - Skew-Symmetric Matrix: A square matrix that is equal to the negative of its transpose (
).A = − A T A = -A^T - Upper Triangular Matrix: A square matrix in which all elements below the main diagonal are zero.
- Lower Triangular Matrix: A square matrix in which all elements above the main diagonal are zero.
Matrix Operations :
1. Addition:
2. Subtraction
3. Scalar Multiplication
4. Matrix Multiplication
Two matrices
Where each element
5. Transpose
6. Determinant
The determinant is a scalar value. For a
IV. Matrix Inversion.
The inverse of a square matrix
For a
Conditions for Inversion:
Not all matrices have inverses. A matrix
is a square matrix.A A - The determinant of
is non-zero, i.e.,A A .det ( A ) ≠ 0
If these conditions are not met, the matrix is said to be singular or non-invertible.
Properties of Inverse Matrix:
- Uniqueness: If
is invertible, its inverseA A is unique.A − 1 A^{-1} - Product of Inverses: If
andA A are invertible matrices of the same dimension, then the productB B is invertibleA B AB
( A B ) − 1 = B − 1 A − 1 - Inverse of Transpose: If
is invertible, thenA A ( A T ) − 1 = ( A − 1 ) T - Inverse of a Scalar Multiple: If
is invertible andA A is a non-zero scalar, thenc c
( c A ) − 1 = 1 c A − 1 (cA)^{-1} = \frac{1}{c}A^{-1}
Methods for Finding the Inverse:
1. Gaussian Elimination
To find the inverse of a matrix
- Form the augmented matrix
, where[ A ∣ I ] [A | I] is the identity matrix of the same dimension asI I .A A - Use row operations to transform
into[ A ∣ I ] [A | I] .[ I ∣ A − 1 ] [I | A^{-1}] - If this is possible, the matrix
is invertible and the right half of the augmented matrix will beA A .A − 1 A^{-1}
2. Adjugate Method
For a square matrix
where
- Compute the determinant
.det ( A ) \det(A) - Find the matrix of cofactors.
- Transpose the matrix of cofactors to get the adjugate.
- Divide each entry of the adjugate by
.det ( A ) \det(A)
3. Using Elementary Matrices
An elementary matrix is obtained by performing a single elementary row operation on an identity matrix. The inverse of
Then,
Eg:
Let's find the inverse of the following 2x2 matrix
The inverse is given by:
where
For example, if:
Then:
Applications
- Solving Linear Systems: Given
, ifA x = b is invertible, the solution isA A .x = A − 1 b - Computer Graphics: Inverse matrices are used for transforming coordinates and manipulating images.
- Control Theory: Inverse matrices are essential in system design and stability analysis.
V. Properties of Determinants.
Determinant of the Identity Matrix
The determinant of an identity matrix
of any size is 1:I I det ( I ) = 1 \det(I) = 1 Determinant of a Diagonal Matrix
The determinant of a diagonal matrix (a square matrix in which all off-diagonal elements are zero)
with elementsD D :d 11 , d 22 , … , d n n det ( D ) = d 11 ⋅ d 22 ⋅ … ⋅ d n n \det(D) = d_{11} \cdot d_{22} \cdot \ldots \cdot d_{nn Determinant of a Triangular Matrix
Similar to diagonal matrices, the determinant of a triangular matrix (either upper or lower triangular) is the product of its diagonal elements.
Determinant of the Transpose
The determinant of a matrix is equal to the determinant of its transpose:
det ( A ) = det ( A T ) \det(A) = \det(A^T) Multiplicative Property
The determinant of the product of two matrices is the product of their determinants:
det ( A B ) = det ( A ) ⋅ det ( B ) \det(AB) = \det(A) \cdot \det(B) Determinant of an Inverse
If
is an invertible matrix, the determinant of its inverse is the reciprocal of the determinant ofA A :A A det ( A − 1 ) = 1 det ( A ) \det(A^{-1}) = \frac{1}{\det(A Determinant of a Scalar Multiple
If
is anA A matrix andn × n n \times n is a scalar, the determinant of the scalar multiple ofc c is:A A det ( c A ) = c n det ( A ) \det(cA) = c^n \det(A) Row and Column Operations
Row Interchange: Swapping two rows (or two columns) of a matrix changes the sign of the determinant:
det ( B ) = − det ( A ) \det(B) = -\det(A) if
is obtained by interchanging two rows (or columns) ofB B .A A Row Scaling: Multiplying a row (or column) by a scalar multiplies the determinant by the same scalar:
det ( B ) = k ⋅ det ( A ) \det(B) = k \cdot \det(A) if
is obtained by multiplying a row (or column) ofB B byA A .k k Row Addition: Adding a multiple of one row (or column) to another row (or column) does not change the determinant:
det ( B ) = det ( A ) \det(B) = \det(A) if
is obtained by adding a multiple of one row (or column) to another row (or column) ofB B .A A
Determinant of a Block Matrix
For a block diagonal matrix:
A = ( A 1 0 0 A 2 ) A = \begin{pmatrix} A_1 & 0 \\ 0 & A_2 \end{pmatrix} The determinant is the product of the determinants of the blocks:
det ( A ) = det ( A 1 ) ⋅ det ( A 2 ) \det(A) = \det(A_1) \cdot \det(A_2) Singular Matrix
A matrix is singular (non-invertible) if and only if its determinant is zero:
det ( A ) = 0 ⟺ A is singular \det(A) = 0 \iff A \text{ is singular} Linearity in Rows and Columns
The determinant is a linear function in each row and each column.
VI. Eigen Values and Eigen Vectors.
Given a square matrix
Eigenvalue: A scalar
is called an eigenvalue ofλ if there exists a non-zero vectorA (called an eigenvector) such that:v A v = λ v Eigenvector: A non-zero vector
is called an eigenvector ofv corresponding to the eigenvalueA if it satisfies the above equation.λ
Finding Eigenvalues and Eigenvectors
To find the eigenvalues and eigenvectors of a matrix
Eigenvalues: Solve the characteristic equation:
det ( A − λ I ) = 0 \det(A - \lambda I) = 0 This equation is derived from the equation
by rearranging it to:A v = λ v ( A − λ I ) v = 0 (A - \lambda I) \mathbf{v} = 0 For non-trivial solutions (non-zero
), the matrixv \mathbf{v} must be singular, which means its determinant must be zero.A − λ I A - \lambda I Eigenvectors: For each eigenvalue
, solve the linear system:λ \lambda ( A − λ I ) v = 0 (A - \lambda I) \mathbf{v} = 0 to find the corresponding eigenvector(s)
.v \mathbf{v}
Properties of Eigenvalues and Eigenvectors
Sum of Eigenvalues: The sum of the eigenvalues of a matrix
is equal to the trace ofA A (the sum of the diagonal elements).A A ∑ i = 1 n λ i = tr ( A ) \sum_{i=1}^{n} \lambda_i = \text{tr}(A) Product of Eigenvalues: The product of the eigenvalues of a matrix
is equal to the determinant ofA A .A A ∏ i = 1 n λ i = det ( A ) \prod_{i=1}^{n} \lambda_i = \det(A) Eigenvectors of Different Eigenvalues: Eigenvectors corresponding to distinct eigenvalues are linearly independent.
Diagonalizability: A matrix
is diagonalizable if it hasA A linearly independent eigenvectors. In such cases,n n can be written as:A A A = P D P − 1 A = PDP^{-1} where
is the matrix of eigenvectors andP P is the diagonal matrix of eigenvalues.D D Similarity Transformation: If
andA A are similar matrices, they have the same eigenvalues.B B Power of a Matrix: If
is diagonalizable, thenA A can be expressed as:A k A k = P D k P − 1 A^k = PD^kP^{-1} where
is the diagonal matrix with eigenvalues ofD D on the diagonal, andA A is simply raising each diagonal entry to theD k D^k -th power.k k
Applications:
- Differential Equations: Eigenvalues and eigenvectors are used to solve systems of linear differential equations.
- Stability Analysis: In control theory, the stability of a system can be analyzed using the eigenvalues of the system matrix.
- Principal Component Analysis (PCA): In statistics, PCA uses eigenvalues and eigenvectors of the covariance matrix to reduce the dimensionality of data.
- Quantum Mechanics: Eigenvalues and eigenvectors are used to solve the Schrödinger equation.
- Vibration Analysis: In mechanical engineering, the natural frequencies (eigenvalues) and mode shapes (eigenvectors) of a system are analyzed.
VII. Diagonalization of Matrices.
Diagonalization of matrices is a process by which a given square matrix
Here’s a step-by-step guide to diagonalizing a matrix:
Find the Eigenvalues of
:A - Solve the characteristic equation
fordet ( A − λ I ) = 0 . The solutionsλ are the eigenvalues ofλ 1 , λ 2 , … , λ n .A
- Solve the characteristic equation
Find the Eigenvectors of
:A - For each eigenvalue
, solve the equationλ for the eigenvector( A − λ I ) v = 0 .v
- For each eigenvalue
Form the Matrix
:P - Construct the matrix
using the eigenvectors as columns.P
- Construct the matrix
Form the Diagonal Matrix
:D - Construct the matrix
by placing the eigenvaluesD on the diagonal. The order of the eigenvalues inλ i should correspond to the order of the eigenvectors inD .P
- Construct the matrix
Verify the Diagonalization:
- Verify that
by calculating both sides of the equation.A = P D P − 1
- Verify that
VIII. Singular Value Decomposition (SVD).
For a given
where:
is anU orthogonal matrix whose columns are called the left singular vectors ofm × m .A is anΣ diagonal matrix with non-negative real numbers on the diagonal, known as the singular values ofm × n .A is anV orthogonal matrix whose columns are called the right singular vectors ofn × n .A
Steps to Compute the SVD
Compute
andA T A :A A T - These are both symmetric matrices.
Find the eigenvalues and eigenvectors:
- Compute the eigenvalues and eigenvectors of
. The eigenvalues are the squares of the singular values ofA T A .A - Compute the eigenvalues and eigenvectors of
. The eigenvectors form the columns ofA A T andU .V
- Compute the eigenvalues and eigenvectors of
Construct
:Σ - The singular values
are the square roots of the eigenvalues ofσ i .A T A
- The singular values
Form the matrices
andU :V - The columns of
are the eigenvectors ofU .A A T - The columns of
are the eigenvectors ofV .A T A
- The columns of
Applications of SVD in Machine Learning: