Docsity

LINEAR ALGEBRA & NUMERICAL ANALYSIS, Study notes of Linear Algebra

Partial preview of the text

Download LINEAR ALGEBRA & NUMERICAL ANALYSIS and more Study notes Linear Algebra in PDF only on Docsity!

LINEAR ALGEBRA & NUMERICAL

ANALYSIS

LANA — Complete Notes

Prof. Dr. Debanjan Roy

Weeks 1– 13

WEEK 1 — Introduction: Matrices & Vectors in Data Science & AI

  • Matrices & Vectors are used in Data Science and AI
  • Computer Programming is needed for solving big data problems
  • Used in Networks

What is a Vector?

  • Physics: Vector has Magnitude and Direction
  • Mathematics: Considers position in 2D Plane or 3D Space
  • Computer Science: Deals with Dimensions — any number (3D, 4D, 2046D, 4028D...) WEEK 2 — Vectors & Matrices: The Language of Data
  • Linear Algebra = Mathematics of Data
  • Matrices & Vectors = Language of Data
  • Interpretable = Something that can be understood and explained (Numbers are interpretable)
  • Everything is written in numbers — whether it's images, X-rays, gamma rays, etc.

Vector

  • An Ordered List of Numbers ◦ Example: [-1, 0.0, 3.6, - 7.2] → 4-Dimensional (4D) vector ◦ Written as column (matrix form) or row
  • n-size vector = n-vector
  • These numbers are called scalars
  • Zero Vector: (0, 0, ...0) — size n×
  • Unit Vector: Vector whose magnitude is 1

Vector in Python (NumPy)

import numpy as np as_list = [1, 2, 3] as_array = np.array([1, 2, 3]) # 1D array row_vec = np.array([[1, 2, 3]]) # Row vector col_vec = np.array([[1],[2],[3]]) # Column vector

  • Vector = Single Row
  • Matrices = Multiple Rows
  • Dimensions = Number of values in your vector
  • For Column: ([[col1],[col2],[col3],...])
  • For Rows: ([a, b, c, ...])

A + λI → A_(2×2) = [[a,2],[2,a]] + λ[[1,0],[0,1]] = [[a+λ, 2],[2, a+λ]] np.eye(len(A)) # Identity Matrix I of size A A + s * np.eye(len(A)) # Shifting

Matrix Scalar Multiplication

  • kA = Ak (A = matrix, k = scalar) ◦ Property 1: k(A+B) = kA + kB → Distributive ◦ Property 2: (k+q)A = kA + qA → Linear Combination ◦ Property 3: k(AB) = (kA)B = A(kB) → Associative ◦ Property 4: k(qA) = (kq)A

Matrix Multiplication

[M×N] × [N×K] = [M×K]

📝 Note: No. of columns of 1st Matrix = No. of rows of 1st Matrix (Conformable)

  • Properties: ◦ A(BC) = (AB)C = ABC → Associative Law ◦ A(B+C) = AB + BC → Distributive Law ◦ AB ≠ BA → NOT Commutative ◦ AB = 0 does NOT mean A=0 or B= ◦ AB = AC does NOT necessarily mean B = C
  • IA = A (Identity Matrix) WEEK 5 — Transpose & Special Matrices
  • Rows in Dataset → Samples
  • Columns in Dataset → Features
  • Some ML Algorithms → Principal Component Analysis (PCA) → Requires Transpose

Transpose

  • Flipping the matrix: rows become columns If A is [m×n], then Aᵀ is [n×m]

Python Code

A_T1 = A.T # As Method A_T2 = np.transpose(A) # As Function

Transpose Properties

◦ (A+B)ᵀ = Aᵀ + Bᵀ

◦ (AB)ᵀ = Bᵀ Aᵀ ← IMPORTANT

◦ (kA)ᵀ = k Aᵀ ◦ (Aᵀ)ᵀ = A

Stochastic Matrix

  • All entries are non-negative
  • All column sums equal to 1
  • Used in Markov Process → Probability of entering a certain state

Symmetric Matrix

  • Rows and Columns should be equal (Square Matrix)
  • A Square Matrix is Symmetric if A = Aᵀ
  • Applications: Image Processing, Mathematics (Covariance Matrix), SVM (Kernel Matrix), Network Analysis
  • Non-Symmetric to Symmetric: If A is M×N, then AᵀA = (N×M)(M×N) = N×N (Square & Symmetric) WEEK 5– 6 — Determinant & Inverse

Determinant

det([[a,b],[c,d]]) = ad - bc np.linalg.det(A) # NumPy scipy.linalg.det(A) # SciPy

📝 Note: If determinant = 0 (Singular Matrix), Inverse is NOT possible

Inverse Matrix

  • Applications: Solving Linear Systems, 3D Computer Graphics, Encryption/Decryption, GPS Systems For 2×2: M ⁻ ¹ = (1/det) × [[d, - b],[-c, a]]
  • Theorems:

◦ (A ⁻ ¹) ⁻ ¹ = A

◦ (AB) ⁻ ¹ = B ⁻ ¹A ⁻ ¹

◦ (Aᵀ) ⁻ ¹ = (A ⁻ ¹)ᵀ

np.linalg.inv(A) invert_matrix(A)

📝 Note: A matrix is invertible if and only if it has full rank

Rank

  • Max. number of linearly independent rows or columns
  • Can't be negative
  • max(r) = min(m, n)
  • rank(A) ≤ min(m, n)
  • Full Rank = Square matrix without any dependency
  • Only Matrix with Rank = 0 is Zero Matrix np.linalg.matrix_rank(A) WEEK 6 — Row Echelon Form (REF)

WEEK 8 — Eigenvalues & Eigenvectors

  • Real world applications: Image Compression, Google's PageRank Algorithm

Definition

  • Eigenvector: Special vector whose direction does NOT change when multiplied with matrix
  • Eigenvalue: The scalar by which eigenvector is scaled Av = λv (Eigenvalue Equation) ◦ A = n×n matrix ◦ λ = scalar (eigenvalue) ◦ x = non-zero vector (eigenvector)

Characteristic Equation

Ax = λx Ax - λx = 0 (A - λI ₙ )x = 0 |A - λI ₙ | = 0 ← Characteristic Equation

Eigenspace

  • Set of all eigenvectors of λ together with zero vector = Subspace of Rⁿ = Eigenspace of λ

Matrix Diagonalization

  • For Triangular Matrix: Eigenvalues are the diagonal entries
  • Diagonal Matrix is also a Triangular Matrix If D = [[λ ₁ ,0],[0,λ ₂ ]], then Dᵏ = [[λ ₁ ᵏ,0],[0,λ ₂ ᵏ]] Diagonalization: P ⁻ ¹AP = D (P = invertible matrix)

📝 Note: If A and B are similar matrices (B = P ⁻ ¹AP), they have same eigenvalues

📝 Note: If A = symmetric matrix & λ ₁ ,λ ₂ = distinct eigenvalues, their eigenvectors are

orthogonal

Python Code

np.linalg.eig(A)[0] # Eigenvalues np.linalg.eigvals(A) # Eigenvalues only np.linalg.eig(A) # Eigenvectors WEEK 9 — Vector Spaces & Span

  • Real world: Mechanics, Structural Engineering, Computer Graphics, Economics
  • Refers to objects for which addition & scalar multiplication are defined
  • Distributive Property: (α+β)(v+w) = αv + αw + βv + βw

Trace of a Matrix

  • Trace = Addition of the diagonal entries

Span

  • Set of all linear combinations of given vectors with same no. of components c ₁ v ₁ + c ₂ v ₂ + ... + c ₙ v ₙ = 0 (if c ₁ ≠ 0, vectors are Linearly Dependent)
  • span{v₁,v₂,...,vₙ} = span{v₂,v₃,...,vₙ} if v₁ is dependent on others

Subspace of Vector Spaces

  • A subset W of V is called Subspace of V only if: ◦ 1. Zero vector of V is also in W

◦ 2. W is closed under addition (u,v ∈ W → u+v ∈ W)

◦ 3. W is closed under scalar multiplication (u ∈ W, α scalar → αu ∈ W)

Basis Vectors

  • Linearly Independent Vectors
  • Used to represent any vector in vector space Standard vectors: e ₁ =[1,0], e ₂ =[0,1] (for 2D) WEEK 10 — Linear Dependence & Independence

Definitions

  • Linearly Dependent: At least one λ ≠ 0 in λ₁v₁ = λ₂v₂ + ... + λₙvₙ
  • Linearly Independent: All λ = 0

Basis

  • Span + Independence = Basis
  • Vectors that Span the space + are Linearly Independent
  • Standard basis: e₁=[1,0], e₂=[0,1] (2D); Identity matrix vectors (ND)

Function Spaces

  • Vector spaces where elements are functions from a set to a field
  • f(t) + g(t) differentiable → Linearly Dependent if c₁f(t)+c₂g(t) = 0
  • Otherwise Linearly Independent

Python (Matplotlib)

import matplotlib.pyplot as plt plt.arrow(0, 0, v1[0], v1[1]) plt.arrow(0, 0, v2[0], v2[1])

◦ Q = Orthogonal Matrix ◦ R = Triangular Matrix (Upper Δr) Q, R = np.linalg.qr(A) A ⁻ ¹ = R ⁻ ¹ Qᵀ ← Important Result

  • Economy: Reduced → Q_eco = m×n, R_eco = n×n
  • Full: Complete → Q_full = m×m, R_full = m×n
  • Purpose: All this to SOLVE SYSTEM OF LINEAR EQUATIONS ◦ A = Any Matrix ◦ Q = Orthonormal Matrix ◦ R = Resultant Matrix WEEK 13 — LU Decomposition & Gauss Elimination
  • LU Decomposition: Similar to QR — mixture of Row Reduction & Gaussian Elimination

LU Decomposition

A = LU

◦ L = Lower Triangular Matrix ◦ U = Upper Triangular Matrix L ⁻ ¹A = U → Linear Transformation from scipy.linalg import lu L, U = scipy.linalg.lu(Matrix_Name)

Row Reduction → Scalar Multiplication & Addition

[[2,3],[-2,2]] R ₂ =R ₁ +R ₂ → [[2,3],[0,5]] → Upper Triangular

Gauss Elimination

  • Row Reduced Form → then further to RREF (Gauss-Jordan)

📝 Note: In Gauss Elimination: no need to find any Inverse to solve the problem

📝 Note: In Gauss-Jordan: instead of Row Reduced Form, it is Row Reduced Echelon

Form (RREF)

Applications of LU

  • Engineering: Structural Analysis, Electrical Circuit Analysis, Fluid Dynamics & Heat Transfer
  • Computer Science: Computer Graphics, Machine Learning, Network Flow Algorithms Quick Reference — Key Formulas

Concept Formula / Key Point Magnitude ||v||^ =^ √(v₁²^ +^ v₂²^ +^ ...^ +^ vₙ²) Scalar × Vector ||kv||^ =^ |k|^ ·^ ||v|| Matrix Mult. [M×N]^ ×^ [N×K]^ =^ [M×K] Transpose (AB)ᵀ^ =^ BᵀAᵀ Determinant 2×2 det([[a,b],[c,d]])^ =^ ad^ -^ bc Inverse Formula A⁻¹^ =^ adj^ A^ /^ |A| Eigenvalue Eq. Ax^ =^ λx^ →^ |A^ -^ λI|^ =^0 Projection proj_a(b)^ =^ (aᵀb^ /^ aᵀa)^ ·^ a QR Result A⁻¹^ =^ R⁻¹^ Qᵀ LU Decomp. A^ =^ LU^ (L=Lower,^ U=Upper^ Triangular) Orthogonal Matrix QᵀQ^ =^ I Symmetric Matrix A^ =^ Aᵀ