Linear Systems I (part 2)

Similar documents
Abstract: We describe the beautiful LU factorization of a square matrix (or how to write Gaussian elimination in terms of matrix multiplication).

Direct Methods for Solving Linear Systems. Matrix Factorization

7 Gaussian Elimination and LU Factorization

CS3220 Lecture Notes: QR factorization and orthogonal transformations

Solution of Linear Systems

Solving Systems of Linear Equations

SOLVING LINEAR SYSTEMS

MATRIX ALGEBRA AND SYSTEMS OF EQUATIONS

MATRIX ALGEBRA AND SYSTEMS OF EQUATIONS. + + x 2. x n. a 11 a 12 a 1n b 1 a 21 a 22 a 2n b 2 a 31 a 32 a 3n b 3. a m1 a m2 a mn b m

6. Cholesky factorization

Solving Linear Systems, Continued and The Inverse of a Matrix

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

MATH10212 Linear Algebra. Systems of Linear Equations. Definition. An n-dimensional vector is a row or a column of n numbers (or letters): a 1.

a 11 x 1 + a 12 x a 1n x n = b 1 a 21 x 1 + a 22 x a 2n x n = b 2.

Elementary Matrices and The LU Factorization

Systems of Linear Equations

Solving Systems of Linear Equations

Linear Equations ! $ & " % & " 11,750 12,750 13,750% MATHEMATICS LEARNING SERVICE Centre for Learning and Professional Development

1.2 Solving a System of Linear Equations

Chapter 19. General Matrices. An n m matrix is an array. a 11 a 12 a 1m a 21 a 22 a 2m A = a n1 a n2 a nm. The matrix A has n row vectors

1 Solving LPs: The Simplex Algorithm of George Dantzig

2x + y = 3. Since the second equation is precisely the same as the first equation, it is enough to find x and y satisfying the system

Systems of Linear Equations

Solving Linear Systems of Equations. Gerald Recktenwald Portland State University Mechanical Engineering Department

1 Determinants and the Solvability of Linear Systems

LINEAR ALGEBRA. September 23, 2010

Linear Algebra Notes for Marsden and Tromba Vector Calculus

Matrices 2. Solving Square Systems of Linear Equations; Inverse Matrices

1 Review of Least Squares Solutions to Overdetermined Systems

Lecture 3: Finding integer solutions to systems of linear equations

Data Mining: Algorithms and Applications Matrix Math Review

Factorization Theorems

SYSTEMS OF EQUATIONS AND MATRICES WITH THE TI-89. by Joseph Collison

1 VECTOR SPACES AND SUBSPACES

Linear Algebra Notes

Operation Count; Numerical Linear Algebra

by the matrix A results in a vector which is a reflection of the given

The Point-Slope Form

Solution to Homework 2

Using row reduction to calculate the inverse and the determinant of a square matrix

Orthogonal Projections

Similar matrices and Jordan form

Question 2: How do you solve a matrix equation using the matrix inverse?

General Framework for an Iterative Solution of Ax b. Jacobi s Method

Eigenvalues and Eigenvectors

University of Lille I PC first year list of exercises n 7. Review

MAT188H1S Lec0101 Burbulla

Notes on Determinant

10.2 ITERATIVE METHODS FOR SOLVING LINEAR SYSTEMS. The Jacobi Method

Linear Programming Problems

u = [ 2 4 5] has one row with three components (a 3 v = [2 4 5] has three rows separated by semicolons (a 3 w = 2:5 generates the row vector w = [ 2 3

8 Square matrices continued: Determinants

December 4, 2013 MATH 171 BASIC LINEAR ALGEBRA B. KITCHENS

Section 5.3. Section 5.3. u m ] l jj. = l jj u j + + l mj u m. v j = [ u 1 u j. l mj

DERIVATIVES AS MATRICES; CHAIN RULE

Math 215 HW #6 Solutions

Lecture 1: Systems of Linear Equations

Recall that two vectors in are perpendicular or orthogonal provided that their dot

Syntax Description Remarks and examples Also see

Introduction to Matrix Algebra

Solving simultaneous equations using the inverse matrix

Vector Notation: AB represents the vector from point A to point B on a graph. The vector can be computed by B A.

Lecture notes on linear algebra

Solving Systems of Linear Equations Using Matrices

5.5. Solving linear systems by the elimination method

[1] Diagonal factorization

Similarity and Diagonalization. Similar Matrices

Vector and Matrix Norms

Lecture 2 Linear functions and examples

MATH2210 Notebook 1 Fall Semester 2016/ MATH2210 Notebook Solving Systems of Linear Equations... 3

x = + x 2 + x

A =

MAT 200, Midterm Exam Solution. a. (5 points) Compute the determinant of the matrix A =

Row Echelon Form and Reduced Row Echelon Form

Lecture Notes 2: Matrices as Systems of Linear Equations

Au = = = 3u. Aw = = = 2w. so the action of A on u and w is very easy to picture: it simply amounts to a stretching by 3 and 2, respectively.

The Determinant: a Means to Calculate Volume

1 Introduction to Matrices

3.1. Solving linear equations. Introduction. Prerequisites. Learning Outcomes. Learning Style

8.2. Solution by Inverse Matrix Method. Introduction. Prerequisites. Learning Outcomes

160 CHAPTER 4. VECTOR SPACES

Here are some examples of combining elements and the operations used:

II. Linear Systems of Equations

Linearly Independent Sets and Linearly Dependent Sets

Matrix algebra for beginners, Part I matrices, determinants, inverses

Solutions to Math 51 First Exam January 29, 2015

Vector Math Computer Graphics Scott D. Anderson

9.4. The Scalar Product. Introduction. Prerequisites. Learning Style. Learning Outcomes

Elasticity Theory Basics

1.5 SOLUTION SETS OF LINEAR SYSTEMS

Reduced echelon form: Add the following conditions to conditions 1, 2, and 3 above:

Linear Algebra Review. Vectors

Geometric Transformations

TWO-DIMENSIONAL TRANSFORMATION

Introduction to Matrices

18.06 Problem Set 4 Solution Due Wednesday, 11 March 2009 at 4 pm in Total: 175 points.

MATH APPLIED MATRIX THEORY

Chapter 12 Modal Decomposition of State-Space Models 12.1 Introduction The solutions obtained in previous chapters, whether in time domain or transfor

8. Linear least-squares

6. Vectors Scott Surgent (surgent@asu.edu)

Transcription:

Linear Systems I (part 2) Steve Marschner Cornell CS 322 Cornell CS 322 Linear Systems I (part 2) 1

Outline Gauss-Jordan Elimination The LU Factorization Summary Cornell CS 322 Linear Systems I (part 2) 2

Solving linear systems We all know how to approach these systems by hand, taking advantage of certain transformations we can apply without changing the answer: Multiply both sides of an equation by a number Add or subtract two equations In a system expressed as a matrix, these operations correspond to scaling and combining rows of the matrix (as long as we do the same thing to the RHS). Cornell CS 322 Linear Systems I (part 2) 3

Gauss-Jordan elimination A procedure you may have learned for systematically eliminating variables from a linear system. Subtract rst equation from all others, scaled appropriately to cancel the rst variable. Subtract second equation from all others, again scaled appropriately does not disturb the canceled rst variable Continue with all other rows Answer can be read directly from reduced equations Example from Moler p. 54. Cornell CS 322 Linear Systems I (part 2) 4

Gauss-Jordan example Cornell CS 322 Linear Systems I (part 2) 5

Gauss-Jordan example Cornell CS 322 Linear Systems I (part 2) 5

Gauss-Jordan example Cornell CS 322 Linear Systems I (part 2) 5

Gauss-Jordan example Cornell CS 322 Linear Systems I (part 2) 5

Gauss-Jordan in matrix operations In matrix terms, why are these scaling and combination operations allowed? Ax = b Ax b = 0 Then for any reasonable matrix M: M(Ax b) = 0 holds if and only if Mx b = 0. So the system with MA and Mb is equivalent to the system with A and b. What is M for a Gauss-Jordan step? Cornell CS 322 Linear Systems I (part 2) 6

Row operations as matrix multiplication For the rst step of a 3 3 system: 1 a 11 a 21 11 1 a 31 a 11 1 a 11 a 12 a 13 1 a + 12 a + 13 a 21 a 22 a 23 = a 31 a 32 a 33 a + 22 a + 23 a + 32 a + 33 The row operations amount to multiplying by a specially designed matrix to zero out A(2 : 3, 1). Cornell CS 322 Linear Systems I (part 2) 7

Row operations as matrix multiplication The general case for step j in an n n system: 1 a 1j /a jj.... M j = 1/a jj.... a nj /a jj 1 In Matlab we could write (though we wouldn't form M j in practice): M = eye(n); M(:,j) = -A(:,j)/A(j,j); M(j,j) = 1/A(j,j); Cornell CS 322 Linear Systems I (part 2) 8

Gauss-Jordan in matrix terms Applying the row operations to the matrix and RHS amounts to hitting a wide matrix containing A and b with a sequence of matrices on the left: [ M n M 2 M 1 A ] [ b = I ] x M [ A b ] = [ I x ] (Recall that multiplying by a matrix on the left transforms the columns, independently.) The sequence of M j s (row operations) reduces A to I and b to x. Cornell CS 322 Linear Systems I (part 2) 9

Gauss-Jordan in matrix terms So this product matrix M is something that when multiplied by A gives the identity. There's a name for that! M = M n M 2 M 1 = A 1 The product of all the Gauss-Jordan matrices is the inverse of A. This is another way to see why Mb = x. In an implementation we wouldn't really form the M j s and multiply them. Instead start with I and apply the same row operations we apply to A. Y 0 = I ; Y k = M k Y k 1 Y n = M Cornell CS 322 Linear Systems I (part 2) 10

Multiple right-hand sides There might be more than one set of RHS values that are of interest. Geometry example: nd domain points that map to a bunch of range points Circuit example: solve same circuit with different source voltages Radiosity example: solve energy balance with different emissions Each of these examples requires solving many systems with the same matrix; e.g. nd x 1, x 2 such that Ax 1 = b 1 and Ax 2 = b 2 Cornell CS 322 Linear Systems I (part 2) 11

Multiple right-hand sides It's easy to package a multi-rhs system as a matrix equation, using the interpretation of matrix multiplication as transforming the columns of the right-hand matrix: A [ x 1 x 2 ] = [ b1 b 2 ] AX = B This kind of system is not any harder to solve than Ax = b; we just use the same method but apply the operations to all the columns of B at once. Sometimes a system that you form from matrices that you are not thinking of as a stack of columns surprises you by turning out to be a multi-rhs system. Cornell CS 322 Linear Systems I (part 2) 12

Pivoting in Gauss-Jordan In our G-J example, the second pivot was 0.1. This led to a large multiplier (70 and 25) and big numbers in the intermediate results where there were only small numbers in the problem and in the solution. Worse, we computed the RHS of row 2 as 6.1 6.0. If the pivot was 10 6 this would result in complete loss of accuracy in single precision. It wasn't obvious from the initial problem that this was coming! Cornell CS 322 Linear Systems I (part 2) 13

Pivoting in Gauss-Jordan An extreme example [ ] [ ] 0 1 x1 = 1 0 x 2 [ ] 2 3 Obviously x 1 = 3 and x 2 = 2, but our G-J algorithm will not gure this out. Cornell CS 322 Linear Systems I (part 2) 14

Pivoting in Gauss-Jordan Geometric intuition: G-J is adding a multiple of row i to the other rows to get them into the plane perpendicular to the i th coordinate axis. r 1 r 1 r 2 r 1 r 2 r 2 Cornell CS 322 Linear Systems I (part 2) 15

Pivoting in Gauss-Jordan Geometric intuition: G-J is shearing perpendicular to dimension i to get the i th column onto the i th coordinate axis. (That is, it projects each column in turn onto an axis.) c 2 c 2 c 2? c 1 c 1 c 1 Cornell CS 322 Linear Systems I (part 2) 16

Pivoting in Gauss-Jordan So the pivot problem is just a bad choice of arbitrary axis onto which to project. The solution is simply to process the axes in a different order. To keep the bookkeeping simple we do this by reordering the rows and then processing them in order. Cornell CS 322 Linear Systems I (part 2) 17

Pivoting in Gauss-Jordan Can express this in matrices using a permutation matrix, which is a matrix with a single 1 in each row and column. Note that we don't physically move the rows of A around in memory; we just keep track of P so that we know where to nd them. Cornell CS 322 Linear Systems I (part 2) 18

Computational complexity of G-J Cornell CS 322 Linear Systems I (part 2) 19

Gaussian elimination We can do better than G-J on two fronts: Overall operation count G-J can't handle new RHS vectors that come along after the fact, unless you compte the inverse. Can x both problems by only doing part of the work! Cornell CS 322 Linear Systems I (part 2) 20

Gaussian elimination No need to reduce A all the way down to the identityonly to an easy matrix to solve. E.g. the version we used for the by-hand examples, without dividing through to make the diagonal entries equal to 1, does this: where D is diagonal. MA = D Cornell CS 322 Linear Systems I (part 2) 21

Gaussian elimination Further laziness leads to only operating on rows below the row we're working on: This is an upper triangular matrixthat is, it has zeros below the diagonal (a ij = 0 for i > j). Cornell CS 322 Linear Systems I (part 2) 22

Gaussian elimination The reduced system can be solved easily: From these equations we can compute the values of the unknowns, starting from x 3. Once we have x 3 we substitute into the second equation to get x 2, and so forth. This is known as back substitution. Cornell CS 322 Linear Systems I (part 2) 23

The LU factorization This approach can be expressed as a series of Gauss transformations (slightly different from the ones used in G-J because they have zeros above the diagonal): or M n 1 M 2 M 1 A = U MA = U A = M 1 1 M 1 2 M 1 n 1 U A = LU Multiplying together the inverse Ms in this order serves simply to lay out the multipliers in L, below the diagonal. Try it! Cornell CS 322 Linear Systems I (part 2) 24

Gaussian elimination If we keep the multipliers around in this way, Gaussian elimination becomes the LU factorization A = LU One way to think of this is that the matrix U is a reduced form of A, ant L contains the instructions for how to reconstitute A from U. An advantage over Gauss-Jordan is that we factor A with no RHS in sight. Then, to solve LUx = b: solve Ly = b solve Ux = y. (another way to say this is we compute U 1 (L 1 b)). Cornell CS 322 Linear Systems I (part 2) 25

The LU factorization Cornell CS 322 Linear Systems I (part 2) 26

The LU factorization Cornell CS 322 Linear Systems I (part 2) 27

Linear systems in Matlab Solving a linear system in Matlab is simple: to solve Ax = b, write x = A \ b The idea behind this name for the operator is: ax = b = x = b/a except that for a matrix A you have to keep track of whether it is on the left or the right. Since A is on the left, we use the backslash to remind us that A is on the left and in the denominator. Note that there is also a corresponding forward slash operator that solves systems with A on the right (basically it solves a system with A T ). Cornell CS 322 Linear Systems I (part 2) 28

Summary Gauss-Jordan is a method for directly solving systems Process the RHS with the matrix Can compute the inverse as a side effect LU factorization is both faster and more exible Process matrix rst, then RHSs as they come along Based on a factorization into two triangular matrices Both require pivoting for stability LU is a good default for general system solving Cornell CS 322 Linear Systems I (part 2) 29