Numerical Methods Lecture 2 Simultaneous Equations

Similar documents
Numerical Methods Lecture 2 Simultaneous Equations

Basic Linear Algebra in MATLAB

Chapter 2 Notes, Linear Algebra 5e Lay

Getting Started with Communications Engineering. Rows first, columns second. Remember that. R then C. 1

Solving Systems of Linear Equations

Matrices and systems of linear equations

Section Matrices and Systems of Linear Eqns.

A Review of Matrix Analysis

Definition of Equality of Matrices. Example 1: Equality of Matrices. Consider the four matrices

22A-2 SUMMER 2014 LECTURE 5

Chapter 1 Linear Equations. 1.1 Systems of Linear Equations

Matrix notation. A nm : n m : size of the matrix. m : no of columns, n: no of rows. Row matrix n=1 [b 1, b 2, b 3,. b m ] Column matrix m=1

Topic 15 Notes Jeremy Orloff

CSE 160 Lecture 13. Numerical Linear Algebra

GAUSSIAN ELIMINATION AND LU DECOMPOSITION (SUPPLEMENT FOR MA511)

Lecture 9: Elementary Matrices

POLI270 - Linear Algebra

Elementary Linear Algebra

MTH5112 Linear Algebra I MTH5212 Applied Linear Algebra (2017/2018)

LECTURES 14/15: LINEAR INDEPENDENCE AND BASES

Matrices, Row Reduction of Matrices

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

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

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

2 Systems of Linear Equations

7.2 Linear equation systems. 7.3 Linear least square fit

Linear Algebra. Chapter Linear Equations

Basic Concepts in Linear Algebra

Linear Algebra March 16, 2019

Chapter 4. Solving Systems of Equations. Chapter 4

Review of Basic Concepts in Linear Algebra

1 Matrices and Systems of Linear Equations. a 1n a 2n

Introduction to Systems of Equations

Linear Algebra for Beginners Open Doors to Great Careers. Richard Han

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

1300 Linear Algebra and Vector Geometry

1 GSW Gaussian Elimination

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

1111: Linear Algebra I

1111: Linear Algebra I

18.06 Problem Set 3 Due Wednesday, 27 February 2008 at 4 pm in

6: Introduction to Elimination. Lecture

Final Review Sheet. B = (1, 1 + 3x, 1 + x 2 ) then 2 + 3x + 6x 2

Matrices. Chapter Definitions and Notations

[Disclaimer: This is not a complete list of everything you need to know, just some of the topics that gave people difficulty.]

Exercise Sketch these lines and find their intersection.

BASIC NOTIONS. x + y = 1 3, 3x 5y + z = A + 3B,C + 2D, DC are not defined. A + C =

Review for Exam Find all a for which the following linear system has no solutions, one solution, and infinitely many solutions.

MAC Module 1 Systems of Linear Equations and Matrices I

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

Linear Algebra, Summer 2011, pt. 2

Handout 1 EXAMPLES OF SOLVING SYSTEMS OF LINEAR EQUATIONS

Designing Information Devices and Systems I Fall 2018 Lecture Notes Note Introduction to Linear Algebra the EECS Way

Linear Algebra. The analysis of many models in the social sciences reduces to the study of systems of equations.

TOPIC 2 Computer application for manipulating matrix using MATLAB

Lecture 2 Systems of Linear Equations and Matrices, Continued

Numerical Linear Algebra

Linear Algebra II. 2 Matrices. Notes 2 21st October Matrix algebra

CS 246 Review of Linear Algebra 01/17/19

The matrix will only be consistent if the last entry of row three is 0, meaning 2b 3 + b 2 b 1 = 0.

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

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

Chapter. Algebra techniques. Syllabus Content A Basic Mathematics 10% Basic algebraic techniques and the solution of equations.

Next topics: Solving systems of linear equations

Chapter 2. Solving Systems of Equations. 2.1 Gaussian elimination

LECTURES 4/5: SYSTEMS OF LINEAR EQUATIONS

Vector Spaces. 9.1 Opening Remarks. Week Solvable or not solvable, that s the question. View at edx. Consider the picture

Linear Equations and Matrix

Matrices MA1S1. Tristan McLoughlin. November 9, Anton & Rorres: Ch

SOLVING LINEAR SYSTEMS

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

Introduction to Matrices

CHAPTER 8: Matrices and Determinants

L1-5. Reducing Rows 11 Aug 2014

Numerical Linear Algebra

Linear Algebra (part 1) : Matrices and Systems of Linear Equations (by Evan Dummit, 2016, v. 2.02)

Math 1314 Week #14 Notes

Differential Equations

Matrix & Linear Algebra

MATH 320, WEEK 7: Matrices, Matrix Operations

A primer on matrices

PH1105 Lecture Notes on Linear Algebra.

Topic 14 Notes Jeremy Orloff

Gaussian Elimination and Back Substitution

Row Reduced Echelon Form

Linear Algebra. Matrices Operations. Consider, for example, a system of equations such as x + 2y z + 4w = 0, 3x 4y + 2z 6w = 0, x 3y 2z + w = 0.

Designing Information Devices and Systems I Spring 2018 Lecture Notes Note Introduction to Linear Algebra the EECS Way

Chapter 7. Linear Algebra: Matrices, Vectors,

The Gauss-Jordan Elimination Algorithm

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

3 Fields, Elementary Matrices and Calculating Inverses

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

Chapter 1. Linear Equations

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:

Math 123, Week 2: Matrix Operations, Inverses

Systems of equation and matrices

Solving Systems of Linear Equations Using Matrices

Elementary maths for GMT

Topics. Vectors (column matrices): Vector addition and scalar multiplication The matrix of a linear function y Ax The elements of a matrix A : A ij

Lecture 3: Matrix and Matrix Operations

Transcription:

CGN 42 - Computer Methods Numerical Methods Lecture 2 Simultaneous Equations Topics: matrix operations solving systems of equations Matrix operations: Adding / subtracting Transpose Multiplication Adding matrices Add the elements of A to those in B for i : number of rows in A and B for j number of columns in A and B C(i,j) A(i,j) + B(i,j) end end OR C A + B; %higher level command Rule: Transpose A, B, and C must all have the same dimensions C 5 + 2 4 6 7 79 82 5 9 2 swap rows and columns of any matrix. No dimension restrictions -D A 529, A T 5 2 x > x 9 2-D B 8. 4.5 7.6, B T 8..2 4.5. 2x > x2.2..9 7.6.9 In general Bij (, ) B T ( j, i) Numerical Methods Lecture 2 Simultaneous Equations page 7 of 85

CGN 42 - Computer Methods In MATLAB, The transpose is indicated by a single quote after the array >> B [5 6 2; 9 8 4 7]; >> B B 562 9847 >> B ans 59 8 64 27 Multiplication matrix multiplication C A x B is the result of dot products of rows in matrix A with columns of matrix B Step : Dot Product (a -row matrix times a -column matrix) The Dot product is the scalar result of multiplying one row by one column 6 25 * 8 2*6 + 5*8 + *7 7 x x 7 x Rule: ) # of elements in the row and column must be the same 2) must be a row times a column, not a column times a row Step 2: general matrix multiplication is taking a series of dot products each row in pre-matrix by each column in post-matrix 5 6 42* 8 2 *5+4*8+2* +6*4*2+2* 57 76 97 9*5+*8+7* 9*6+*2+7* 9 67 2x x2 2x2 In general nca and nrb C ik, A i, j * B jk, j loop over all j for each i and k (i is length nra, k is ncb) C(i,k) is the result of the dot product of row i in A with column k in B Numerical Methods Lecture 2 Simultaneous Equations page 74 of 85

CGN 42 - Computer Methods Matrix Multiplication Rules: ) The # of columns in the pre-matrix must equal # of rows in post-matrix inner matrix dimensions must agree 2) The result of the multiplication will have the outer dimensions # rows in pre-matrix by # columns in post-matrix For this example, apply rules >> C A * B A is nra x nca B is nrb x ncb Rule says: nca nrb or else we can t multiply (can t take dot products with different number of terms in row and column) Rule 2 says: C will be nra x ncb result C has outer dimensions nra x nca * nrb x ncb inner dimensions must agree How to perform matrix multiplication in MATLAB??? Easy >> A [4 5; 2 ]; >> B [9 ; 6 2]; >> C A*B if inner matrix dimensions don t match, you ll get an error example >> x [2 4 9 5 2]; >> y x^2 same as >> y x*x??? Error using > ^ Matrix must be square. can t take a dot product of two row vectors, since ncx not nrx rules of matrix multiplication violated in this case Numerical Methods Lecture 2 Simultaneous Equations page 75 of 85

CGN 42 - Computer Methods Practice matrix operations on the following examples. List the size of the resulting matrix first. then perform the operations by hands. Use MATLAB to confirm each of your answers. 925 * 2 8 97 6 7 2 4 6 82 4 2 * 87 96 4 9 7 * 28 49 864 * 9 47 498 T * 27 47 5 T + * 27 89 6 5 Numerical Methods Lecture 2 Simultaneous Equations page 76 of 85

CGN 42 - Computer Methods Solving simultaneous linear equations Now we ll use matrices to represent sets of algebraic equations. The solution to these sets of equations can be solved using matrix methods. The simultaneous solution of multiple equations finds its way in to many common engineering problems. In fact, modern structural engineering analysis techniques are ALL ABOUT solving systems of equations simultaneously. You ll see the following material in CES 44 (structures II) for sure. Matrices - an organized way of presenting a set of coupled equations. We seek a single unique solution that satisfies all the equations at the same time. Consider the three coupled linear equations below: + 5 + 2X 8 2 + X 2 X Coupled because each equation has one or more terms in common with the others,,, X, so that a change in one of these variables will affect more than one equation. Linear because each equation contains only first order terms of,, X. There are no terms like, or, or log( X ), or ( ), etc. 2 Using the rules of matrix multiplication, we can represent the above equations in matrix form: 5 2 2 2 X 8 coefficient matrix A unknowns vector X solution vector B Try multiplying the matrices A and X together, make sure you get the original equations above. There are several ways to solve for unknown vector X. Each method involves some manipulations to the coefficient matrix using algebraic rules, creating a new and equivalent problem in a more easily solvable form. These manipulations involve the addition of multiples of one row to another. Adding one row to another results in an equivalent equation, since both sides are equal. For example, starting with the two equations: + 5 their addition gives: 2 5 () (2) Numerical Methods Lecture 2 Simultaneous Equations page 77 of 85

CGN 42 - Computer Methods + 2 8 () This addition does not add any new information, but it does present a new form of the old information. If we plot these equations, the solution is the place where they intersect. That is, we are seeking the one pair of X and X2 values which lines along both or the original lines (eq, eq2). For only two equations and two unknowns, finding the solution is trivial substitution. However, many problems require the solution of many equations and as many unknowns. If we had 5 equations and 5 unknowns, things get more difficult to handle with just substitusion. We ll now look at several ways to systematically solve a set of simultaneous equations of any size. First we put the equations in matrix form, then manipulate the matrix to get a solution. Gaussian Elimination (method #): Consider the three coupled linear equations given earlier. The original form looks like this: 5 2 2 2 But what if we could recast the same problem to look like this? X 8. (4) 5 2 2 X 8 4 (5) This makes life easier, since there is less coupling between equations. In fact, X can be solved immediately using the bottom equation > + 2X 4 to give X 2. Now the result can be used to write the middle equation as ----- X to get > 2 -----2 ( ) X 2. Finally, the known values, are used to solve for in the first equation to get >. This easy solution process is called back-substitution, and is made possible by the lower triangle of zeros in the coefficient matrix, marked with a dashed triangular box. Great, it would be nice if the problem looked like Eq. (5), but it actually looks like Eq. (4), so what now? Numerical Methods Lecture 2 Simultaneous Equations page 78 of 85

CGN 42 - Computer Methods We can use a series of additions of the equations in Eq. (4) to get it to look like Eq. (5). In a series of steps just like the above addition of Eqs (), (2) to get Eq. () we ll reduce the coefficients A( 2, ), A(, ), A( 2, ) to zero, in that order. KEY: Whatever we do to the l.h.s. of an equation, we do to the r.h.s. so we don t change the problem. Let s rewrite the matrix in Eq. (5) to get one matrix with both A and B in it: This is called augmenting the matrix. Step ) - reduce A(2,) to zero l.h.s. 5 2 8 2 2 A B r.h.s. pivot row (6) New Row 2 (Row )(-2/) + (Row 2) Row is called pivot row for this step. Some multiple of it is added to another equation, but the pivot row remains unchanged add 2 2 5 2 2 2 8 2 7 (7) 5 2 8 -- 7 2 New Row 2 (8) Step 2) - reduce A(,) to zero New Row (Row)(-/) + (Row ) Row is the pivot row again Expanding this instruction like we did in Eq.(7), the result is 5 2 8 7 New Row Now we need to reduce A(,2) to zero. If we added some multiple of Row, then A(,) would become non-zero. Instead, we ll need to add some multiple of Row 2 to Row to get a new Row. (9) Numerical Methods Lecture 2 Simultaneous Equations page 79 of 85

CGN 42 - Computer Methods Before we go on, let s consider error reduction... error reduction - swap Rows 2 and If there were some numerical error in the computer storage of any coefficient, say the error from rounding off the -/ currently in spot A(2,2), then when we multiply Row 2 by some factor and add it to Row, we also multiply the error by that factor. If we can always multiply by some small number (less than ), we can reduce the propagation of that round-off error. We can enforce this by making sure the lead coefficient (the pivot coefficient) in the pivot row has the largest absolute value among itself and all the coefficients under it (the coefficients to be reduced to zero). Since it does not matter what order I put the equations in, we will rearrange rows when we find the current pivot coefficient has a smaller absolute value than those beneath it. In the current example we have: 5 2 8 7 Row 2 will be the pivot row to eliminate A(,2), which makes A(2,2) the pivot coefficient. Since >, we ll swap Rows 2 and, and the new pivot coefficient will be largest: 5 2 8 Now we can continue with minimal round-off error propagation 7 () Step ) - reduce A(,2) to zero New Row (Row 2)(-/) + (Row ) Row 2 is the pivot row now 5 2 8 New Row 2 4 Now let s expand this to its full form with A, X, B in separate matrices () Numerical Methods Lecture 2 Simultaneous Equations page 8 of 85

CGN 42 - Computer Methods 5 2 2 X 8 4 (2) Summary of Gaussian Elimination: Starting with a problem defined as in Eq. (4), we created some equivalent problem Eq. (5),(2) with the desired lower triangle of zeros. (2) and (4) are equivalent since all we did was a series of steps where we added the same thing to both sides of a row. Now a little back-substitution (the paragraph following Eq. (5)) gives us X 2 () Solution Method 2 The Inverse matrix (matrix version of division): Let s take another look at the problem AX B (4) where we have A, B, and we want to solve for the unknown(s) X. If this were a scalar problem, the answer is just to divide both sides by A A B -- X -- or X B A. (5) A A There is no dividing with matrices, but we can try to find some other matrix to pre-multiply both sides with such that we re left with MAX ( ) MB ( ) X (6) which says that MAX X. (7) What we seek what is called the Identity matrix (denoted I). A square matrix with ones on the diagonal, and zeros everywhere else. Multiplying any matrix by the Identity matrix (I) is equivalent to multiplying by one in the scalar world. IX X X X (8) Perform the multiplication in Eq. (8) by hand to see that it s true. Numerical Methods Lecture 2 Simultaneous Equations page 8 of 85

CGN 42 - Computer Methods So Eqs. (6), and (7) say that what we want is some magic M such that MAX IX X or MA I. (9) Back in the scalar world again, we can always get by dividing anything by itself, or multiplying anything by its inverse 5 -- 5*. 5 5 -- Y -- --Y Y Y So let s call the matrix we seek, M, the inverse of A, since we want the resulting multiplication to be the identity matrix. We ll change the symbol from M to A to indicate the inverse of A. MA A A I. What we seek is so we can get the solution for from equivalent to equivalent to A X A AX B AX A B (2) (2) equivalent to IX A B (22) X A B (2) Gauss-Jordan Elimination - finding the inverse Gauss-Jordan Elimination I: For the first version of this method, let s continue where we left off in the Gaussian elimination example: 5 2 X 8 X (24) 2 2 X 4 where Gaussian elimination is used to get the lower triangle of zeros. The idea of Gauss Jordan elimination is to continue and get an upper triangle of zeros, until the three equations are completely uncoupled. Just as we worked from top to bottom to get zeros for A(2,), A(,), and A(,2) in that order, we can start working from the bottom up to make A(2,), A(,), and A(,2) zero, in that order. Just start with the bottom as the pivot row to zero A(2,), A(,), then switch the pivot row to the second row to make A(,2) zero. The three steps to get rid of A(2,), A(,), A(,2) would be Step ) New Row 2 (Row )(-/6) + (Row 2) Step 2) New Row (Row )() + (Row ) Step ) New Row (Row 2)(5/) + (Row ) Numerical Methods Lecture 2 Simultaneous Equations page 82 of 85

CGN 42 - Computer Methods And the result is 2 X We see now that the three equations have been completely uncoupled. Now if we multiply each row by whatever it takes to make the A coefficient in that row equal to, we get 9 ----- 4 (25) This last bit of making each coefficient equal to one is called normalizing The solution,, X 2 is now shown directly on the right hand side. Notice that A has been transformed into the identity matrix! X 2 (26) What we have done is built the inverse matrix see in Eq. (26) is exactly the result of A into the right hand side of the equation. So what we AX A A B Summary of Gauss Jordan Elimination I - ) Augment coefficient matrix with the solution vector 2) Create lower triangle of zeros ) Create upper triangle of zeros 4) Normalize the coefficient matrix 5) Values of the unknowns are now in the right hand column Gauss-Jordan Elimination part II - Finding A directly In the above method, we used Gauss-Jordan elimination, and wound up with the result of on the right hand side. A We never actually explicitly saw, it was just built in. A B We can also used Gauss-Jordan elimination to explicitly compute the inverse of A, then multiply this A by B to get the desired unknowns in X as in X A B. As you may have noticed, finding A has nothing to do with what s in B. Only A is needed to find A. Let s look way back at Eq. (6), repeated below Numerical Methods Lecture 2 Simultaneous Equations page 8 of 85

CGN 42 - Computer Methods 5 2 8 2 2 A B We augmented the matrix A with B, since we wanted to operate on B. Now Let s throw out B and replace it with the identity matrix A augmented with B. (27) 5 2 2 2 A I If we now use the Gauss-Jordan elimination method to reduce the three left hand columns to the identity matrix, the result on the right hand side is the inverse of A. We do the exact same steps we did before to get to Eq. (26). Only this time, instead of tacking on B for the ride, we tack on what starts as I for the A ride. When its all over, the right three columns are. Example: we ll just solve for the inverse of a 2x2 Start with (28) The steps are: 2 4 (29) Step ) New Row 2 (Row )(-) + Row 2... 2 2 finished lower triangle of zeros, now get upper triangle of zeros Step 2) New Row (Row 2)() + Row... Step ) Normalize each row: (Row 2)(-/2) 2 2 The result is: 2. ().5.5 Which means A 2. ().5.5 How can I check to make sure the inverse of 2 is really 2????? 4.5.5 We know that A I, Numerical Methods Lecture 2 Simultaneous Equations page 84 of 85

CGN 42 - Computer Methods so let s try it 2.5.5 * 2 4. This checks out, so we ve found the inverse Solving equations using MATLAB Let s go back to the original problem in this lecture + 5 + 2X 8 2 + X 2 X Re-written as 5 2 2 2 X 8 coefficient matrix A unknowns vector X solution vector B Let s use the built in MATLAB commands to solve this problem >> A[ 5 2; 2 -; -2 -]; >> B [8; ; -]; %IMPORTANT: B must be a COLUMN >> % NOT a ROW >> >> X inv(a)*b; >> %OR we can use >> X B\A ; >> %using \ instead of / indicates matrix division inv is a built in MATLAB function that will return the inverse of the matrix in the argument Yep, pages of lecture notes captured in a single MATLAB line (of course the inverse function contains the MATLAB code to augment the matrix, create the upper and lower triangles, and normalize) Numerical Methods Lecture 2 Simultaneous Equations page 85 of 85