Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 10: Solving Linear Systems of Equations

Similar presentations


Presentation on theme: "Chapter 10: Solving Linear Systems of Equations"โ€” Presentation transcript:

1 Chapter 10: Solving Linear Systems of Equations
Introduction Requirements for a solution Gaussian elimination This covers Ch. 8 of the Numerical Methods with MATLAB: Implementation and Application book.

2 Introduction Motivational example: Pump Curve Model
Objective: Find the coefficients of the quadratic equation that approximates the data from a pump. Curve model equation: โ„Ž= ๐‘ 1 ๐‘ž 2 + ๐‘ 2 ๐‘ž+ ๐‘ 3 How to identify ๐‘ 1 , ๐‘ 2 , ๐‘ 3 ? Three data points: 1ร— 10 โˆ’4 ,115 8ร— 10 โˆ’4 ,110 (1.4ร— 10 โˆ’3 ,92.5) โ„Ž: ๐‘ž:

3 Introduction Substitute each pair of data points into the model equation: Rewrite in matrix form as:

4 Introduction Using more compact symbolic notation: ๐ด๐‘ฅ=๐‘
where ๐ด= 1ร— 10 โˆ’8 1ร— 10 โˆ’ ร— 10 โˆ’8 8ร— 10 โˆ’ ร— 10 โˆ’8 14ร— 10 โˆ’4 1 , ๐‘ฅ= ๐‘ 1 ๐‘ 2 ๐‘ 3 , ๐‘= Our goal: How to numerically solve for the unknown vector ๐‘ฅ?

5 Introduction Solving systems of equations is one of the most widely automated computing tasks. In this chapter, we will focus on: setting up a system of equations; using the built-in capability of MATLAB to solve the system; developing and understanding the numerical complications that affect the reliability of the computed result.

6 Introduction The generic system of equations is ๐ด๐‘ฅ=๐‘:
๐ด is an ๐‘šร—๐‘› matrix of known real numbers; ๐‘ฅ is a length-๐‘› vector of unknowns to be determined; ๐‘ is a length-๐‘š vector of known real numbers. Before solving, we always need to go from the physical problem to the general linear-algebra form (๐ด, ๐‘ฅ, and ๐‘). Only consider linear equations hereโ€ฆ

7 Introduction How to put system equations into the standard form? Recommended procedure: Write the equations in their natural form. Identify unknowns, and order them. Isolate the unknowns. Write equations in matrix form.

8 Requirements for a Solution
The nature of the solution to ๐ด๐‘ฅ=๐‘ depends on the shape of matrix ๐ด: โˆŽ โˆŽ โˆŽ โˆŽ โˆŽ โˆŽ โˆŽ โˆŽ โˆŽ ๐‘š=๐‘› โˆŽ โˆŽ โˆŽ โˆŽ โˆŽ โˆŽ โˆŽ โˆŽ โˆŽ โˆŽ โˆŽ โˆŽ ๐‘š>๐‘› โˆŽ โˆŽ โˆŽ โˆŽ โˆŽ โˆŽ โˆŽ โˆŽ โˆŽ โˆŽ โˆŽ โˆŽ ๐‘š<๐‘› Solving ๐ด๐‘ฅ=๐‘ for ๐‘› unknowns related by ๐‘› equations. Overdetermined systems (more equations than unknowns) Underdetermined systems (less equations than unknowns).

9 Requirements for a Solution
Consistency: the Elements of the unknown vector ๐‘ฅ are the coefficients in the linear combination of the columns of ๐ด that yield the vector ๐‘. ๐ด๐‘ฅ=๐‘ โ†” ๐‘ฅ 1 ๐‘Ž 11 โ‹ฎ ๐‘Ž ๐‘š1 + ๐‘ฅ 2 ๐‘Ž 12 โ‹ฎ ๐‘Ž ๐‘š2 +โ€ฆ+ ๐‘ฅ ๐‘› ๐‘Ž 1๐‘› โ‹ฎ ๐‘Ž ๐‘š๐‘› = ๐‘ 1 โ‹ฎ ๐‘ ๐‘š If an exact solution to Ax = b exists, b must lie in the column space of A. If it does, then the system is said to be consistent. Otherwise, the system is said to be inconsistent.

10 Requirements for a Solution
How to check if a system is consistent or not? Can be expressed by forming the augmented matrix ๐ด from the columns of ๐ด and the vector ๐‘: ๐ด = ๐ด ๐‘ = ๐‘Ž 11 โ‹ฎ ๐‘Ž ๐‘š1 ๐‘Ž 12 โ‹ฎ ๐‘Ž ๐‘š2 โ€ฆ ๐‘Ž 1๐‘› โ‹ฎ ๐‘Ž ๐‘š๐‘› ๐‘ 1 โ‹ฎ ๐‘ ๐‘š ๐ด and ๐‘ are consistent if and only if ๐ด and ๐ด have the same rank, i.e. rank( ๐ด )=rank (๐ด). If rank( ๐ด )>rank (๐ด), the vector ๐‘ does not lie in the column space of ๐ด. An exact solution is therefore not possible.

11 Requirements for a Solution
Role of ๐‘Ÿ๐‘Ž๐‘›๐‘˜(๐ด): If ๐‘Ÿ๐‘Ž๐‘›๐‘˜(๐ด) = ๐‘› and the system is consistent, the solution exists and it is unique. If ๐‘Ÿ๐‘Ž๐‘›๐‘˜(๐ด) < ๐‘› and the system is consistent, an infinite number of solutions exist. If the system is inconsistent, no solution exists. E.g., ๐‘ฅ 1 ๐‘ฅ 2 = rank (A)=rank([A b]): the system is consistent, and solution exists. rank(A)=2=# of unknowns: the solution is unique.

12 Requirements for a Solution
Special case, ๐’Ž=๐’: For ๐‘›ร—๐‘› systems, the rank of ๐ด tells us a lot. If ๐‘Ÿ๐‘Ž๐‘›๐‘˜(๐ด)=๐‘›, the columns of ๐ด span the ๐‘น ๐‘› space, and hence any length-๐‘› vector lies in the column space of ๐ด. In other words, ๐‘Ÿ๐‘Ž๐‘›๐‘˜([๐ด ๐‘])=๐‘› for any vector ๐‘. For a system of ๐‘› equations and ๐‘› unknowns in the form ๐ด๐‘ฅ=๐‘, the solution ๐‘ฅ exists and is unique for any ๐‘ if and only if ๐‘Ÿ๐‘Ž๐‘›๐‘˜(๐ด)=๐‘›.

13 Requirements for a Solution
Again, for ๐‘›ร—๐‘› systems, the unique solution is ๐‘ฅ= ๐ด โˆ’1 ๐‘ if and only if ๐ด โˆ’1 exists. Several ways to check if ๐ด โˆ’1 exists or not (equivalent conditions): ๐‘Ÿ๐‘Ž๐‘›๐‘˜(๐ด)=๐‘› (๐ด is a full rank matrix) detโก(๐ด)โ‰ 0 The columns of ๐ด are linearly independent. The rows of ๐ด are linearly independent.

14 Requirements for a Solution
If ๐ด โˆ’1 exists, ๐ด๐‘ฅ=๐‘ โ†’ ๐‘ฅ= ๐ด โˆ’1 ๐‘ Lots of computer tools allow you to compute ๐ด โˆ’1 directly, so then you can find ๐‘ฅ . However, there are many reasons you may not want to solve equations this way: more roundoff error, more operations (computations), โ€ฆ We use Gaussian elimination to solve the system. Not only saves computer time, also produces a result with less roundoff error (fewer operations). The matrix inverse ๐ด โˆ’1 is more of a conceptual device than a computational tool here. People donโ€™t normally use it to solve linear systems.

15 Gaussian Elimination To start, let us consider a special case:
Triangular systems: Lower triangular systems: ๐‘Ž ๐‘–๐‘— =0 for all ๐‘–<๐‘— ๐ด= ๐‘Ž ๐‘Ž 21 โ‹ฎ ๐‘Ž ๐‘› ๐‘Ž 22 โ‹ฎ ๐‘Ž ๐‘›2 โ€ฆ โ‹ฎ ๐‘Ž ๐‘›๐‘› Upper triangular systems: ๐‘Ž ๐‘–๐‘— =0 for all ๐‘–>๐‘— ๐ด= ๐‘Ž โ‹ฎ ๐‘Ž ๐‘Ž 22 โ‹ฎ 0 โ€ฆ ๐‘Ž 1๐‘› ๐‘Ž 2๐‘› โ‹ฎ ๐‘Ž ๐‘›๐‘›

16 Gaussian Elimination Solving triangular systems: (upper-triangular)
Equivalent to solve: Solve in backward order (last equation is solved first):

17 Gaussian Elimination Solving for ๐‘ฅ ๐‘› , ๐‘ฅ ๐‘›โˆ’1 ,โ€ฆ, ๐‘ฅ 1 for an upper triangular system is called backward substitution.

18 Gaussian Elimination Solving triangular systems: (lower-triangular)
๐ด= โˆ’2 0 โˆ’ , b= 8 โˆ’1 9 Equivalent to solve: 4 ๐‘ฅ 1 =8 3 ๐‘ฅ 1 โˆ’2 ๐‘ฅ 2 =โˆ’1 โˆ’2 ๐‘ฅ 1 + ๐‘ฅ 2 +2 ๐‘ฅ 3 =9 Solve in forward order (first equation is solved first): ๐‘ฅ 1 =8/4=2 ๐‘ฅ 2 =(3 ๐‘ฅ 1 +1)/2=7/2 ๐‘ฅ 3 =(9+2 ๐‘ฅ 1 โˆ’ ๐‘ฅ 2 )/2=19/4

19 Gaussian Elimination Solving for ๐‘ฅ 1 , ๐‘ฅ 2 ,โ€ฆ, ๐‘ฅ ๐‘› for a lower triangular system is called forward substitution.

20 Gaussian Elimination How to solve a general equation by hand?
Subtract 2 times the first equation from the second equation This equation is now in upper-triangular form, and can be solved by backward substitution. The elimination phase transforms the matrix and right hand side to an equivalent system. The two systems have the same solution.

21 Gaussian Elimination Goal is to transform an arbitrary, square system into the equivalent upper triangular system so that it may be easily solved with backward substitution. We need to perform the Gaussian elimination to [๐ด ๐‘], the augmented matrix (not just ๐ด)!

22 Gaussian Elimination For example, to solve: Form the augmented system:
Add 2 times row 1 to row 2, and add (1 times) row 1 to row 3: ๐ด (1) Subtract (1 times) row 2 from row 3: ๐ด (2)

23 Gaussian Elimination The transformed system is now in upper triangular form: Solve by back substitution to get:

24 Gaussian Elimination The procedure for Gaussian elimination:
Pivot: ๐‘Ž ๐‘–๐‘– , ratio: ๐‘Ž ๐‘˜๐‘– / ๐‘Ž ๐‘–๐‘– ๐‘Ž ๐‘˜๐‘— = ๐‘Ž ๐‘˜๐‘— โˆ’( ๐‘Ž ๐‘˜๐‘– / ๐‘Ž ๐‘–๐‘– )โˆ— ๐‘Ž ๐‘–๐‘— ๐ด = ๐ด ๐‘ = ๐‘Ž 11 ๐‘Ž ๐‘Ž 13 ๐‘Ž 14 ๐‘ 1 ๐‘Ž 21 ๐‘Ž ๐‘Ž 23 ๐‘Ž 24 ๐‘ ๐‘Ž 31 ๐‘Ž ๐‘Ž 32 ๐‘Ž ๐‘Ž 33 ๐‘Ž 34 ๐‘ ๐‘Ž 43 ๐‘Ž 44 ๐‘ 4 Column ๐‘–=1 Column ๐‘–=2 Column ๐‘–=3 Row ๐‘–=1 Row ๐‘–=2 Row ๐‘–=3 ร—( ๐‘Ž 41 / ๐‘Ž 11 ) ร—( ๐‘Ž 31 / ๐‘Ž 11 ) ร—( ๐‘Ž 21 / ๐‘Ž 11 ) ร—( ๐‘Ž 43 โ€ฒโ€ฒ / ๐‘Ž 33 โ€ฒโ€ฒ ) ร—( ๐‘Ž 32 โ€ฒ / ๐‘Ž 22 โ€ฒ ) ร—( ๐‘Ž 42 โ€ฒ / ๐‘Ž 22 โ€ฒ ) Row ๐‘˜=2 Row ๐‘˜=3 Row ๐‘˜=4

25 Gaussian Elimination Note : This process requires that all the diagonal elements are nonzero! (Otherwise the ratio ๐‘Ž ๐‘˜๐‘— / ๐‘Ž ๐‘–๐‘– is undefined since denominator is zero.) The GaussianElimination function uses Gaussian elimination to solve a system of equations. >> GaussianElimination(A,b) ans = 2 -1

26 Gaussian Elimination Unfortunately, the Gaussian elimination algorithm does not work alwaysโ€ฆ One counterexample: matrix ๐ด is full rank, a unique solution exists. Now form the augmented system:

27 Gaussian Elimination Start the elimination for the pivot location ๐‘Ž 11 : Subtract 1/2 times the first row from the second row; Add 3/2 times the first row to the third row; Add 1/2 times the first row to the fourth row. The next stage of Gaussian elimination will not work, because there is a zero in the pivot location ๐‘Ž 22 .

28 Gaussian Elimination What to do if we run into this situation?
A smart way is to swap the second and fourth rows of the augmented matrix. Why does this work? Because we are just re-ordering the unknowns here, and not changing the system. This row exchanging method to avoid zeros at pivot locations is called Gaussian Elimination with Pivoting.

29 Gaussian Elimination Continue with elimination: subtract (1 times) row 2 from row 3. Another zero has appear in the pivot position. Swap row 3 and row 4. The augmented system is now ready for backward substitution.

30 Gaussian Elimination The GaussianEliminationPivot function uses Gaussian elimination with pivoting to solve a system of equations.

31 Gaussian Elimination Ex: >> GaussianEliminationPivot(A,b)
Swap rows 1 and 3; new pivot = -3 Swap rows 2 and 3; new pivot = 2 ans = 1.0000 2.0000 3.0000 4.0000


Download ppt "Chapter 10: Solving Linear Systems of Equations"

Similar presentations


Ads by Google