Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 9 Gauss Elimination.

Similar presentations


Presentation on theme: "Chapter 9 Gauss Elimination."— Presentation transcript:

1 Chapter 9 Gauss Elimination

2 Gauss Elimination 9.1 Solving small numbers of equations
9.2 Naive Gauss Elimination 9.3 Pivoting 9.4 Tridiagonal Systems MATLAB M-files GaussNaive, GaussPivot, Tridiag

3 Small Matrices Graphical Cramer's rule Elimination
For small numbers of equations, can be solved by hand Graphical Cramer's rule Elimination

4 Graphical Method x1 + x2 = 3 2x1 – x2 = 3 One solution

5 Graphical Method No solution 2x1 – x2 = – 1 2x1 – x2 = 3

6 Graphical Method Infinite many solution 2x1 – x2 = 3 6x1 – 3x2 = 9

7 Graphical Method Ill conditioned 2x1 – x2 = 3 2.1x1 – x2 = 3

8 Cramer’s Rule Compute the determinant D 2 x 2 matrix 3 x 3 matrix

9 Cramer’s Rule To find xk for the following system
Replace kth column of as with bs (i.e., aik  bi )

10 Example 3 x 3 matrix

11 Ill-Conditioned System
What happen if the determinant D is very small or zero? Divided by zero (linearly dependent system) Divided by a small number: Round-off error Loss of significant digits

12 Elimination Method Eliminate x2  Subtract to get
Not very practical for large number (> 4) of equations

13 MATLAB’s Methods Forward slash ( / ) Back-slash ( \ )
Multiplication by the inverse of the quantity under the slash

14 Gauss Elimination Manipulate equations to eliminate one of the unknowns Develop algorithm to do this repeatedly The goal is to set up upper triangular matrix Back substitution to find solution (root)

15 Basic Gauss Elimination
Direct Method (no iteration required) Forward elimination Column-by-column elimination of the below-diagonal elements Reduce to upper triangular matrix Back-substitution

16 Naive Gauss Elimination
Begin with Multiply the first equation by a21 / a11 and subtract from second equation

17 Gauss Elimination Reduce to Repeat the forward elimination to get

18 Gauss Elimination First equation is pivot equation
a11 is pivot element Now multiply second equation by a'32 /a'22 and subtract from third equation

19 Gauss Elimination Repeat the elimination of ai2 and get
Continue and get

20 Back Substitution Now we can perform back substitution to get {x}
By simple division Substitute this into (n-1)th equation Solve for xn-1 Repeat the process to solve for xn-2 , xn-3 , …. x2, x1

21 Back Substitution Back substitution: starting with xn
Solve for xn1 , xn2 , … , 3, 2, 1 for i = n1, n2, …, 1 Naive Gauss Elimination

22 Elimination of first column

23 Elimination of second column

24 Elimination of third column
Upper triangular matrix

25 Back-Substitution Upper triangular matrix

26 Example

27 Forward Elimination

28 Upper Triangular Matrix

29 Back-Substitution

30 MATLAB Script File: GaussNaive

31 Print all factor and Aug (do not suppress output)
>> format short >> x = GaussNaive(A,b) m = 4 n = Aug = factor = -1 6 factor = 0.5000 Aug = 1 14 x = 0.4714 0.2286 x4 Aug = [A, b] x3 x2 Eliminate second column x1 Back-substitution Eliminate third column Print all factor and Aug (do not suppress output) Eliminate first column

32 Algorithm for Gauss elimination
1. Forward elimination for each equation j, j = 1 to n-1 for all equations k greater than j (a) multiply equation j by akj /ajj (b) subtract the result from equation k This leads to an upper triangular matrix 2. Back-Substitution (a) determine xn from (b) put xn into (n-1)th equation, solve for xn-1 (c) repeat from (b), moving back to n-2, n-3, etc until all equations are solved

33 Operation Count Important as matrix gets large For Gauss elimination
Elimination routine uses on the order of O(n3/3) operations Back-substitution uses O(n2/2)

34 Operation Count Total operation counts for elimination stage = 2n3/3 + O(n2) Total operation counts for back substitution stage = n2 + O(n)

35 Operation Count Number of flops (floating-point operations) for Naive Gauss elimination Computation time increase rapidly with n Most of the effort is incurred in the elimination step Improve efficiency by reducing the elimination effort

36 Partial Pivoting Problems with Gauss elimination
division by zero round off errors ill conditioned systems Use “Pivoting” to avoid this Find the row with largest absolute coefficient below the pivot element Switch rows (“partial pivoting”) complete pivoting switch columns also (rarely used)

37 Round-off Errors A lot of chopping with more than n3/3 operations
More important - error is propagated For large systems (more than 100 equations), round-off error can be very important (machine dependent) Ill conditioned systems - small changes in coefficients lead to large changes in solution Round-off errors are especially important for ill-conditioned systems

38 Ill-conditioned System
2x1 – x2 = 3 2.1x1 – x2 = 3

39 Ill-Conditioned System
Consider Since slopes are almost equal Divided by small number

40 Determinant Calculate determinant using Gauss elimination

41 Gauss Elimination with Partial Pivoting
Forward elimination for each equation j, j = 1 to n-1 first scale each equation k greater than j then pivot (switch rows) Now perform the elimination (a) multiply equation j by akj /ajj (b) subtract the result from equation

42 Partial (Row) Pivoting

43 Forward Elimination Interchange rows 1 & 4

44 Forward Elimination No interchange required

45 Back-Substitution Interchange rows 3 & 4

46 MATLAB M-File: GaussPivot
Partial Pivoting (switch rows) largest element in {x} [big,i] = max(x) Partial Pivoting index of the largest element

47 Eliminate first column
>> format short >> x=GaussPivot0(A,b) Aug = big = 6 i = 4 ipr = factor = 0.1667 Aug = [A b] Find the first pivot element and its index Interchange rows 1 and 4 Eliminate first column No need to interchange

48 Save factors fij for LU Decomposition
Back substitution big = 2.3333 i = 1 ipr = 2 factor = 0.4286 Aug = 4 Second pivot element and index No need to interchange x = 0.4714 0.2286 Eliminate second column Third pivot element and index Interchange rows 3 and 4 Save factors fij for LU Decomposition Eliminate third column

49 TRUSS 4 5 F45 F35 F14 F24 F25   1 3 H1 2 F23 F12 V1 V3  
W = 100 kg

50 Statics: Force Balance
Node 1 Node 2 Node 3 Node 4 Node 5

51 Example: Forces in a Simple Truss

52 Define Matrices A and b in script file
function [A,b]=Truss(alpha,beta,gamma,delta) A=zeros(10,10); A(1,1)=1; A(1,5)=sin(alpha); A(2,2)=1; A(2,4)=1; A(2,5)=cos(alpha); A(3,7)=sin(beta); A(3,8)=sin(gamma); A(4,4)=-1; A(4,6)=1; A(4,7)=-cos(beta); A(4,8)=cos(gamma); A(5,3)=1; A(5,9)=sin(gamma); A(6,6)=-1; A(6,9)=-cos(delta); A(7,5)=-sin(alpha); A(7,7)=-sin(beta); A(8,5)=-cos(alpha); A(8,7)=cos(beta); A(8,10)=1; A(9,8)=-sin(gamma); A(9,9)=-sin(delta); A(10,8)=-cos(gamma); A(10,9)=cos(delta); A(10,10)=-1; b=zeros(10,1); b(3,1)=100;

53 Gauss Elimination with Partial Pivoting
>> alpha=pi/6; beta=pi/3; gamma=pi/4; delta=pi/3; >> [A,b] = Truss(alpha,beta,gamma,delta) A = b = 100 >> x = GaussPivot(A,b) x = Simple truss

54 Banded Matrix HBW: Half Band Width

55 Banded Matrix ai,j= 0 if j > i + HB or j< i - HB
HB: Half Bandwidth B: Bandwidth B = 2*HB + 1 In this example HB = 1 & B = 3

56 Tridiagonal Matrix Only three nonzero elements in each equation (3n instead of n2 elements) Subdiagonal, diagonal, superdiagonal Row Scaling (not implemented in textbook) -- scale the diagonal element to aii = 1 Solve by Gauss elimination

57 Tridiagonal Matrix Special case of banded matrix with bandwidth = 3
Save storage, 3  n instead of n  n

58 Tridiagonal Matrix Forward elimination Back substitution
Use factor = ek / fk1 to eliminate subdiagonal element Apply the same matrix operations to right hand side

59 Hand Calculations: Tridiagonal Matrix
(a) Forward elimination (b) Back substitution

60 MATLAB M-file: Tridiag

61 Example: Tridiagonal matrix
function [e,f,g,r] = example e=[ ]; f=[ ]; g=[ ]; r=[ ]; » [e,f,g,r] = example e = f = g = r = » x = Tridiag (e, f, g, r) x = Note: e(1) = 0 and g(n) = 0

62 Chapter 8 Problem 8.2 (20), 8.3(10), 8.7(15) Chapter 9
CVEN Homework No. 6 Chapter 8 Problem 8.2 (20), 8.3(10), 8.7(15) Chapter 9 Problem 9.5 (15), 9.8(20), 9.11(20). Due Monday 10/06/08 at the beginning of the period


Download ppt "Chapter 9 Gauss Elimination."

Similar presentations


Ads by Google