Chapter 9 Gauss Elimination.

Slides:



Advertisements
Similar presentations
Chapter 2 Solutions of Systems of Linear Equations / Matrix Inversion
Advertisements

Chapter: 3c System of Linear Equations
Algebraic, transcendental (i.e., involving trigonometric and exponential functions), ordinary differential equations, or partial differential equations...
MATH 685/ CSI 700/ OR 682 Lecture Notes
Scientific Computing Linear Systems – Gaussian Elimination.
Simultaneous Linear Equations
Systems of Linear Equations
SOLVING SYSTEMS OF LINEAR EQUATIONS. Overview A matrix consists of a rectangular array of elements represented by a single symbol (example: [A]). An individual.
CISE301_Topic3KFUPM1 SE301: Numerical Methods Topic 3: Solution of Systems of Linear Equations Lectures 12-17: KFUPM Read Chapter 9 of the textbook.
Lecture 9: Introduction to Matrix Inversion Gaussian Elimination Sections 2.4, 2.5, 2.6 Sections 2.2.3, 2.3.
Part 3 Chapter 9 Gauss Elimination
Solution of linear system of equations
Chapter 9 Gauss Elimination The Islamic University of Gaza
Major: All Engineering Majors Author(s): Autar Kaw
Ecuaciones Algebraicas lineales. An equation of the form ax+by+c=0 or equivalently ax+by=- c is called a linear equation in x and y variables. ax+by+cz=d.
Linear Algebraic Equations
LU method 1) factor (decompose) A into L and U 2) given b, determine d 3) using Ux=d and backsubstitution, solve for x Advantage: Once you have L and U,
Chapter 10 LU Decomposition.
Chapter 8 Linear Algebraic Equations and Matrices.
Dr. Jie Zou PHY Chapter 3 Solution of Simultaneous Linear Algebraic Equations: Lecture (II) Note: Besides the main textbook, also see Ref: Applied.
MATRIX METHODS SYSTEMS OF LINEAR EQUATIONS
ECIV 520 Structural Analysis II Review of Matrix Algebra.
Dr. Jie Zou PHY Chapter 3 Solution of Simultaneous Linear Algebraic Equations: Lecture (III) Note: Besides the main textbook, also see Ref: Applied.
1 Systems of Linear Equations (Optional) Special Matrices.
Chapter 11 Matrix Inverse and Condition. zHow do we get inverse [A]  1 ? zOne way is through LU decomposition and back- substitution zSolve [A]{x i }
Algorithm for Gauss elimination 1) first eliminate for each eq. j, j=1 to n-1 for all eq.s k greater than j a) multiply eq. j by a kj /a jj b) subtract.
ECIV 301 Programming & Graphics Numerical Methods for Engineers REVIEW II.
Mujahed AlDhaifallah (Term 342) Read Chapter 9 of the textbook
Systems of Linear Equations
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. by Lale Yurttas, Texas A&M University Part 31 Chapter.
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 ~ Linear Algebraic Equations ~ Gauss Elimination Chapter.
Major: All Engineering Majors Author(s): Autar Kaw
Chapter 8 Objectives Understanding matrix notation.
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. by Lale Yurttas, Texas A&M University Part 31 Linear.
Linear Systems Gaussian Elimination CSE 541 Roger Crawfis.
Engineering Analysis ENG 3420 Fall 2009 Dan C. Marinescu Office: HEC 439 B Office hours: Tu-Th 11:00-12:00.
MECN 3500 Inter - Bayamon Lecture 7 Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar E. Meza Castillo
ΑΡΙΘΜΗΤΙΚΕΣ ΜΕΘΟΔΟΙ ΜΟΝΤΕΛΟΠΟΙΗΣΗΣ 4. Αριθμητική Επίλυση Συστημάτων Γραμμικών Εξισώσεων Gaussian elimination Gauss - Jordan 1.
Chemical Engineering Majors Author(s): Autar Kaw
Lecture 7 - Systems of Equations CVEN 302 June 17, 2002.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 3 - Chapter 9 Linear Systems of Equations: Gauss Elimination.
Gaussian Elimination Electrical Engineering Majors Author(s): Autar Kaw Transforming Numerical Methods Education for.
Chapter 9 Gauss Elimination The Islamic University of Gaza
1 Gauss Elimination Small Matrices  For small numbers of equations, solvable by hand  Graphical  Cramer's rule  Elimination 2.
Gaussian Elimination Industrial Engineering Majors Author(s): Autar Kaw Transforming Numerical Methods Education for.
Gaussian Elimination Mechanical Engineering Majors Author(s): Autar Kaw Transforming Numerical Methods Education for.
Lecture 6 - Single Variable Problems & Systems of Equations CVEN 302 June 14, 2002.
Part 3 Chapter 9 Gauss Elimination PowerPoints organized by Dr. Michael R. Gustafson II, Duke University All images copyright © The McGraw-Hill Companies,
Gaussian Elimination Civil Engineering Majors Author(s): Autar Kaw Transforming Numerical Methods Education for STEM.
Unit #1 Linear Systems Fall Dr. Jehad Al Dallal.
Autar Kaw Benjamin Rigsby Transforming Numerical Methods Education for STEM Undergraduates.
Numerical Methods. Introduction Prof. S. M. Lutful Kabir, BRAC University2  One of the most popular techniques for solving simultaneous linear equations.
1 Numerical Methods Solution of Systems of Linear Equations.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 Part 3 - Chapter 9.
Numerical Methods. Prof. S. M. Lutful Kabir, BRAC University2  One of the most popular techniques for solving simultaneous linear equations is the Gaussian.
Pitfalls of Gauss Elimination ● Division by zero (avoid by pivoting) ● Round-off errors – Important with >100 eqns – Substitute answer into original eqn.
Part 3 Chapter 9 Gauss Elimination
Chapter: 3c System of Linear Equations
Simultaneous Linear Equations
Spring Dr. Jehad Al Dallal
Gaussian Elimination.
Choi, Jong-In Lee, Ho-Keun Shim, Yoon-Sik
Naïve Gauss Elimination Pitfalls
Part 3 - Chapter 9.
Engineering Analysis ENG 3420 Fall 2009
Major: All Engineering Majors Author(s): Autar Kaw
Lecture 13 Simultaneous Linear Equations – Gaussian Elimination (2) Partial Pivoting Dr .Qi Ying.
Simultaneous Linear Equations Gaussian Elimination with Partial Pivoting
Chapter 11 Chapter 11.
Naïve Gauss Elimination Pitfalls
Presentation transcript:

Chapter 9 Gauss Elimination

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

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

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

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

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

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

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

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

Example 3 x 3 matrix

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

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

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

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)

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

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

Gauss Elimination Reduce to Repeat the forward elimination to get

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

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

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

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

Elimination of first column

Elimination of second column

Elimination of third column Upper triangular matrix

Back-Substitution Upper triangular matrix

Example

Forward Elimination

Upper Triangular Matrix

Back-Substitution

MATLAB Script File: GaussNaive

Print all factor and Aug (do not suppress output) >> format short >> x = GaussNaive(A,b) m = 4 n = Aug = 1 0 2 3 1 -1 2 2 -3 -1 0 1 1 4 2 6 2 2 4 1 factor = -1 0 2 4 0 0 6 0 2 -10 -14 -5 factor = 0.5000 Aug = 1 0 2 3 1 0 2 4 0 0 0 0 -1 4 2 0 2 -10 -14 -5 1 0 0 -14 -14 -5 14 0 0 0 -70 -33 x = 0.4714 -0.1143 0.2286 -0.1857 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

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

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)

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

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

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)

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

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

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

Determinant Calculate determinant using Gauss elimination

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

Partial (Row) Pivoting

Forward Elimination Interchange rows 1 & 4

Forward Elimination No interchange required

Back-Substitution Interchange rows 3 & 4

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

Eliminate first column >> format short >> x=GaussPivot0(A,b) Aug = 1 0 2 3 1 -1 2 2 -3 -1 0 1 1 4 2 6 2 2 4 1 big = 6 i = 4 ipr = factor = -0.1667 6.0000 2.0000 2.0000 4.0000 1.0000 0 2.3333 2.3333 -2.3333 -0.8333 0 1.0000 1.0000 4.0000 2.0000 1.0000 0 2.0000 3.0000 1.0000 0.1667 0 -0.3333 1.6667 2.3333 0.8333 Aug = [A b] Find the first pivot element and its index Interchange rows 1 and 4 Eliminate first column No need to interchange

Save factors fij for LU Decomposition Back substitution big = 2.3333 i = 1 ipr = 2 factor = 0.4286 Aug = 6.0000 2.0000 2.0000 4.0000 1.0000 0 2.3333 2.3333 -2.3333 -0.8333 0 0 0 5.0000 2.3571 0 -0.3333 1.6667 2.3333 0.8333 -0.1429 0 0 2.0000 2.0000 0.7143 4 Second pivot element and index No need to interchange x = 0.4714 -0.1143 0.2286 -0.1857 Eliminate second column Third pivot element and index Interchange rows 3 and 4 Save factors fij for LU Decomposition Eliminate third column

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

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

Example: Forces in a Simple Truss

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;

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 = 1.0000 0 0 0 0.5000 0 0 0 0 0 0 1.0000 0 1.0000 0.8660 0 0 0 0 0 0 0 0 0 0 0 0.8660 0.7071 0 0 0 0 0 -1.0000 0 1.0000 -0.5000 0.7071 0 0 0 0 1.0000 0 0 0 0 0 0.7071 0 0 0 0 0 0 -1.0000 0 0 -0.5000 0 0 0 0 0 -0.5000 0 -0.8660 0 0 0 0 0 0 0 -0.8660 0 0.5000 0 0 1.0000 0 0 0 0 0 0 0 -0.7071 -0.8660 0 0 0 0 0 0 0 0 -0.7071 0.5000 -1.0000 b = 100 >> x = GaussPivot(A,b) x = 40.5827 48.5140 70.2914 -81.1655 34.3046 46.8609 84.0287 -68.6091 -93.7218 Simple truss

Banded Matrix HBW: Half Band Width

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

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

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

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

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

MATLAB M-file: Tridiag

Example: Tridiagonal matrix function [e,f,g,r] = example e=[ 0 -2 4 -0.5 1.5 -3]; f=[ 1 6 9 3.25 1.75 13]; g=[-2 4 -0.5 1.5 -3 0]; r=[-3 22 35.5 -7.75 4 -33]; » [e,f,g,r] = example e = 0 -2.0000 4.0000 -0.5000 1.5000 -3.0000 f = 1.0000 6.0000 9.0000 3.2500 1.7500 13.0000 g = -2.0000 4.0000 -0.5000 1.5000 -3.0000 0 r = -3.0000 22.0000 35.5000 -7.7500 4.0000 -33.0000 » x = Tridiag (e, f, g, r) x = 1 2 3 -1 -2 -3 Note: e(1) = 0 and g(n) = 0

Chapter 8 Problem 8.2 (20), 8.3(10), 8.7(15) Chapter 9 CVEN 302-501 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