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

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

In this LAB you will explore the following topics using MATLAB. Investigate properties of the column space of a matrix.

MAT 343 Laboratory 3 The LU factorization

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

Section 5.6. LU and LDU Factorizations

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

MATH 3511 Lecture 1. Solving Linear Systems 1

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

0.1 Eigenvalues and Eigenvectors

Numerical Linear Algebra

Direct Methods for Solving Linear Systems. Matrix Factorization

MATLAB Project: LU Factorization

GAUSSIAN ELIMINATION AND LU DECOMPOSITION (SUPPLEMENT FOR MA511)

7.6 The Inverse of a Square Matrix

MATH2210 Notebook 2 Spring 2018

MAC Module 2 Systems of Linear Equations and Matrices II. Learning Objectives. Upon completing this module, you should be able to :

Linear Systems of n equations for n unknowns

22A-2 SUMMER 2014 LECTURE 5

MODEL ANSWERS TO THE THIRD HOMEWORK

Finite Mathematics Chapter 2. where a, b, c, d, h, and k are real numbers and neither a and b nor c and d are both zero.

18.06 Problem Set 2 Solution

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

Introduction to Matlab

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

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 )

Math 313 Chapter 1 Review

Chapter 1: Systems of linear equations and matrices. Section 1.1: Introduction to systems of linear equations

Review. Example 1. Elementary matrices in action: (a) a b c. d e f = g h i. d e f = a b c. a b c. (b) d e f. d e f.

CHAPTER 6. Direct Methods for Solving Linear Systems

MAC1105-College Algebra. Chapter 5-Systems of Equations & Matrices

Math 414 Lecture 1. Reading assignment: Text: Pages 1-29 and Scilab Users Guide: Sections 1-3.

Scientific Computing

MIDTERM 1 - SOLUTIONS

Matrix decompositions

Matrix decompositions

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

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

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

AMS526: Numerical Analysis I (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

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

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

Linear Equations and Matrix

Gaussian Elimination without/with Pivoting and Cholesky Decomposition

1.5 Gaussian Elimination With Partial Pivoting.

18.06 Problem Set 3 - Solutions Due Wednesday, 26 September 2007 at 4 pm in

4 Elementary matrices, continued

PowerPoints organized by Dr. Michael R. Gustafson II, Duke University

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

Chapter 1 Linear Equations. 1.1 Systems of Linear Equations

Example: 2x y + 3z = 1 5y 6z = 0 x + 4z = 7. Definition: Elementary Row Operations. Example: Type I swap rows 1 and 3

Chapter 2 Notes, Linear Algebra 5e Lay

Next topics: Solving systems of linear equations

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

9.1 - Systems of Linear Equations: Two Variables

Numerical Linear Algebra

The Solution of Linear Systems AX = B

Process Model Formulation and Solution, 3E4

Math 552 Scientific Computing II Spring SOLUTIONS: Homework Set 1

Introduction to Mathematical Programming

is a 3 4 matrix. It has 3 rows and 4 columns. The first row is the horizontal row [ ]

4 Elementary matrices, continued

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

Chapter 2: Matrices and Linear Systems

Matrices and Matrix Algebra.

2.1 Gaussian Elimination

Linear Algebra and Matrices

INVERSE OF A MATRIX [2.2]

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

Linear Algebra and Matrix Inversion

Chapter 2. Solving Systems of Equations. 2.1 Gaussian elimination

1 GSW Sets of Systems

Linear Algebra March 16, 2019

MAC Module 1 Systems of Linear Equations and Matrices I

THE NULLSPACE OF A: SOLVING AX = 0 3.2

Recall, we solved the system below in a previous section. Here, we learn another method. x + 4y = 14 5x + 3y = 2

Math 343 Midterm I Fall 2006 sections 002 and 003 Instructor: Scott Glasgow

Gaussian Elimination and Back Substitution

LINEAR SYSTEMS, MATRICES, AND VECTORS

Matrix Solutions to Linear Equations

Math 1314 Week #14 Notes

Extra Problems: Chapter 1

Chapter 4. Solving Systems of Equations. Chapter 4

MATLAB Project 2: MATH240, Spring 2013

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

STAT 309: MATHEMATICAL COMPUTATIONS I FALL 2018 LECTURE 13

MAC Learning Objectives. Learning Objectives (Cont.) Module 10 System of Equations and Inequalities II

Linear Algebra: Lecture notes from Kolman and Hill 9th edition.

Scientific Computing: Dense Linear Systems

Fundamentals of Engineering Analysis (650163)

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

Draft. Lecture 12 Gaussian Elimination and LU Factorization. MATH 562 Numerical Analysis II. Songting Luo

Linear Algebraic Equations

Cheat Sheet for MATH461

MODEL ANSWERS TO THE FIRST QUIZ. 1. (18pts) (i) Give the definition of a m n matrix. A m n matrix with entries in a field F is a function

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

Matrix Algebra. Matrix Algebra. Chapter 8 - S&B

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

Review Questions REVIEW QUESTIONS 71

Transcription:

MATH 22AL Lab # 4 1 Objectives In this LAB you will explore the following topics using MATLAB. Properties of invertible matrices. Inverse of a Matrix Explore LU Factorization 2 Recording and submitting your work The following steps will help you to record your work and save and submit it successfully. Open a terminal window. In Computer LAB (2118 MSB) click on terminal Icon at the bottom of the screen In Windows OS, Use Putty In MAC OS, Use terminal window of MAC. Start a MATLAB Session that is : Type textmatlab Press Enter Enter your information that is : Type diary LAB4.text Type % First Name: then enter your first name Type % Last Name: then enter your Last name Type % Date: then enter the date Type % Username: then enter your Username for 22AL account Do the LAB that is : Follow the instruction of the LAB. Type needed command in MATLAB. All commands must be typed in front of MATLAB Command >>.. Close MATLAB session Properly that is : When you are done or if you want to stop and continue later do the following: Type save Press Enter Type diary off Press Enter 1

Type exit Press Enter Edit Your Work before submitting it that is : Use pico or editor of your choice to clean up the file you want to submit: in command line of pine type pico LAB2.text Delete the error Properties of invertible matrices. Inverse of a Matrix Explore LU Factorization s or insert missed items. Save using ˆ o= control key then o Exit using ˆ x= control key then x Send your LAB that is : Type ssh point : Press enter Type submitm22al LAB2.text 2

MAT22AL 3 Inverse of A 3.1 Reading: SupposeA is a square matrix. The inverse is written A 1 and is defined to be a matrix when A is multiplied by A 1 the result is the identity matrix I. Note: The following facts about the inverse of a matrix are information from your 22A class. Section 2.5. Please review them before continuing the LAB Not all square matrices have inverses. A square matrix which has an inverse is called invertible or nonsingular A square matrix without an inverse is called non invertible or singular. The inverse exists if and only if elimination produces n pivots The matrix A cannot have two different inverses. If A is invertible, the one and only solution to Ax = 0 is x = A 1 x Suppose there is a nonzero vector x such that Ax = 0 then A cannot have an inverse. A 2 by 2 matrix is invertible if and only if ad bc is not zero A diagonal matrix has an inverse provided no diagonal entries are zero. If A and B are invertible then so is AB. The inverse of a product (AB) 1 = B 1 A 1 For square matrices, an inverse on one side is automatically an inverse on the other side. The right-inverse equals the left-inverse. BA = I and AC = I then B = C If A doesn t have n pivots, elimination will lead to a zero row. An invertible matrix A can t have a zero row! A triangular matrix is invertible if and only if no diagonal entries are zero. The Gauss-Jordan method solves AA 1 = I to find the n columns of A 1. 3

3.2 Working with MATLAB 3.2.1 Basic Properties of inverse type A= [ 1 2 3 ; 3 4 1; 9 4 2] To enter a 3 by 3 matrix. type AI = inv(a) to find the inverse of A type AII = inv(ai) Explain what is happening by typing % before your answer. type AR =rref(a) to see the Reduced Row Echelon Form of A. What type of the matrix you are getting? Is this true for all invertible matrices A? Explain by typing % before your answer. type B(:,1) = A(:,1) to define the first column of B as first column of A. type B(:,2) = A(:,2) to define the second column of B as second column of A. type B(:,3) = A(:,1) + A(:,2) to define the third column of B as the sum of the first two columns of A. type BR =rref(b) to see the Reduced Row Echelon Form of B. Do you see a row of zeros? type BI = inv(b) Does the inverse of B exist? Explain by typing % before your answer. 4

3.2.2 Inverse of Diagonal Matrices type C= [0 0 0 3; 0 0 2 0; 0 5 0 0 ; 4 0 0 0 ] type inv(c) To see the inverse of C. type format rat to see the numbers in fraction format. type inv(c) To see the inverse of C. type D = [ 0 0 3; 0 8 0; 5 0 0] type inv(d) to see inverse of D Without typing it in the MATLAB guess what the inverse of E= [ 0 0 1; 0 3 0; 7 0 0 ] should be? Explain by typing % before your answer. Enter your answer as EI= 3.2.3 Inverse of Block Matrices type J= E*EI If you did not get an Identity matrix, try it again, until you get it right. type F= [ 3 2 0 0 ; 4 3 0 0 ; 0 0 6 5 ; 0 0 7 6 ]. type FI= inv(f) to find inverse of F Any thing interesting? Explain by typing % before your answer. type F1I= inv( [3 2; 4 3 ]) type F1I= inv( [6 5; 7 6 ]) Explain the relation of the last two inverses with the inverse of matrix F, by typing % before your answer. 5

3.2.4 An Interesting Observation type type type type type E1 = 5*eye(4) - ones(4,4) E1I = inv(e1) to see the inverse of E1 E2 = 6*eye(5) - ones(5,5) E2I = inv(e2) to see the inverse of E1 E3 = 3*eye(2) - ones(2,2) Generalize your observation. Representing a n n identity matrix by I n and a n n matrix of ones by O n write an inverse for (n + 1)I n O n, it will be in the form of k(i n + O n ). Enter your response by typing % before your answer. Your answer has to be in the form of INV((n + 1)I n O n ) = k(i n + O n ). where the k is replaced by the value you choose. 6

4 Using Gauss- Jordan Elimination to calculate H 1 You may find inverse of a n n matrix H by forming a new matrix as K = [A I] then using rref(k), if H is invertible, H will transform to I and I will transform to H 1. 4.1 Calculating H 1 type H= [ 1 3 ; 2 7] type H1= [ H eye(2) ] to form [H I] type H2=rref(H1) To find Reduced Row Echelon Form of [H I] type HI= H2(:,[3 4]) to extract inverse of H type inv(h) To find the inverse of H using MATLAB command type L = [2 1 0; 1 2 1; 0 1 2] To enter 3 3 matrix L. type J = [1 3 5; 3 2 1; 0 1 2] To enter 3 3 matrix L. type LI1 = inv(l) to find inverse of L type LI2 = rref([l eye(3)]) to calculate inverse of L type LI3 = LI2(:, 4 : 6) to extract the inverse of L type JI1 = inv(j) to find inverse of J type JI2 = rref([j eye(3)]) to calculate inverse of J type JI3 = JI2(:, 4 : 6) to extract the inverse of J 4.2 Inverse of LJ type LJ = L J to find LJ type LJI = inv(l J) to calculate inverse of LJ type LJ2= inv(l) *inv(j) L 1 J 1 type LJ3= inv(j) *inv(l) J 1 L 1 7

4.2.1 True, False questions With these observation, determine which one of the following statements is true which one is false: For each statement enter your response after % as ( for example a.) is True ) or ( for example a.) is False ). a.) b.) c.) d.) If A and B are given invertible matrices, then (AB) 1 = (A) 1 (B) 1 For any given invertible matrices A and B we have (AB) 1 = (B) 1 (A) 1 For any given matrices A and B we have (AB) 1 = (B) 1 (A) 1 There is a group of matrices in which for any given invertible matrices A and B in that group, we have (AB) 1 = (A) 1 (B) 1. 8

5 LU Factorization 5.1 Reading Using Gaussian elimination we can express any square matrix as the product of a permutation of a lower triangular matrix and an upper triangular matrix. M = P LU. If A is invertible, Usually we choose the lower triangular matrix L with diagonal entries 1 and if we choose both L and U to have diagonal entries 1, then we need a diagonal matrix in the middle and decomposition becomes as M = P LDU, which is unique. One of the applications of LU decomposition or factorization is in solving a linear system AX = b. This can be seen as LUX = b. Assume UX = Y the linear system becomes as LY = b which can be solves easily for Y. Then the system UX = Y can be solved for X. You can read more on LU-Factorization in section 2.6 of your text book 5.2 Using MATLAB You can find LU factorization of a matrix in MATLAB using lu(a), the matrix L returned by MATLAB is a permutation of a lower triangular matrix. 5.2.1 Note [L,U] = lu(a) stores an upper triangular matrix in U and a potentially lower triangular matrix (i.e. a product of lower triangular and permutation matrices) in L, so that A = L*U. A can be rectangular. [L,U,P] = lu(a) returns unit lower triangular matrix L, upper triangular matrix U, and permutation matrix P so that P*A = L*U. 9

5.2.2 Examples type A= [ 8 2 9; 4 9 4; 6 7 9 ] To enter A. type [L U] = lu(a) To see LU factorization of A. type [L U P ] = lu(a) To see LU factorization of A with the permutation matrix P. Note that matrix P in this case will be an identity matrix. type A1= L*U To check your answer. type B= [ 6 7 9; 4 9 4; 8 2 9 ] To enter B. Note that first and third row of A are interchanged. type [L U P ] = lu(b) To see LU factorization of B with the permutation matrix P. type [L U ] = lu(b) To see LU factorization of B. Notice that L needs row exchange (permutation) to become a lower triangular matrix. type M= [2 1 0; 1 2 1; 0 1 2] To enter M. type [L U] = lu(m) To see LU factorization of M. type [L U P ] = lu(m) To see LU factorization of M with the permutation matrix. type N= L*U To check your answer. type O= [ 1 3 0; 3 11 4; 0 4 9] To enter O. type [L U P ] = lu(o) To see LU factorization of O with the permutation matrix. type [L U ] = lu(o) To see LU factorization of O to notice that L needs row exchange (permutation) to become a lower triangular matrix. 10

5.2.3 Solving AX=b Using LU factorization When we need to solve several equations with the same coefficient matrix A, ( as AX = b 1, AX = b 2, Ax = b 3 ), an efficient method for solving all of them is to find LU factorization of A, then use forward/back substitution to find X. Computational cost of this method is roughly 2 3 n3 operation (flop). We can also use LU factorization to find inverse of a nonsingular matrix A and use it to solve AX = b. Here is how: Assume A is a nonsingular matrix, and A = P LU. First find the inverse of A using LU factorization as A 1 = (P LU) 1 = U 1 L 1 P T. Then, X = A 1 b = U 1 L 1 P T b. Note that this method is not very efficient, its computational cost is 8 3 n3 operation (flop). 5.2.4 Examples type L= [ 1 0 0 ; 2 1 0 ; 3 4 1] To enter L. type U =[ 1 2 3 ; 0 4 5 ; 0 0 6] To enter U. type S = L*U to create S type b =[ 14 51 152] to enter b To solve SX = b use LU- Factorization. consider SX = LUX = b. Set Y = UX, so you have SX = LUX = L(UX) = L(Y ) = b. Solve LY = b first, this can be done by forward substitution. Do it by hand and check it with MATLAB. type Y = L\b To solve LY = b for Y. Now you have UX = Y which you can solve using backward substitution. Do it on paper then, check you answer using MATLAB type X = U\Y To solve UX = Y for X. This the end of the LAB 4, follow the directions to close your diary file save your variables, edit your work, then send it to the TA. 11