Math 552 Scientific Computing II Spring SOLUTIONS: Homework Set 1

Similar documents
Math/Phys/Engr 428, Math 529/Phys 528 Numerical Methods - Summer Homework 3 Due: Tuesday, July 3, 2018

Gaussian Elimination and Back Substitution

Chapter 2. Solving Systems of Equations. 2.1 Gaussian elimination

MODEL ANSWERS TO THE THIRD HOMEWORK

MATH 3511 Lecture 1. Solving Linear Systems 1

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

Linear Systems of n equations for n unknowns

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

2.1 Gaussian Elimination

Matrix decompositions

1.5 Gaussian Elimination With Partial Pivoting.

Numerical Linear Algebra

The Solution of Linear Systems AX = B

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

Matrix decompositions

Linear Algebra and Matrix Inversion

Chapter 2. Solving Systems of Equations. 2.1 Gaussian elimination

Section 3.5 LU Decomposition (Factorization) Key terms. Matrix factorization Forward and back substitution LU-decomposition Storage economization

LU Factorization a 11 a 1 a 1n A = a 1 a a n (b) a n1 a n a nn L = l l 1 l ln1 ln 1 75 U = u 11 u 1 u 1n 0 u u n 0 u n...

POLI270 - Linear Algebra

Chapter 8 Gauss Elimination. Gab-Byung Chae

Numerical Analysis Fall. Gauss Elimination

MA2501 Numerical Methods Spring 2015

MATH 552 Spectral Methods Spring Homework Set 5 - SOLUTIONS

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

The following steps will help you to record your work and save and submit it successfully.

Numerical Linear Algebra

CHAPTER 6. Direct Methods for Solving Linear Systems

SOLVING LINEAR SYSTEMS

7.6 The Inverse of a Square Matrix

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

Solving Dense Linear Systems I

Hani Mehrpouyan, California State University, Bakersfield. Signals and Systems

Engineering Computation

Find the solution set of 2x 3y = 5. Answer: We solve for x = (5 + 3y)/2. Hence the solution space consists of all vectors of the form

Illustration of Gaussian elimination to find LU factorization. A = a 11 a 12 a 13 a 14 a 21 a 22 a 23 a 24 a 31 a 32 a 33 a 34 a 41 a 42 a 43 a 44

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

(Mathematical Operations with Arrays) Applied Linear Algebra in Geoscience Using MATLAB

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 )

Numerical Linear Algebra

Section Matrices and Systems of Linear Eqns.

Numerical Linear Algebra

Direct Methods for Solving Linear Systems. Matrix Factorization

Y = ax + b. Numerical Applications Least-squares. Start with Self-test 10-1/459. Linear equation. Error function: E = D 2 = (Y - (ax+b)) 2

7.5 Operations with Matrices. Copyright Cengage Learning. All rights reserved.

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

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].

BTCS Solution to the Heat Equation

Math Computation Test 1 September 26 th, 2016 Debate: Computation vs. Theory Whatever wins, it ll be Huuuge!

Chapter 7. Tridiagonal linear systems. Solving tridiagonal systems of equations. and subdiagonal. E.g. a 21 a 22 a A =

CSE 160 Lecture 13. Numerical Linear Algebra

Numerical Analysis FMN011

MATH2210 Notebook 2 Spring 2018

22A-2 SUMMER 2014 LECTURE 5

(Linear equations) Applied Linear Algebra in Geoscience Using MATLAB

Gaussian Elimination without/with Pivoting and Cholesky Decomposition

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

Lecture 12. Linear systems of equations II. a 13. a 12. a 14. a a 22. a 23. a 34 a 41. a 32. a 33. a 42. a 43. a 44)

Chapter 9: Gaussian Elimination

CS513, Spring 2007 Prof. Amos Ron Assignment #5 Solutions Prepared by Houssain Kettani. a mj i,j [2,n] a 11

MTH 464: Computational Linear Algebra

GAUSSIAN ELIMINATION AND LU DECOMPOSITION (SUPPLEMENT FOR MA511)

Solution of Linear Systems

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

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

AMS526: Numerical Analysis I (Numerical Linear Algebra)

Linear Algebraic Equations

MATH 2050 Assignment 8 Fall [10] 1. Find the determinant by reducing to triangular form for the following matrices.

Solving Linear Systems Using Gaussian Elimination. How can we solve

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

MAT 343 Laboratory 3 The LU factorization

Solving Ax = b w/ different b s: LU-Factorization

Applied Linear Algebra in Geoscience Using MATLAB

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

MATH 2030: MATRICES. Example 0.2. Q:Define A 1 =, A. 3 4 A: We wish to find c 1, c 2, and c 3 such that. c 1 + c c

Introduction to Mathematical Programming

MATRICES. a m,1 a m,n A =

Parallel Scientific Computing

y b where U. matrix inverse A 1 ( L. 1 U 1. L 1 U 13 U 23 U 33 U 13 2 U 12 1

Math 22AL Lab #4. 1 Objectives. 2 Header. 0.1 Notes

Math 60. Rumbos Spring Solutions to Assignment #17

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

Perform the same three operations as above on the values in the matrix, where some notation is given as a shorthand way to describe each operation:

Linear Algebra review Powers of a diagonalizable matrix Spectral decomposition

Lab 2 Worksheet. Problems. Problem 1: Geometry and Linear Equations

Scientific Computing: Dense Linear Systems

30.3. LU Decomposition. Introduction. Prerequisites. Learning Outcomes

9. Numerical linear algebra background

MA 138 Calculus 2 with Life Science Applications Matrices (Section 9.2)

Numerical Linear Algebra

MATH 612 Computational methods for equation solving and function minimization Week # 6

1 GSW Sets of Systems

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

Finite Math - J-term Section Systems of Linear Equations in Two Variables Example 1. Solve the system

Scientific Computing

Math 471 (Numerical methods) Chapter 3 (second half). System of equations

Linear Systems of Equations. ChEn 2450

Direct Solution of Linear Systems

Review Questions REVIEW QUESTIONS 71

EBG # 3 Using Gaussian Elimination (Echelon Form) Gaussian Elimination: 0s below the main diagonal

Transcription:

Math 552 Scientific Computing II Spring 21 SOLUTIONS: Homework Set 1 ( ) a b 1 Let A be the 2 2 matrix A = By hand, use Gaussian elimination with back c d substitution to obtain A 1 by solving the two systems Ax 1 = e 1 and Ax 2 = e 2, where e 1 and e 2 are the columns of the 2 2 identity matrix Note that you can perform both at the same time by considering the augmented system [A I Prove that A 1 exists if and only if det(a) ANS: Note that det(a) = ad bc and form the augmented matrix [ a b c d 1 Then the multiplier m 2,1 = c/a and perform the row operation m 2,1 R 1 + R 2 R 2 gives [ a b d bc/a c/a 1 First solving for x 1, back substituion gives (x 1 ) 2 = ( c/a)/(d bc/a) = c/(ad bc) Then (x 2 ) 1 = (1 b(x 1 ) 2 )/a = d/(ad bc) Solving for x 2 now, (x 2 ) 2 = 1/(d bc/a) = a/(ad bc) and (x 2 ) 1 = b(x 2 ) 2 /a = d/(ad bc) So we see that A 1 = 1 ad bc [ d b c a From this we see that A 1 exists if and only if ad bc But we are not done! Note in the row operation that a was in the denominator of the multiplier What if a =? Well, we would have to switch rows then, and in this case we must have that c since otherwise A would be singular So interchanging the rows gives [ c d 1 b SInce c, the matrix is nonsingular if and only if b, so we must have that cb, but ad = d = so this is equivalent to ad bc, and again we see that A 1 exists if and only if ad bc

2 We used a number of results concerning matrices in class in the discussion of LU decompositions These problems are inted as a verification of those results, at least in the case of a 3 3 matrix Let 1 E 1 = m 2,1, E 2 =, P 1 = m 3, 1 m 3,2 1 1 (a) Show that (b) Show that E 1 1 = E 1 1 E 1 2 = m 2,1 m 3, 1 m 2,1 m 3,1 m 3,2 1 (c) Show that P 1 1 =P 1 ANS: For (a) it is easily checked that E 1 E1 1 = I For (b), following the pattern in (a) to determine E2 1 we see that E1 1 E 1 2 = m 2,1 = m 2,1, m 3, m 3,2 1 m 3,1 m 3,2 1 and for (c) note that P1 2 = I (P 1A swaps rows 1 and 2 of A, so applying P 1 again just swaps them back!) thus P1 1 = P 1

3 Find the LU factorization of A by hand without partial pivoting and, showing all steps, use it to solve Ax = b 4 5 A = 1 4 1 4 1, b = 6 6 1 4 5 Check that your answer is correct difference here? Discuss Would the use of partial pivoting have made any ANS: With A (1) = A, m 2,1 = 1/4, so perfoming m 2,1 R 1 + R 2 R 2 and storing the multiplier gives 4 A (2) = 1/4 15/4 1 4 1 1 4 Next, m 3,2 = 1/(15/4) = 4/15, storing this and performing m 3,2 R 2 + R 3 R 3 gives 4 A (3) = 1/4 15/4 4/15 56/15 1 1 4 Finally, m 4,3 = 1/(56/15) = 15/56, storing this and performing m 4,3 R 3 + R 4 R 4 gives 4 A (4) = 1/4 15/4 4/15 56/15 1 15/56 29/56 Writing L and U explicitly gives L = 1/4 4/15 15/56 1 and U = 4 15/4 56/15 1 29/56 Nest, to solve Ax = LUx = b let z = Ux and first solve Lz = b by forward substitution: z 1 = b 1 = 5 z 2 = b 2 (1/4)z 1 = 6 5/4 = 19/4 z 3 = b 3 (4/15)z 2 = 6 19/15 = 71/15 z 3 = b 4 (15/56)z 3 = 5 71/56 = 29/56 And finally, we solve Ux = z by back substitution: (29/56)x 4 = z4 = 29/56 x 4 = 1 (56/15)x 3 = z 3 x 4 = 71/15 1 = 15/56 x 3 = 1 (15/4)x 2 = z 2 x 3 = 19/4 1 = 15/4 x 2 = 1 4x 1 = z 1 x 2 = 5 1 = 4 x 1 = 1 So x = [1 1 1 1 T is easily seen to be the solution of Ax = b since Ax is then just the row sums of A, which is b

What about partial pivoting? Notice that at each stage of the elimination the entry of maximum absolute value on or below the diagonal of the column being eliminated was already on the diagonal The matrix A is symmetric and positive definite, and we ll prove later in the course that this is always the case for such matrices Thus partial pivoting is not needed!

4 Write a MATLAB m-file (function) to find the LU decomposition of a given n n matrix A using partial pivoting The routine should return the updated matrix A and the pivot vector p Name the file mylum, the first few lines of which should be as follows: function [a,p=mylu(a) % [n n=size(a); p=(1:n) ; (your code here!) The code above sets n equal to the dimension of the matrix and initializes the pivot vector p Make sure to store the multipliers m ij in the proper matrix entries For more help on function m-files see pages 1 13 of the MATLAB primer available from the course webpage You should experiment with a few small matrices to make sure your code is correct As a test of your code, in MATLAB execute the statements (exactly as they appear) >>diary mylutxt >>format short e >>type mylum >>a=[2 2-3;3 1-2;6 8 1; >>[a,p=mylu(a) >>diary off Recall we discussed the use of the diary command in class last term If need be, check the online MATLAB help or the Mathworks webpage for help using diary to save your output Print and hand-in the text file mylutxt ANS: Here is the output in mylutxt: format short e type mylum function [a,p = mylu(a) [n n = size(a); p = (1:n) ; for k = 1:n-1 [val,ind = max(abs(a(p(k:n),k))); tind = p(k); p(k) = p(ind+k-1); p(ind+k-1) = tind; if (p(k) == ) disp( Matrix is singular! ); return; for i = (k+1):n m = a(p(i),k)/a(p(k),k); a(p(i),k) = m; % find pivot in p(k:n) % interchange rows via pivot % vector, making sure to % adjust for offset % check for pivot % row loop for elimination % set multiplier % store multiplier for L a(p(i),k+1:n) = a(p(i),k+1:n) % loop over columns k+1:n

-m*a(p(k),k+1:n); a=[2 2-3;3 1-2;6 8 1; [a,p=mylu(a) a = 33333e-1 22222e-1-27778e+ 5e-1-3e+ -25e+ 6e+ 8e+ 1e+ p = 3 2 1

5 Consider the problem Ax = f where A is an n n tridiagonal matrix, b 1 c a 2 b 2 c 2 A = a b c a n b n Note that the right-hand side of the system is denoted by the vector f here Write out pseudo-code to solve the system assuming that partial pivoting is not implemented What is the operation count for the forward elimination and the back substitution steps of Gaussian elimination in this case? Count add/sub and mult/div operations separately, but then give the overall order (big O) of the total operations needed ANS: I will include a MATLAB m-file in place of pseudo-code: function x = mytrige(a,b,c,f) n = length(b); x = zeros(n,1); for i = 1:n-1 m = a(i+1)/b(i); b(i+1) = b(i+1)-m*c(i); f(i+1) = f(i+1)-m*f(i); % determine system size % allocate x % forward eliminatiosweep GE % compute multiplier % b (but not c) is affected in row operation % row op applied to RHS x(n) = f(n)/b(n); % back substitution for i = n-1:-1:1 x(i) = (f(i)-c(i+1)*x(i+1))/b(i); So only a simple forward elimination is needed to zero the entires of a just below the diagonal, followed by a back substitution For the elimination, the loop is over i = 1 :, with 3 mults/divs and 2 adds/subs for each i Thus # mults/divs = 3 = 3n 3 and # adds/subs = 2 = 2n 2 Performing the back substitution, we start with 1 division, and now loop over i = n 1 : 1 : 1 performing 1 subtraction and 2 mults/divs Thus # mults/divs = 1 + 2 = 2n 1 and # adds/subs = Putting these together we have 1 = n 1 # mults/divs = 5n 4 and # adds/subs = 3n 3 Thus, the overall operation count is O(8n)