Lectures on Numerical Linear Algebra
Total Page:16
File Type:pdf, Size:1020Kb
Lectures on Numerical Linear Algebra Yunkai Zhou Department of Mathematics Southern Methodist University Dallas, Texas 75075 [email protected] Spring, 2015 Acknowledgements The lecture slides benefit from the following resources Prof. Per-Olof Persson’s course materials for MIT 18.335 (Thanks Per-Olof for the tex files of slides) Prof. Yousef Saad’s book on iterative methods (Thanks Yousef for the tex files of course materials) Several well-known textbooks on NLA by J. Demmel, Trefethen and Bau, G. W. Stewart, C. D. Meyer, Golub and Van Loan Several other books on matrix analysis and matrix computations Several books/papers on theory and applications of LA The Wikipedia website The open source software: Linux, LATEX, beamer, pstricks The instructor greatly acknowledges NSF for grants CMMI-0727194 and OCI-0749074. Y. Zhou Math-6316/CS-7366, SMU 2/230 Lecture Outline Some Background on Linear Algebra Elementary matrices Vector norms, matrix norms Inner product, orthogonality, orthogonal matrices Matrix Decompositions: Overview Singular Value Decomposition (SVD) Schur Decomposition, Variational Principle, Pseudo Inverse Variational Principle Pseudo-inverse (Generalized Inverse) QR Decomposition: Projection, Reflection, Rotation Linear Least Squares Problems Linear Equations: GE/LU, Cholesky Conditioning and Stability Floating Points Eigenvalue Problems: Concepts and Algorithms Y. Zhou Math-6316/CS-7366, SMU 3/230 Basic Linear Algebra Spaces: Rn, Cn, Rn×n, Cn×n, Rm×n, Cm×n (by default, Rn = Rn×1, Cn = Cn×1) (Real: Rn, Rn×n, Rm×n; Complex: Cn, Cn×n, Cm×n) Y. Zhou Math-6316/CS-7366, SMU 4/230 Basic Linear Algebra Spaces: Rn, Cn, Rn×n, Cn×n, Rm×n, Cm×n (by default, Rn = Rn×1, Cn = Cn×1) (Real: Rn, Rn×n, Rm×n; Complex: Cn, Cn×n, Cm×n) Vectors: v Rn (length-n column real vector) v ∈ Cn (length-n column complex vector) w ∈ R1×n (length-n row real vector) w ∈ C1×n (length-n row complex vector) ∈ (We use column vector as the default, so a vector means a column vector) Y. Zhou Math-6316/CS-7366, SMU 4/230 Basic Linear Algebra Spaces: Rn, Cn, Rn×n, Cn×n, Rm×n, Cm×n (by default, Rn = Rn×1, Cn = Cn×1) (Real: Rn, Rn×n, Rm×n; Complex: Cn, Cn×n, Cm×n) Vectors: v Rn (length-n column real vector) v ∈ Cn (length-n column complex vector) w ∈ R1×n (length-n row real vector) w ∈ C1×n (length-n row complex vector) ∈ (We use column vector as the default, so a vector means a column vector) Special vectors: Length-n basis vector: ei ei : (all elements equal to 0 except the i-th element equals to 1) n Length-n vector of all-ones: 1 =[1, 1, , 1]T = e ··· i n Xi=1 Y. Zhou Math-6316/CS-7366,| SMU {z } 4/230 Basic Linear Algebra Matrices: (element-wise) An m n matrix A Rm×n (or A Cm×n) × ∈ ∈ A = ai,j where a R (or C), i = 1, 2,..., m, j = 1, 2,..., n. i,j ∈ Y. Zhou Math-6316/CS-7366, SMU 5/230 Basic Linear Algebra Matrices: (element-wise) An m n matrix A Rm×n (or A Cm×n) × ∈ ∈ A = ai,j where a R (or C), i = 1, 2,..., m, j = 1, 2,..., n. i,j ∈ Matrices: (vector-wise) An m n matrix A Rm×n (or A Cm×n) × ∈ ∈ A = a1, a2, , an ··· where a Rm (or Cm), i = 1, 2,..., n. i ∈ Y. Zhou Math-6316/CS-7366, SMU 5/230 Basic Linear Algebra Transpose: T A =[a ]m n A =[a ]n m i,j × ⇐⇒ j,i × Example: a11 a12 T a11 a21 a31 A = a21 a22 A = ⇐⇒ a12 a22 a32 a31 a32 Y. Zhou Math-6316/CS-7366, SMU 6/230 Basic Linear Algebra Transpose: T A =[a ]m n A =[a ]n m i,j × ⇐⇒ j,i × Example: a11 a12 T a11 a21 a31 A = a21 a22 A = ⇐⇒ a12 a22 a32 a31 a32 Adjoint (conjugate transpose) : H ∗ A =[a ]m n A = A =[a¯ ]n m i,j × ⇐⇒ j,i × Example: a11 a12 H a¯11 a¯21 a¯31 A = a21 a22 A = ⇐⇒ a¯12 a¯22 a¯32 a31 a32 Y. Zhou Math-6316/CS-7366, SMU 6/230 Basic Linear Algebra A is symmetric: if A = AT (usually it refers to “real” symmetric, it can also be “complex” symmetric) A is hermitian: if A = AH (or A = A∗) Vector-wise notation: a Cm aT C1×m ∈ ⇐⇒ ∈ T a1 aT m×n T 2 n×m A = a1, a2, , an C A = . C ··· ∈ ⇐⇒ . ∈ aT n Y. Zhou Math-6316/CS-7366, SMU 7/230 Basic Linear Algebra Let b =(b ) Rm, A =(a ) Rm×n, x =(x ) Rn i ∈ i,j ∈ i ∈ Matrix-vector product b = Ax n Element-wise bi = ai,j xj , i = 1, 2,..., m j=1 Xn Vector-wise b = aj xj Xj=1 Any A Cm×n is a linear mapping from Cn to Cm, meaning that ∈ A(x + y) = Ax + Ay, x, y Cn ∀ ∈ A(αx) = αAx, α C ∀ ∈ Conversely, any linear mapping in finite dimensional space can be expressed as a matrix-vector product Y. Zhou Math-6316/CS-7366, SMU 8/230 Basic Linear Algebra Let b =(b ) Rm, A =(a ) Rm×n, x =(x ) Rn i ∈ j ∈ i ∈ Matrix-vector product b = Ax Vector-wise n b = aj xj Xj=1 = x1[a1] + x2[a2] + xn[an] ··· b is a linear combination of the columns of A Any column of A can be picked out by choosing a specific x, e.g. aj = A(:, j) = Aej Any row of of A can be picked out by matrix-vector product, e.g. T A(i, :) = ei A Y. Zhou Math-6316/CS-7366, SMU 9/230 Basic Linear Algebra Let A =(a ) Rm×n, B =(b ) Rn×k , C =(c ) Rm×k j ∈ j ∈ j ∈ Matrix-matrix product C = AB Vector-wise (compare columns in C = AB) [c1, c2,..., ck ] = A[b1, b2,..., bk ] n = cj = Abj = ak bk j ⇒ , Xk=1 Each cj is a linear combination of the columns of A Y. Zhou Math-6316/CS-7366, SMU 10/230 Basic Linear Algebra Subroutines (BLAS) – Standardized interface for simple vector and matrix operations – The building block of LAPACK (as the one used in Matlab) – Optimized implementations for specific machines provided by manufacturers History: – BLAS1 (1970s) Vector operations: β = x Ty, y = βx + y – BLAS2 (mid 1980s) Matrix-vector operations: y = Ax + y – BLAS3 (late 1980s) Matrix-matrix operations: C = AB + C Careful cache-aware implementations give close to peak performance for BLAS3 operations High level algorithms (Gaussian elimination, etc) use BLAS but no other machine dependent code – Performance and portability Y. Zhou Math-6316/CS-7366, SMU 11/230 Memory Hierarchy and (BLAS) Modern computers use a memory hierarchy: From fast/expensive to cheap/slow: Registers, L1 cache, L2 cache, (L3 cache ...) local memory, remote memory, secondary memory Fast algorithms perform many operations on each memory block to minimize memory access (cache reuse) Only BLAS3 has potential for very high performance BLAS Memory Refs Flops Flops/Memory Ref Level 1 (y = βx + y) 3n 2n 2/3 Level 2 (y = Ax + y) n2 2n2 2 Level 3 (C = AB + C) 4n2 2n3 n/2 Flop — floating points operations, here each +, , , /, √ counts as one flop, with no distinction between real and complex. − ∗ Y. Zhou Math-6316/CS-7366, SMU 12/230 BLAS implementations Vendor provided: — Intel Math Kernel Library (MKL) — AMD Core Math Library (ACML) — Sun Performance Library — SGI Scientific Computing Software Library Automatically Tuned Linear Algebra Software (ATLAS) — Analyzes hardware to produce BLAS libraries for any platform — Used in MATLAB, precompiled libraries freely available — Sometimes outperforms vendor libraries GOTO BLAS (mainly for Intel processors) — Manually optimized assembly code, (fastest implementation for Intel processors) Y. Zhou Math-6316/CS-7366, SMU 13/230 Basic Linear Algebra Examples of matrix-matrix product: Outer product: (rank-1) For a =(a ) Cm, b =(b ) Cn, (a , b C) i ∈ i ∈ i i ∈ H m×n ab =[ab¯1, ab¯2, , ab¯n]=(a b ) C ··· i j ∈ Outer product: (rank k) For U =[u ] Cm×k ,≤V =[v ] Cn×k , (u Cm, v Cn) j ∈ j ∈ j ∈ j ∈ H v1 v H k H 2 H Cm×n UV =[u1, u2, , uk ] . = uj vj ··· . ∈ j=1 v H X k Rank-k SVD is a representative rank-k outer product. H k H A = UΣV = j=1 σj uj vj Y. Zhou Math-6316/CS-7366,P SMU 14/230 Basic Linear Algebra Examples of matrix-matrix product: A Cm×n ∈ Right multiply by an upper triangular matrix: B = AR Let R =(r ) Cn×n be upper triangular, ij ∈ r11 r1n j ···. B = AR =[a1, a2, , an] . = b = a r ··· . ⇒ j ℓ ℓj r ℓ=1 nn X (bj is a linear combination of only the first j columns of A) Right multiply by a lower triangular matrix: B = AL, L Cn×n (b is a linear combination of only the last n j + 1 columns∈ of A j − Left multiply by an upper triangular matrix: B = RA, R Cm×m (i-th row of B is a linear combination of last m i + 1 rows∈ of A) − Left multiply by a lower triangular matrix: B = LA, L Cm×m (i-th row of B is a linear combination of only the first ∈i rows of A) Y. Zhou Math-6316/CS-7366, SMU 15/230 Basic Linear Algebra: Range, Nullspace m×n The range or column space of A =[a1, a2,..., an] C : ∈ range(A) = span a1, a2,..., an { } = All linear combinations of the columns of A = Ax x Cn { |∀ ∈ } The nullspace of A Cm×n: (also written as kernel space ker(A)) ∈ null(A)= x Ax = 0 { | } Relation between range(AH) and null(A) null(A)=(range(AH))⊥ Equivalently, Rank-nullity theorem: rank(A)+ dim(null(A)) = n Y.