Lecture 13 Simultaneous Linear Equations – Gaussian Elimination (2) Partial Pivoting Dr .Qi Ying.

Slides:



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

CSCI-455/552 Introduction to High Performance Computing Lecture 25.
Linear Algebra Applications in Matlab ME 303. Special Characters and Matlab Functions.
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
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.
Linear Systems Pivoting in Gaussian Elim. CSE 541 Roger Crawfis.
Part 3 Chapter 9 Gauss Elimination
Chapter 9 Gauss Elimination The Islamic University of Gaza
Major: All Engineering Majors Author(s): Autar Kaw
Linear Algebraic Equations
ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 17 Solution of Systems of Equations.
ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 15 Solution of Systems of Equations.
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.
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.
Major: All Engineering Majors Author(s): Autar Kaw
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. by Lale Yurttas, Texas A&M University Part 31 Linear.
Advanced Computer Graphics Spring 2014 K. H. Ko School of Mechatronics Gwangju Institute of Science and Technology.
Square n-by-n Matrix.
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.
Yasser F. O. Mohammad Assiut University Egypt. Previously in NM Introduction to NM Solving single equation System of Linear Equations Vectors and Matrices.
ΑΡΙΘΜΗΤΙΚΕΣ ΜΕΘΟΔΟΙ ΜΟΝΤΕΛΟΠΟΙΗΣΗΣ 4. Αριθμητική Επίλυση Συστημάτων Γραμμικών Εξισώσεων Gaussian elimination Gauss - Jordan 1.
13.6 MATRIX SOLUTION OF A LINEAR SYSTEM.  Examine the matrix equation below.  How would you solve for X?  In order to solve this type of equation,
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.
Direct Methods for Linear Systems Lecture 3 Alessandra Nardi Thanks to Prof. Jacob White, Suvranu De, Deepak Ramaswamy, Michal Rewienski, and Karen Veroy.
Chapter 9 Gauss Elimination The Islamic University of Gaza
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.
Linear Systems Dinesh A.
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.
Lecture 9 Numerical Analysis. Solution of Linear System of Equations Chapter 3.
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
Simultaneous Linear Equations
Spring Dr. Jehad Al Dallal
Gaussian Elimination.
CHAPTER 9: GAUSSIAN ELIMINATION.
Chapter 10: Solving Linear Systems of Equations
Naïve Gauss Elimination Pitfalls
Part 3 - Chapter 9.
Engineering Analysis ENG 3420 Fall 2009
Simultaneous Linear Equations
Lecture 11 Matrices and Linear Algebra with MATLAB
Major: All Engineering Majors Author(s): Autar Kaw
Review of Matrix Algebra
Numerical Analysis Lecture14.
Numerical Analysis Lecture10.
Gaussian Elimination.
Simultaneous Linear Equations
Simultaneous Linear Equations Gaussian Elimination with Partial Pivoting
Lecture 8 Matrix Inverse and LU Decomposition
Naïve Gauss Elimination Pitfalls
Presentation transcript:

Lecture 13 Simultaneous Linear Equations – Gaussian Elimination (2) Partial Pivoting Dr .Qi Ying

Objectives Understanding and implementing partial pivoting Understanding the solution technique for the tridiagonal system

Example Consider the following system Using Gaussian elimination, the multiplying factor is 1/ε: Solution is:

Try it with our simple Gauss-elimination solver. >> A=[1e-17 1 ; 1 1] A = 0.000000000000000 1.000000000000000 1.000000000000000 1.000000000000000 >> b=[2 1]’ b = 2 1 >> gauss_simple(A,b) ans = 0 2

What happened? If ε is small, for example 1e-17, then 1/ε=1e17, and 1- 1/ε=-1/ε (when using double precision) becomes and the solution is which is obviously wrong

Gauss Elimination – Improvement using pivoting Examine the factor used in the forward elimination Fac=A(m,i)/A(i,i); A(i,i) = 0 -- leads to “divide by zero” error Solution: rearrange the rows so that the ith diagonal element is none zero. 2. A(i,i) is close to zero – leads to roundoff error. Solution: rearrange the rows so that the ith diagonal element is as large as possible.

Pivoting (1) Fundamentals Pivot element: in the ith step of the forward elimination process, A(i,i) is called the pivot element

Pivoting (2) Fundamentals Row switching does not change to solution of the linear system and the order of the unknowns.

Pivoting (3) Fundamentals Switching columns does not change the solution of the system but change the order of the unknowns

Pivoting (4) Partial pivoting finds the coefficient with the largest absolute value in the column below the pivot element. Row swap operations are used to make the coefficient the pivoting element. Full pivoting finds the coefficient with the largest absolute value in the columns and rows below the pivot element. Both row and column swaps are used to make the coefficient the pivoting element.

Partial Pivoting row i row m Find the largest in these coefficients

Example Partial pivoting: Forward elimination: This always generates the correct solution:

Partial pivoting code row i row m [max_num,ir]=max(abs(A(i:n,i))) % ir is the row that has the % largest coefficient irow=ir+i-1; % row index in the complete matrix for m=i:n % now swap the coeffients between temp=A(i,m); % row (i) and row (irow) A(i,m)=A(irow,m); A(irow,m)=temp; end temp=b(i); % and the RHS coefficients b(i)=b(irow); b(irow)=temp; row i row m

Exercise Implement the partial pivoting code in the gauss_simple code and call the new function gauss_partial_pivoting. Test the Guass elimination with partial pivoting using the example. Could you get the correct result? >> A=[1e-17 1 ; 1 1] A = 0.000000000000000 1.000000000000000 1.000000000000000 1.000000000000000 >> b=[2 1]’ b = 2 1 >> gauss_partial_pivoting(A,b)

Tri-diagonal Systems

Tri-diagonal Systems Gaussian elimination for tri-diagonal system – can be very efficient because there are many zeros in the coefficients Equations for forward elimination:

Tri-diagonal Systems Back substitution is also easier

Example Code function x=tridiag(e,f,g,r) % TRIDIAG solves a tridiagonal linear equation system. % Inputs: % e,f,g: coefficients in the diagonals % r: right hand size vector % Output: % x: solution vector n=length(f); % forward elimination for i=2:n fac=e(i)/f(i-1); f(i)=f(i)-fac*g(i-1); r(i)=r(i)-fac*r(i-1); end % back substitution x(n)=r(n)/f(n) for i=n-1:-1:1 x(i)=(r(i)-g(i)*x(i+1))/f(i)

Non-singular condition For a square coefficient matrix A, the product of the main diagonal elements after Gaussian elimination process is not zero. Otherwise, there could be more than 1 solution, or no solution at all, as we have seen previously.

Computation time analysis A multiplication/division operation usually takes more time than add/subtraction. Order of magnitude analysis, no need for exact results.

(n-1)(n+1) (n-2)(n) (n-i)(n-i+2) 1: For each row, 1 division + n multiplication, and there are n-1 rows. Thus, total number of multiplication/division is: (n-1)(n+1) 2: For each row, 1 division + n-1 multiplication, and there are n-2 rows. Thus, total number of multiplication/division is: (n-2)(n) i: For each row, 1 division + n-i+1 multiplication, and there are n-i rows. Thus, total number of multiplication/division is: (n-i)(n-i+2) Total number of multiplication/division is:

Now consider a tridiagonal system Total number of multiplication/division (including the right hand side) is: 4(n-1), or O(n)

Key points Forward elimination: row operation that converts the coefficient matrix into an upper triangular matrix Back substitution: solves the unknowns from the last to the first (Partial) pivoting: reduce round-off error and avoid divide by zero error during forward elimination Tridiagonal systems: fast equations Computation time estimation: order of magnitude analysis.