QUIZ: strings
Section 14.3 Matrices and Systems of Linear Eqns.
Remembering matrices from Ch.2
How to test if 2 matrices are equal Assume equal until proved wrong! else? myflag = logical(1)
How to test if 2 matrices are equal isequal(mata,matb)
What matrix is created here?
What matrix is created here?
Square Matrices
Diagonal of a matrix vs. diagonal matrix
QUIZ
QUIZ: Matrices Write a function that takes a matrix as argument and returns True if the matrix is upper triangular. (Use loops)
Upper and lower triangular
QUIZ: Matrices Write a function that takes a matrix as argument and returns True if the matrix is upper triangular. Vectorize, using triu() and/or tril()
QUIZ
Trace and eye
QUIZ
>> trace(eye(42)) ans =??? >> trace(fliplr(eye(42))) ans =??? >> trace(fliplr(eye(43))) ans =???
To do for next time: Read the notes and pp.473-9 of text Solve Practice 14.3 / p.478
Matrix multiplication Mnemonic: rows times columns Compatibility condition:.
Your turn!
Your turn! What is the output?
Your turn!
Triple for loop!
Extra-credit
eye(?) Identity
Identity eye(3) What if we did not know in advance the size of A?
Identity What is the output?
Identity
Inverse How do we calculate the inverse of a 2x2 matrix with pencil and paper?
Inverse To calculate the inverse of a 2x2 matrix with pencil and paper: The elements on the main diagonal switch places The elements on the antidiagonal change signs Divide by the determinant
QUIZ: Inverse Find the inverse of this matrix with pencil and paper, and check! M = M -1 = 10 2 11 2 To calculate the inverse of a 2x2 matrix with pencil and paper: The elements on the main diagonal switch places The elements on the antidiagonal change signs Divide by the determinant
Dot product See p.59
Cross product See p.59 Verify with pencil and paper!
System of linear equations: m eqns., n unknowns
QUIZ: Write this system in matrix form
QUIZ: Write this system in matrix form
Your turn!
Visualizing the solution
Numerical instability in a nutshell M = 1 1 1 1+ e Calculate the inverse of this matrix M -1 =
To do for next time: Read pp.478-84 Practice 14.4 / 484
QUIZ: Inverse M = 1 2 3 4 To calculate the inverse of a 2x2 matrix with pencil and paper: M -1 = The elements on the main diagonal switch places The elements on the antidiagonal change signs Divide by the determinant
QUIZ: Solving a linear system
Second problem with matrix inverses: complexity! 3x3 4x4 NxN O(N N!)
Calculate N N! for the following values of N: N = 1 N = 2 N = 3 N = 4 N = 5 O(N N!)
Conclusion The matrix inverse is (almost) never computed in real-life numerical applications!
Better idea: Elimination This is what we do with pencil and paper when we multiply an entire eqn. by a constant, and add or subtract one eqn. from another!
Better idea: Elimination Use the augmented matrix, since the free terms must change, too!
Augmenting in MATLAB Write a command to create the augmented matrix.
Augmenting in MATLAB A = Write a command to augment A with a 3-by-3 identity matrix (on the right).
Augmenting in MATLAB
Back to elimination How can we bring the augmented matrix to upper triangular form?
By performing Elementary Row Operations (EROS ) Multiply a row by a non-zero constant Add a row to another Switch two rows We ll use it later, when we learn about pivoting.
Elementary Row Operations
Your turn! Bring this system to upper triangular form using Gaussian elimination: First step: Write it in matrix form!
Your turn! Bring this system to upper triangular form using Gaussian elimination: Next steps: Perform EROs!
Source: http://en.wikipedia.org/wiki/gaussian_elimination
Extra-credit:
What to do once the matrix is in upper-triangular form? Back-substitution
QUIZ:
Your turn: Find the solution to the system using backsubstitution Source: http://en.wikipedia.org/wiki/gaussian_elimination
Extra-credit
Conclusion: Gauss method has complexity O(N 3 ) O(2N 3 /3), to be more precise
QUIZ Solve this system with pencil and paper: Using the inverse Using Gauss method
To do for next time: Read pp.484-8 Practice 14.5 / 486 Exercise 14.34 / 512 only Gaussian elimination
Gauss-Jordan method The elimination continues above he diagonal!
Your turn: Find the solution to the system using Gauss-Jordan method Source: http://en.wikipedia.org/wiki/gaussian_elimination
Gauss-Jordan method What is the Big-Oh complexity?
QUIZ Solve this system two ways using: Gaussian elimination + backsubstitution Gauss-Jordan method
Reduced row-echelon form (and method)
How to find the inverse of a matrix (if we have to)
QUIZ: Find the solution by calculating the inverse. Check.
How to find the inverse of a matrix (if we have to) What is the Big-Oh complexity? How does it compare to O(N N!)?
Homework for Ch.14 27 (use Gaussian elim. + backsub.) 30, 31, 32 35 (use Gauss-Jordan)