Scientific Computing: Dense Linear Systems

Similar documents
Numerical Methods I Solving Square Linear Systems: GEM and LU factorization

Scientific Computing: Solving Linear Systems

Numerical Methods I Non-Square and Sparse Linear Systems

Linear Algebra Section 2.6 : LU Decomposition Section 2.7 : Permutations and transposes Wednesday, February 13th Math 301 Week #4

MTH 464: Computational Linear Algebra

Linear Algebra Massoud Malek

Review of Basic Concepts in Linear Algebra

Lecture 9. Errors in solving Linear Systems. J. Chaudhry (Zeb) Department of Mathematics and Statistics University of New Mexico

Linear Algebra and Matrix Inversion

Scientific Computing

Basic Concepts in Linear Algebra

A Review of Matrix Analysis

LU Factorization. Marco Chiarandini. DM559 Linear and Integer Programming. Department of Mathematics & Computer Science University of Southern Denmark

Computational Methods. Systems of Linear Equations

MATH 3511 Lecture 1. Solving Linear Systems 1

Linear Algebra Formulas. Ben Lee

Fundamentals of Engineering Analysis (650163)

Outline. Math Numerical Analysis. Errors. Lecture Notes Linear Algebra: Part B. Joseph M. Mahaffy,

Numerical Methods I Eigenvalue Problems

9. Numerical linear algebra background

Math 4A Notes. Written by Victoria Kala Last updated June 11, 2017

Linear Algebra Review. Vectors

MATH2210 Notebook 2 Spring 2018

MATH 240 Spring, Chapter 1: Linear Equations and Matrices

Lecture 7. Gaussian Elimination with Pivoting. David Semeraro. University of Illinois at Urbana-Champaign. February 11, 2014

Numerical Linear Algebra

MATH 315 Linear Algebra Homework #1 Assigned: August 20, 2018

Foundations of Matrix Analysis

G1110 & 852G1 Numerical Linear Algebra

MATH 323 Linear Algebra Lecture 12: Basis of a vector space (continued). Rank and nullity of a matrix.

Linear Algebra Review

lecture 2 and 3: algorithms for linear algebra

COURSE Numerical methods for solving linear systems. Practical solving of many problems eventually leads to solving linear systems.

Linear Algebra Highlights

Jim Lambers MAT 610 Summer Session Lecture 1 Notes

1.Chapter Objectives

AMS526: Numerical Analysis I (Numerical Linear Algebra)

Conceptual Questions for Review

Numerical Linear Algebra

GAUSSIAN ELIMINATION AND LU DECOMPOSITION (SUPPLEMENT FOR MA511)

CHAPTER 6. Direct Methods for Solving Linear Systems

AMS526: Numerical Analysis I (Numerical Linear Algebra)

1 Multiply Eq. E i by λ 0: (λe i ) (E i ) 2 Multiply Eq. E j by λ and add to Eq. E i : (E i + λe j ) (E i )

AMS526: Numerical Analysis I (Numerical Linear Algebra for Computational and Data Sciences)

CS227-Scientific Computing. Lecture 4: A Crash Course in Linear Algebra

lecture 3 and 4: algorithms for linear algebra

Numerical Linear Algebra

B553 Lecture 5: Matrix Algebra Review

2. Linear algebra. matrices and vectors. linear equations. range and nullspace of matrices. function of vectors, gradient and Hessian

Math 4153 Exam 3 Review. The syllabus for Exam 3 is Chapter 6 (pages ), Chapter 7 through page 137, and Chapter 8 through page 182 in Axler.

Solving Linear Systems of Equations

Linear Algebraic Equations

9. Numerical linear algebra background

MAT 610: Numerical Linear Algebra. James V. Lambers

MATRIX ALGEBRA AND SYSTEMS OF EQUATIONS. + + x 1 x 2. x n 8 (4) 3 4 2

Numerical Methods I Singular Value Decomposition

Final Review Sheet. B = (1, 1 + 3x, 1 + x 2 ) then 2 + 3x + 6x 2

2.1 Gaussian Elimination

MATH 2331 Linear Algebra. Section 2.1 Matrix Operations. Definition: A : m n, B : n p. Example: Compute AB, if possible.

Review of Some Concepts from Linear Algebra: Part 2

Cheat Sheet for MATH461

1 Linear Algebra Problems

Introduction to Matrices

MAT Linear Algebra Collection of sample exams

Chapter 4 - MATRIX ALGEBRA. ... a 2j... a 2n. a i1 a i2... a ij... a in

Math 1553 Introduction to Linear Algebra

Chapter 4 No. 4.0 Answer True or False to the following. Give reasons for your answers.

2. Every linear system with the same number of equations as unknowns has a unique solution.

Linear Algebra Review

Index. book 2009/5/27 page 121. (Page numbers set in bold type indicate the definition of an entry.)

NOTES on LINEAR ALGEBRA 1

MTH 464: Computational Linear Algebra

LINEAR ALGEBRA REVIEW

MATH 20F: LINEAR ALGEBRA LECTURE B00 (T. KEMP)

Review of Matrices and Block Structures

Online Exercises for Linear Algebra XM511

Matrix & Linear Algebra

MATH 304 Linear Algebra Lecture 34: Review for Test 2.

Math 18, Linear Algebra, Lecture C00, Spring 2017 Review and Practice Problems for Final Exam

IMPORTANT DEFINITIONS AND THEOREMS REFERENCE SHEET

Math Camp Lecture 4: Linear Algebra. Xiao Yu Wang. Aug 2010 MIT. Xiao Yu Wang (MIT) Math Camp /10 1 / 88

Elementary linear algebra

Problem Set (T) If A is an m n matrix, B is an n p matrix and D is a p s matrix, then show

ANSWERS (5 points) Let A be a 2 2 matrix such that A =. Compute A. 2

IMPORTANT DEFINITIONS AND THEOREMS REFERENCE SHEET

CSL361 Problem set 4: Basic linear algebra

ANALYTICAL MATHEMATICS FOR APPLICATIONS 2018 LECTURE NOTES 3

Dot Products, Transposes, and Orthogonal Projections

Direct Methods for Solving Linear Systems. Simon Fraser University Surrey Campus MACM 316 Spring 2005 Instructor: Ha Le

A Review of Linear Algebra

Chapter 3 Transformations

Equality: Two matrices A and B are equal, i.e., A = B if A and B have the same order and the entries of A and B are the same.

Numerical Linear Algebra

Program Lecture 2. Numerical Linear Algebra. Gaussian elimination (2) Gaussian elimination. Decompositions, numerical aspects

Direct Methods for Solving Linear Systems. Matrix Factorization

Math Linear Algebra Final Exam Review Sheet

Engineering Computation

Chapter 5 Eigenvalues and Eigenvectors

MATH 1120 (LINEAR ALGEBRA 1), FINAL EXAM FALL 2011 SOLUTIONS TO PRACTICE VERSION

Review problems for MA 54, Fall 2004.

Transcription:

Scientific Computing: Dense Linear Systems Aleksandar Donev Courant Institute, NYU 1 donev@courant.nyu.edu 1 Course MATH-GA.2043 or CSCI-GA.2112, Spring 2012 February 9th, 2012 A. Donev (Courant Institute) Lecture III 2/9/2011 1 / 34

Outline 1 Linear Algebra Background 2 Conditioning of linear systems 3 Gauss elimination and LU factorization 4 Conclusions A. Donev (Courant Institute) Lecture III 2/9/2011 2 / 34

Linear Spaces Linear Algebra Background A vector space V is a set of elements called vectors x V that may be multiplied by a scalar c and added, e.g., z = αx + βy I will denote scalars with lowercase letters and vectors with lowercase bold letters. Prominent examples of vector spaces are R n (or more generally C n ), but there are many others, for example, the set of polynomials in x. A subspace V V of a vector space is a subset such that sums and multiples of elements of V remain in V (i.e., it is closed). An example is the set of vectors in x R 3 such that x 3 = 0. A. Donev (Courant Institute) Lecture III 2/9/2011 3 / 34

Image Space Linear Algebra Background Consider a set of n vectors a 1, a 2,, a n R m and form a matrix by putting these vectors as columns A = [a 1 a 2 a m ] R m,n. I will denote matrices with bold capital letters, and sometimes write A = [m, n] to indicate dimensions. The matrix-vector product is defined as a linear combination of the columns: b = Ax = x 1 a 1 + x 2 a 2 + + x n a n R m. The image im(a) or range range(a) of a matrix is the subspace of all linear combinations of its columns, i.e., the set of all b s. It is also sometimes called the column space of the matrix. A. Donev (Courant Institute) Lecture III 2/9/2011 4 / 34

Dimension Linear Algebra Background The set of vectors a 1, a 2,, a n are linearly independent or form a basis for R m if b = Ax = 0 implies that x = 0. The dimension r = dimv of a vector (sub)space V is the number of elements in a basis. This is a property of V itself and not of the basis, for example, dim R n = n Given a basis A for a vector space V of dimension n, every vector of b V can be uniquely represented as the vector of coefficients x in that particular basis, b = x 1 a 1 + x 2 a 2 + + x n a n. A simple and common basis for R n is {e 1,..., e n }, where e k has all components zero except for a single 1 in position k. With this choice of basis the coefficients are simply the entries in the vector, b x. A. Donev (Courant Institute) Lecture III 2/9/2011 5 / 34

Kernel Space Linear Algebra Background The dimension of the column space of a matrix is called the rank of the matrix A R m,n, r = rank A min(m, n). If r = min(m, n) then the matrix is of full rank. The nullspace null(a) or kernel ker(a) of a matrix A is the subspace of vectors x for which Ax = 0. The dimension of the nullspace is called the nullity of the matrix. For a basis A the nullspace is null(a) = {0} and the nullity is zero. A. Donev (Courant Institute) Lecture III 2/9/2011 6 / 34

Linear Algebra Background Orthogonal Spaces An inner-product space is a vector space together with an inner or dot product, which must satisfy some properties. The standard dot-product in R n is denoted with several different notations: n x y = (x, y) = x, y = x T y = x i y i. For C n we need to add complex conjugates (here denotes a complex conjugate transpose, or adjoint), i=1 x y = x y = n x i y i. i=1 Two vectors x and y are orthogonal if x y = 0. A. Donev (Courant Institute) Lecture III 2/9/2011 7 / 34

Linear Algebra Background Part I of Fundamental Theorem One of the most important theorems in linear algebra is that the sum of rank and nullity is equal to the number of columns: For A R m,n rank A + nullity A = n. In addition to the range and kernel spaces of a matrix, two more important vector subspaces for a given matrix A are the: Row space or coimage of a matrix is the column (image) space of its transpose, im A T. Its dimension is also equal to the the rank. Left nullspace or cokernel of a matrix is the nullspace or kernel of its transpose, ker A T. A. Donev (Courant Institute) Lecture III 2/9/2011 8 / 34

Linear Algebra Background Part II of Fundamental Theorem The orthogonal complement V or orthogonal subspace of a subspace V is the set of all vectors that are orthogonal to every vector in V. Let V be the set of vectors in x R 3 such that x 3 = 0. Then V is the set of all vectors with x 1 = x 2 = 0. Second fundamental theorem in linear algebra: im A T = (ker A) ker A T = (im A) A. Donev (Courant Institute) Lecture III 2/9/2011 9 / 34

Linear Algebra Background Linear Transformation A function L : V W mapping from a vector space V to a vector space W is a linear function or a linear transformation if L(αv) = αl(v) and L(v 1 + v 2 ) = L(v 1 ) + L(v 2 ). Any linear transformation L can be represented as a multiplication by a matrix L L(v) = Lv. For the common bases of V = R n and W = R m, the product w = Lv is simply the usual matix-vector product, w i = n L ik v k, k=1 which is simply the dot-product between the i-th row of the matrix and the vector v. A. Donev (Courant Institute) Lecture III 2/9/2011 10 / 34

Matrix algebra Linear Algebra Background w i = (Lv) i = n L ik v k k=1 The composition of two linear transformations A = [m, p] and B = [p, n] is a matrix-matrix product C = AB = [m, n]: z i = n A ik y k = k=1 p z = A (Bx) = Ay = (AB) x A ik k=1 j=1 n B kj x j = C ij = ( n p ) A ik B kj x j = j=1 p A Ik B kj k=1 k=1 Matrix-matrix multiplication is not commutative, AB BA in general. n C ij x j A. Donev (Courant Institute) Lecture III 2/9/2011 11 / 34 j=1

Linear Algebra Background The Matrix Inverse A square matrix A = [n, n] is invertible or nonsingular if there exists a matrix inverse A 1 = B = [n, n] such that: AB = BA = I, where I is the identity matrix (ones along diagonal, all the rest zeros). The following statements are equivalent for A R n,n : A is invertible. A is full-rank, rank A = n. The columns and also the rows are linearly independent and form a basis for R n. The determinant is nonzero, det A 0. Zero is not an eigenvalue of A. A. Donev (Courant Institute) Lecture III 2/9/2011 12 / 34

Linear Algebra Background Matrix Algebra Matrix-vector multiplication is just a special case of matrix-matrix multiplication. Note x T y is a scalar (dot product). C (A + B) = CA + CB and ABC = (AB) C = A (BC) ( A T ) T = A and (AB) T = B T A T ( A 1 ) 1 = A and (AB) 1 = B 1 A 1 and ( A T ) 1 = ( A 1 ) T Instead of matrix division, think of multiplication by an inverse: AB = C ( A 1 A ) { B = A 1 B = A 1 C C A = CB 1 A. Donev (Courant Institute) Lecture III 2/9/2011 13 / 34

Vector norms Linear Algebra Background Norms are the abstraction for the notion of a length or magnitude. For a vector x R n, the p-norm is and special cases of interest are: ( n ) 1/p x p = x i p 1 The 1-norm (L 1 norm or Manhattan distance), x 1 = n i=1 x i 2 The 2-norm (L 2 norm, Euclidian distance), x 2 = n x x = i=1 x i 2 3 The -norm (L or maximum norm), x = max 1 i n x i 1 Note that all of these norms are inter-related in a finite-dimensional setting. i=1 A. Donev (Courant Institute) Lecture III 2/9/2011 14 / 34

Matrix norms Linear Algebra Background Matrix norm induced by a given vector norm: Ax A = sup x 0 x Ax A x The last bound holds for matrices as well, AB A B. Special cases of interest are: 1 The 1-norm or column sum norm, A 1 = max j n i=1 a ij 2 The -norm or row sum norm, A = max i n j=1 a ij 3 The 2-norm or spectral norm, A 2 = σ 1 (largest singular value) 4 The Euclidian or Frobenius norm, A F = i,j a ij 2 (note this is not an induced norm) A. Donev (Courant Institute) Lecture III 2/9/2011 15 / 34

Conditioning of linear systems Matrices and linear systems It is said that 70% or more of applied mathematics research involves solving systems of m linear equations for n unknowns: n a ij x j = b i, i = 1,, m. j=1 Linear systems arise directly from discrete models, e.g., traffic flow in a city. Or, they may come through representing or more abstract linear operators in some finite basis (representation). Common abstraction: Ax = b Special case: Square invertible matrices, m = n, det A 0: x = A 1 b. The goal: Calculate solution x given data A, b in the most numerically stable and also efficient way. A. Donev (Courant Institute) Lecture III 2/9/2011 16 / 34

Conditioning of linear systems Stability analysis: rhs perturbations Perturbations on right hand side (rhs) only: A (x + δx) = b + δb b + Aδx = b + δb Using the bounds δx = A 1 δb δx A 1 δb b A x x b / A the relative error in the solution can be bounded by δx x A 1 δb A 1 δb x b / A = κ(a) δb b where the conditioning number κ(a) depends on the matrix norm used: κ(a) = A A 1 1. A. Donev (Courant Institute) Lecture III 2/9/2011 17 / 34

Conditioning of linear systems Stability analysis: matrix perturbations Perturbations of the matrix only: (A + δa) (x + δx) = b δx = A 1 (δa) (x + δx) δx x + δx A 1 δa = κ(a) δa A. Conclusion: The worst-case conditioning of the linear system is determined by κ(a) = A A 1 1 Solving an ill-conditioned system, κ(a) 1, should only be done if something is known about x or b (e.g., smooth solutions in PDEs). The conditioning number can only be estimated in practice since A 1 is not available (see MATLAB s rcond function). A. Donev (Courant Institute) Lecture III 2/9/2011 18 / 34

Conditioning of linear systems Mixed perturbations Now consider general perturbations of the data: (A + δa) (x + δx) = b + δb The full derivation, not given here, estimates the uncertainty or perturbation in the solution: ( δx x κ(a) δb 1 κ(a) δa b + δa ) A A Best possible error with rounding unit u u 10 16 : δx x 2uκ(A), which is close to what the MATLAB linear solvers achieve. It certainly makes no sense to try to solve systems with κ(a) > 10 15! A. Donev (Courant Institute) Lecture III 2/9/2011 19 / 34

Gauss elimination and LU factorization GEM: Eliminating x 1 A. Donev (Courant Institute) Lecture III 2/9/2011 20 / 34

Gauss elimination and LU factorization GEM: Eliminating x 2 A. Donev (Courant Institute) Lecture III 2/9/2011 21 / 34

Gauss elimination and LU factorization GEM: Backward substitution A. Donev (Courant Institute) Lecture III 2/9/2011 22 / 34

Gauss elimination and LU factorization GEM as an LU factorization tool We have actually factorized A as A = LU, L is unit lower triangular (l ii = 1 on diagonal), and U is upper triangular. GEM is thus essentially the same as the LU factorization method. A. Donev (Courant Institute) Lecture III 2/9/2011 23 / 34

Gauss elimination and LU factorization GEM in MATLAB Sample MATLAB code (for learning purposes only, not real computing!): f u n c t i o n A = MyLU(A) % LU f a c t o r i z a t i o n in p l a c e ( o v e r w r i t e A) [ n,m]= s i z e (A ) ; i f ( n = m) ; e r r o r ( Matrix not square ) ; end f o r k =1:(n 1) % For v a r i a b l e x ( k ) % C a l c u l a t e m u l t i p l i e r s i n column k : A( ( k +1):n, k ) = A( ( k +1):n, k ) / A( k, k ) ; % Note : P i v o t element A( k, k ) assumed nonzero! f o r j =(k +1): n % E l i m i n a t e v a r i a b l e x ( k ) : A( ( k +1):n, j ) = A( ( k +1):n, j )... A( ( k +1):n, k ) A( k, j ) ; end end end A. Donev (Courant Institute) Lecture III 2/9/2011 24 / 34

Pivoting Gauss elimination and LU factorization A. Donev (Courant Institute) Lecture III 2/9/2011 25 / 34

Gauss elimination and LU factorization Pivoting during LU factorization Partial (row) pivoting permutes the rows (equations) of A in order to ensure sufficiently large pivots and thus numerical stability: PA = LU Here P is a permutation matrix, meaning a matrix obtained by permuting rows and/or columns of the identity matrix. Complete pivoting also permutes columns, PAQ = LU. A. Donev (Courant Institute) Lecture III 2/9/2011 26 / 34

Gauss elimination and LU factorization Gauss Elimination Method (GEM) GEM is a general method for dense matrices and is commonly used. Implementing GEM efficiently and stably is difficult and we will not discuss it here, since others have done it for you! The LAPACK public-domain library is the main repository for excellent implementations of dense linear solvers. MATLAB uses a highly-optimized variant of GEM by default, mostly based on LAPACK. MATLAB does have specialized solvers for special cases of matrices, so always look at the help pages! A. Donev (Courant Institute) Lecture III 2/9/2011 27 / 34

Gauss elimination and LU factorization Solving linear systems Once an LU factorization is available, solving a linear system is simple: Ax = LUx = L (Ux) = Ly = b so solve for y using forward substitution. This was implicitly done in the example above by overwriting b to become y during the factorization. Then, solve for x using backward substitution Ux = y. If row pivoting is necessary, the same applies but L or U may be permuted upper/lower triangular matrices, A = LU = ( P T L ) U. A. Donev (Courant Institute) Lecture III 2/9/2011 28 / 34

Gauss elimination and LU factorization In MATLAB In MATLAB, the backslash operator (see help on mldivide) x = A\b A 1 b, solves the linear system Ax = b using the LAPACK library. Never use matrix inverse to do this, even if written as such on paper. Doing x = A\b is equivalent to performing an LU factorization and doing two triangular solves (backward and forward substitution): [ L, U] = lu(a) y = L\b x = U\y This is a carefully implemented backward stable pivoted LU factorization, meaning that the returned solution is as accurate as the conditioning number allows. A. Donev (Courant Institute) Lecture III 2/9/2011 29 / 34

Gauss elimination and LU factorization GEM Matlab example (1) >> A = [ 1 2 3 ; 4 5 6 ; 7 8 0 ] ; >> b=[2 1 1] ; >> x=aˆ( 1) b ; x % Don t do t h i s! ans = 2.5556 2.1111 0.1111 >> x = A\b ; x % Do t h i s i n s t e a d ans = 2.5556 2.1111 0.1111 >> l i n s o l v e (A, b ) % Even more c o n t r o l ans = 2.5556 2.1111 0.1111 A. Donev (Courant Institute) Lecture III 2/9/2011 30 / 34

Gauss elimination and LU factorization GEM Matlab example (2) >> [ L,U] = l u (A) % Even b e t t e r i f r e s o l v i n g L = 0.1429 1.0000 0 0.5714 0.5000 1.0000 1.0000 0 0 U = 7.0000 8.0000 0 0 0.8571 3.0000 0 0 4.5000 >> norm( L U A, i n f ) ans = 0 >> y = L\b ; >> x = U\y ; x ans = 2.5556 2.1111 0.1111 A. Donev (Courant Institute) Lecture III 2/9/2011 31 / 34

Gauss elimination and LU factorization Cost estimates for GEM For forward or backward substitution, at step k there are (n k) multiplications and subtractions, plus a few divisions. The total over all n steps is n (n k) = k=1 n(n 1) 2 n2 2 subtractions and multiplications, giving a total of O(n 2 ) floating-point operations (FLOPs). The LU factorization itself costs a lot more, O(n 3 ), FLOPS 2n3 3, and the triangular solves are negligible for large systems. When many linear systems need to be solved with the same A the factorization can be reused. A. Donev (Courant Institute) Lecture III 2/9/2011 32 / 34

Matrix Rescaling Conclusions Pivoting is not always sufficient to ensure lack of roundoff problems. In particular, large variations among the entries in A should be avoided. This can usually be remedied by changing the physical units for x and b to be the natural units x 0 and b 0. Rescaling the unknowns and the equations is generally a good idea even if not necessary: x = D x x = Diag {x 0 } x and b = D b b = Diag {b 0 } b. Ax = AD x x = D b b ( D 1 b AD x) x = b The rescaled matrix à = D 1 b AD x should have a better conditioning. Also note that reordering the variables from most important to least important may also help. A. Donev (Courant Institute) Lecture III 2/9/2011 33 / 34

Conclusions Conclusions/Summary The conditioning of a linear system Ax = b is determined by the condition number κ(a) = A A 1 1 Gauss elimination can be used to solve general square linear systems and also produces a factorization A = LU. Partial pivoting is often necessary to ensure numerical stability during GEM and leads to PA = LU or A = LU. MATLAB has excellent linear solvers based on well-known public domain libraries like LAPACK. Use them! A. Donev (Courant Institute) Lecture III 2/9/2011 34 / 34