Scientific Computing

Similar documents
Numerical Linear Algebra

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

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

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

Numerical Linear Algebra

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

AMS526: Numerical Analysis I (Numerical Linear Algebra)

2.1 Gaussian Elimination

Scientific Computing: An Introductory Survey

Dense LU factorization and its error analysis

Direct Methods for Solving Linear Systems. Matrix Factorization

CME 302: NUMERICAL LINEAR ALGEBRA FALL 2005/06 LECTURE 6

Gaussian Elimination and Back Substitution

MATH 3511 Lecture 1. Solving Linear Systems 1

14.2 QR Factorization with Column Pivoting

Lecture 12 (Tue, Mar 5) Gaussian elimination and LU factorization (II)

Lecture Notes to Accompany. Scientific Computing An Introductory Survey. by Michael T. Heath. Chapter 2. Systems of Linear Equations

Solving linear systems (6 lectures)

Scientific Computing: Dense Linear Systems

Computational Methods. Systems of Linear Equations

Linear Algebraic Equations

Applied Mathematics 205. Unit II: Numerical Linear Algebra. Lecturer: Dr. David Knezevic

MODULE 7. where A is an m n real (or complex) matrix. 2) Let K(t, s) be a function of two variables which is continuous on the square [0, 1] [0, 1].

7. LU factorization. factor-solve method. LU factorization. solving Ax = b with A nonsingular. the inverse of a nonsingular matrix

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

Matrix decompositions

Linear Systems of n equations for n unknowns

LU Factorization. LU factorization is the most common way of solving linear systems! Ax = b LUx = b

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

Numerical Linear Algebra

1.Chapter Objectives

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

The Solution of Linear Systems AX = B

Ax = b. Systems of Linear Equations. Lecture Notes to Accompany. Given m n matrix A and m-vector b, find unknown n-vector x satisfying

Numerical Methods I: Numerical linear algebra

Lecture 2 Decompositions, perturbations

AMS 209, Fall 2015 Final Project Type A Numerical Linear Algebra: Gaussian Elimination with Pivoting for Solving Linear Systems

Solution of Linear Equations

Matrix decompositions

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

MTH 464: Computational Linear Algebra

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

Pivoting. Reading: GV96 Section 3.4, Stew98 Chapter 3: 1.3

Iterative solution methods

Review of matrices. Let m, n IN. A rectangle of numbers written like A =

5.1 Banded Storage. u = temperature. The five-point difference operator. uh (x, y + h) 2u h (x, y)+u h (x, y h) uh (x + h, y) 2u h (x, y)+u h (x h, y)

Numerical Linear Algebra

GAUSSIAN ELIMINATION AND LU DECOMPOSITION (SUPPLEMENT FOR MA511)

Linear Algebra. Solving Linear Systems. Copyright 2005, W.R. Winfrey

Process Model Formulation and Solution, 3E4

STAT 309: MATHEMATICAL COMPUTATIONS I FALL 2018 LECTURE 13

Review Questions REVIEW QUESTIONS 71

Introduction to Mathematical Programming

A Review of Matrix Analysis

Lecture Note 2: The Gaussian Elimination and LU Decomposition

Solving Linear Systems of Equations

Numerical Linear Algebra

Gaussian Elimination without/with Pivoting and Cholesky Decomposition

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 )

Today s class. Linear Algebraic Equations LU Decomposition. Numerical Methods, Fall 2011 Lecture 8. Prof. Jinbo Bi CSE, UConn

lecture 2 and 3: algorithms for linear algebra

CS412: Lecture #17. Mridul Aanjaneya. March 19, 2015

Scientific Computing with Case Studies SIAM Press, Lecture Notes for Unit VII Sparse Matrix

Matrix decompositions

Gaussian Elimination for Linear Systems

Lecture 9: Numerical Linear Algebra Primer (February 11st)

ACM106a - Homework 2 Solutions

Solving Dense Linear Systems I

AM205: Assignment 2. i=1

6 Linear Systems of Equations

Roundoff Analysis of Gaussian Elimination

This can be accomplished by left matrix multiplication as follows: I

Next topics: Solving systems of linear equations

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

Numerical Methods - Numerical Linear Algebra

. =. a i1 x 1 + a i2 x 2 + a in x n = b i. a 11 a 12 a 1n a 21 a 22 a 1n. i1 a i2 a in

Numerical Linear Algebra And Its Applications

Section 5.6. LU and LDU Factorizations

5 Solving Systems of Linear Equations

Numerical Linear Algebra Primer. Ryan Tibshirani Convex Optimization /36-725

Jim Lambers MAT 610 Summer Session Lecture 2 Notes

1.5 Gaussian Elimination With Partial Pivoting.

Chapter 2 - Linear Equations

Linear System of Equations

Fundamentals of Numerical Linear Algebra

9. Numerical linear algebra background

Introduction to PDEs and Numerical Methods Lecture 7. Solving linear systems

Linear Algebra Linear Algebra : Matrix decompositions Monday, February 11th Math 365 Week #4

lecture 3 and 4: algorithms for linear algebra

Name: INSERT YOUR NAME HERE. Due to dropbox by 6pm PDT, Wednesday, December 14, 2011

Solving Linear Systems of Equations

Scientific Computing: Solving Linear Systems

CHAPTER 6. Direct Methods for Solving Linear Systems

Direct solution methods for sparse matrices. p. 1/49

Engineering Computation

Numerical Analysis Fall. Gauss Elimination

Linear Algebra and Matrix Inversion

AMS526: Numerical Analysis I (Numerical Linear Algebra)

Practical Linear Algebra: A Geometry Toolbox

forms Christopher Engström November 14, 2014 MAA704: Matrix factorization and canonical forms Matrix properties Matrix factorization Canonical forms

Transcription:

Scientific Computing Direct solution methods Martin van Gijzen Delft University of Technology October 3, 2018 1

Program October 3 Matrix norms LU decomposition Basic algorithm Cost Stability Pivoting Pivoting Choleski decomposition Sparse matrices and reorderings 2

Matrix norms (1) The analysis of matrix algorithms frequently requires use of matrix norms. For example, the quality of a linear system solver may be poor if the matrix of coefficients is nearly singular. To quantify the notion of near-singularity we need a measure of distance on the space of matrices. Matrix norms provide that measure. 3

Matrix norms (2) A matrix norm on R m n is a function. : R m n R that satisfies the following properties: i) A 0 A R m n, and A = 0 A = 0, ii) A + B A + B A, B R m n, iii) αa = α A α R, x R m n. The most commonly used matrix norms are the p-norms induced by the vector p-norms. Ax p A p = sup x 0 x p = max x p=1 Ax p p 1. 4

Matrix norms (3) Below we list some properties of vector and matrix p-norms - AB p A p B p A R m n, B R n q m - A 1 = max a ij A R m n 1 j n i=1 - A = max n 1 i m j=1 a ij A R m n - A 2 is equal to the square root of the largest eigenvalue of A T A. - All norms are equivalent, meaning that there are m, M > 0 such that m A p A q M A p. 5

Matrix norms (4) Matrix norms that are not induced by a vector norm also exist. One of the best known is the Frobenius norm. The Frobenius norm of an m n matrix A is given by A F = m n a ij 2 i=1 i=1 This is equal to A F = T r(aa T ) In which T r(a) is the trace of A, which is the sum of the main diagonal elements. 6

Condition number (1) The condition number plays an important role in numerical linear algebra since it gives a measure of how perturbations in A and b affect the solution x. The condition number K p (A), for a nonsingular matrix A, is defined by K p (A) = A p A 1 p. A small condition number means that small perturbations in the matrix or right-hand side give small changes in the solution. A large condition number means that a small perturbation in the problem may give a large change in the solution. 7

Condition number (2) Suppose Ax = b, A R n n and A is nonsingular, 0 b R n, and A(x + x) = b + b, then x p x p K p (A) b p b p. 8

Condition number (2) Suppose Ax = b, A R n n and A is nonsingular, 0 b R n, and A(x + x) = b + b, then x p x p K p (A) b p b p. Proof: From the properties of the norms it follows that b p = Ax p A p x p, so 1 1 A p. x p b p We know that A x = b, so x = A 1 b. Furthermore x p = A 1 b p A 1 p b p. Combination of these inequalities proves the theorem. 8

Condition number (3) Suppose you want the solution x of Ax = b, A R n n nonsingular, 0 b R n You actually solve the perturbed system (A + A)(x + x) = b + b, A R n n, b R n with A p δ A p and b p δ b p. When has this system a (unique) solution? 9

Condition number (3) Suppose you want the solution x of Ax = b, A R n n nonsingular, 0 b R n You actually solve the perturbed system (A + A)(x + x) = b + b, A R n n, b R n with A p δ A p and b p δ b p. When has this system a (unique) solution? If K p (A)δ = r < 1 then A + A is nonsingular and Proof: Lecture notes, p.44. x p x p 2δ 1 r K p(a). 9

Gaussian elimination Consider the system 2 1 1 Ax = 4 1 0 2 2 1 x 1 x 2 x 3 = 1 2 7 Then we can reduce this system to upper triangular form (i) Subtract two times equation one from equation two (ii) Subtract -1 times equation one from equation three (iii) Subtract -3 times the second equation from the third 10

Gaussian elimination (2) The resulting equivalent system is 2 1 1 Ux = 0 1 2 0 0 4 x 1 x 2 x 3 = This system can be solved by back substitution. 1 4 4 If we have a different right-hand side, do we have to do the same operations? Or can we save what we did? 11

Gaussian elimination (3) The first reduction step was Subtract two times equation one from equation two. The so-called elementary matrix E 2,1 that performs this operations is E 2,1 = 1 0 0 2 1 0 0 0 1. Multiplying with this matrix yields 2 1 1 E 2,1 A = 0 1 2. 2 2 1 12

Gaussian elimination (4) The second reduction step Subtract -1 times equation one from equation three is equivalent with multiplying with the matrix 1 0 0 E 3,1 = 0 1 0 1 0 1 and Subtract -3 times the second equation from the third is equivalent with multiplying with the matrix 1 0 0 E 3,2 = 0 1 0 0 3 1 13

Gaussian elimination (4) The second reduction step Subtract -1 times equation one from equation three is equivalent with multiplying with the matrix 1 0 0 E 3,1 = 0 1 0 1 0 1 and Subtract -3 times the second equation from the third is equivalent with multiplying with the matrix 1 0 0 E 3,2 = 0 1 0 0 3 1 14

Gaussian elimination (5) Hence we can write E 3,2 E 3,1 E 2,1 A = U Notice that the matrix E 3,2 E 3,1 E 2,1 is a product of lower triangular matrices and therefore lower triangular. The above equation can also be written as A = E 1 2,1 E 1 3,1 E 1 3,2 U Since the inverse of a lower triangular matrix is lower triangular, the matrix E2,1 1 E 1 3,1 E 1 3,2 must be lower triangular: L = E 1 2,1 E 1 3,1 E 1 3,2 A = LU 15

Gaussian elimination (6) It is easy to check that 1 0 0 E2,1 1 = 2 1 0 E3,1 1 = 0 0 1 1 0 0 0 1 0 1 0 1 E 1 3,2 = 1 0 0 0 1 0 0 3 1 and that L = E 1 2,1 E 1 3,1 E 1 3,2 = 1 0 0 2 1 0 1 3 1 16

Gaussian elimination (7) Clearly L is lower triangular, with 1 s on the main diagonal. The special thing is that the entries below the diagonal are exactly the multipliers 2, -1, -3 used in the elimination steps. The example shows that an LU-decomposition can be made by Reducing A to upper triangular form by elementary row operations, this gives U, Storing all the multipliers in a lower triangular matrix L that has ones on the main diagonal. 17

Gaussian elimination algorithm Given A R n n the following algorithm computes the factorization A = LU. for k = 1,..., n 1 do for i = k + 1,..., n do η := a ik /a kk a ik = η for j = k + 1,..., n a ij := a ij η a kj end for end for end for The element a kk is called pivot 18

Some remarks (1) The algorithm overwrites the matrix A with the matrix U (upper triangular part) and the matrix L (strictly lower triangular part). The main diagonal of L is not stored. The value a kk is called the pivot. The numerical stability of the algorithm depends on the size of the pivots. If a pivot is zero the algorithm breaks down. If a pivot is close to zero large numerical errors may occur. The number of floating point operations to compute the LU-decomposition is 2n 3 /3. 19

Some remarks (2) A more symmetrical variant of the LU-decomposition is the LDU-decomposition. Here D is a diagonal that scales the main diagonal elements of U to one. A system of the form Ax = LUx = b can be solved by a forward substitution Ux = L 1 b, and a back substitution x = U 1 L 1 b. Once the LU-decomposition of A is known, a system with A can simply be solved by forward and back substitution with the LU factors. Both the back and forward substitution (algorithms given in the next two slides) require n 2 flops. 20

Forward substitution Given an n n nonsingular lower triangular matrix L and b R n, the following algorithm finds y R n such that Ly = b. Forward substitution algorithm for i = 1,..., n do y i := b i for j = 1,..., i 1 do y i := y i l ij y j end for y i := y i /l ii end for 21

Backward substitution Given an n n nonsingular upper triangular matrix U and y R n, the following algorithm finds x R n such that Ux = y. Back substitution algorithm for i = n,..., 1 do x i := y i for j = i + 1,..., n do x i := x i u ij x j end for x i := x i /u ii. end for 22

Round off errors, a bound We use the following conventions, if A and B are in R m n then B = A means b ij = a ij, i = 1,..., m, j = 1,..., n. B A means b ij a ij, i = 1,..., m, j = 1,..., n. Theorem Let ˆL and Û be the computed LU factors of the n n floating point matrix A. Suppose that ŷ is the computed solution of ˆLy = b and ˆx is the computed solution of Ûx = ŷ. Then (A + A)ˆx = b with A n(3 A + 5 ˆL Û )u + O(u2 ). Proof: see Golub and van Loan p.107. 23

Round off errors, discussion The term ˆL Û can be large if a small pivot is encountered during the elimination process. Small pivots do not necessarily indicate an ill-conditioned problem. Consider for example [ ] ɛ 1 A = 1 0 Gaussian elimination (without further precautions) can give arbitrarily poor results, even for well-conditioned problems. The method may be unstable, depending on the matrix. Assignment: Compute the LU factorisation of A and bound A. 24

Permutations The problem in the previous example can of course be solved by interchanging the rows (or columns). This is a row permutation. Suppose that the i-th column of the identity matrix I is denoted by e i. A row permuted version of A is given by P A, e T s 1. where P =. e T s n The matrix AP T is a column permuted version of A. Exchanging rows (and/or columns) for selecting large pivots is called pivoting. 25

Partial pivoting A simple strategy to avoid small pivots is partial pivoting: Determine the in absolute value largest element below the pivot, Interchange the corresponding row with the pivot row. Eliminate all nonzeros elements below the pivot. Remark: partial pivoting only works well if the elements of the matrix are scaled in some way. 26

Partial pivoting (2) Partial pivoting leads to the decomposition P A = LU. The permutation matrix P corresponds to all the row exchanges. Using partial pivoting we can show that no multiplier is greater than one in absolute value. 27

Symmetric positive definite systems In many applications the matrix A, used in the linear system Ax = b, is symmetric and positive definite. So matrix A satisfies the following rules: - A = A T, - x T Ax > 0, x R n, x 0. For this type of matrices, memory and CPU time can be saved. Since A is symmetric only the elements a ij, i = j,..., n ; j = 1,..., n should be stored in memory. Moreover, a cheap LU-like decomposition exists. 28

The Choleski decomposition Algorithm Given a symmetric positive definite A R n n, the following algorithm computes A = CC T, with C lower triangular. The entry a ij is overwritten by c ij (i j). for end k = 1, 2,..., n do a kk := (a kk k 1 a 2 kp )1/2 p=1 for i = k + 1,..., n do a ik := (a ik k 1 a ip a kp )/a kk end for for p=1 29

The Choleski decomposition (2) The Choleski decomposition has many favourable properties: The number of flops for the algorithm is n 3 /3; both memory and operations are half that of the LU decomposition for general matrices. The inequality c 2 ij i c 2 ip = a ii, p=1 shows that the elements in C are bounded: pivoting is not necessary. 30

Banded systems In many applications the matrix is banded. This is the case whenever the equations can be ordered so that each unknown x i appears in only a few equations in a neighborhood of the ith equation. The matrix A has upper bandwidth q where q 0 is the smallest number such that a ij = 0 whenever j > i + q and lower bandwidth p where p 0 is the smallest number such that a ij = 0 whenever i > j + p. Typical examples are obtained after finite element or finite difference discretizations. 31

Banded systems (2) Substantial reduction of work and memory can be realized for these systems, since L and U inherit the lower and upper bandwidth of A. This is easily checked by writing down some elimination steps for a banded system of equations. The LU decomposition can now be obtained using 2npq flops if n p and n q. However, the band structure is to a large extend destroyed if partial pivoting is applied. 32

General sparse systems (1) Large matrices with general sparsity patterns arise for example in unstructured finite element calculation. In order to limit the amount of fill in the matrix is usually reordered before it is decomposed. 33

Example: ocean circulation Numerical model: discretisation with FEM 34

Example: Nonzero pattern 4 0 x 10 0.5 1 1.5 2 2.5 3 3.5 4 0 0.5 1 1.5 2 2.5 nz = 294785 3 3.5 4 4 x 10 Scientific Computing October 3, 2018 35

General sparse systems (2) Solving a sparse system Ax = b with a direct method normally consists of three phases: An analysis phase: a symbolic decomposition is made during which a suitable ordering is determined. A decomposition phase: the permuted matrix is decomposed. A solution phase: the solutions for one or more right-hand sides are determined using back and forward substitution, and back permutation to the original ordering. 36

Ordering algorithms Quite sophisticated ordering algorithms exist to minimise the fill in. They are based on graph theory. Some general principles that are used are: Try to minimise the bandwidth in every elimination step. An example is the Reverse Cuthill-McKee algorithm. Select rows with the fewest nonzeros. An example is the minimum degree ordering. 37

Concluding remarks Direct solution methods are the preferred choice for dense systems. Also for sparse methods they are widely used, in particular for positive definite banded systems. A few of the state-of-the-art solvers are: MUMPS, Super-LU, Pardiso, UMFpack (matlab \) For very large sparse systems iterative methods are usually preferred. However, most of the time a combination of the two is used. Iterative methods can be used to improve the solution computed with the direct method, or an approximate factorisation is used to accelerate the convergence of an iterative method. These issues will be discussed in the next lessons. 38