
INTRODUCTION TO NUMERICAL ANALYSIS Cho, Hyoung Kyu Department of Nuclear Engineering Seoul National University 4. A SYSTEM OF LINEAR EQUATIONS 4.1 Background 4.2 Gauss Elimination Method 4.3 Gauss Elimination with Pivoting 4.4 Gauss‐Jordan Elimination Method 4.5 LU Decomposition Method 4.6 Inverse of a Matrix 4.7 Iterative Methods 4.8 Use of MATLAB Built‐In Functions for Solving a System of Linear Equations 4.9 Tridiagonal Systems of Equations 4.1 Background Systems of linear equations Occur frequently not only in engineering and science but in any disciplines Example Electrical engineering . Kirchhoff’s law 4.1 Background Systems of linear equations Occur frequently not only in engineering and science but in any disciplines Example Force in members of a truss . Force balance 4.1 Background Overview of numerical methods for solving a system of linear algebraic equations Direct methods vs. iterative methods Direct methods . The solution is calculated by performing arithmetic operations with the equations. Three systems of equations that can be easily solved are the – Upper triangular – Lower triangular – Diagonal 4.1 Background Overview of numerical methods for solving a system of linear algebraic equations Direct methods . Upper triangular form – Back substitution – Ex) 4 equations – In general 4.1 Background Overview of numerical methods for solving a system of linear algebraic equations Direct methods . Lower triangular form – Forward substitution – Ex) 4 equations – In general 4.1 Background Overview of numerical methods for solving a system of linear algebraic equations Direct methods . Diagonal form . LU decomposition method – Lower and upper triangular form . Gauss‐Jordan method – Diagonal form . Iterative methods – Jacobi – Gauss‐Seidel 4.2 Gauss Elimination Method Gauss elimination method A general form is manipulated to be in upper triangular form . Back substitution 4.2 Gauss Elimination Method Gauss elimination method A general form is manipulated to be in upper triangular form . Forward elimination . Step 1 – Eliminate in all other equations except the first one. – First equation: pivot equation – Coefficient : pivot coefficient 4.2 Gauss Elimination Method Gauss elimination method A general form is manipulated to be in upper triangular form . Forward elimination . Step 1 – Eliminate in all other equations except the first one. – First equation: pivot equation – Coefficient : pivot coefficient 4.2 Gauss Elimination Method Gauss elimination method A general form is manipulated to be in upper triangular form . Forward elimination . Step 1 – Eliminate in all other equations except the first one. – First equation: pivot equation – Coefficient : pivot coefficient 4.2 Gauss Elimination Method Gauss elimination method A general form is manipulated to be in upper triangular form . Forward elimination . Step 2 st nd – Eliminate in all other equations except the 1 and 2 ones. – Second equation: pivot equation – Coefficient : pivot coefficient 4.2 Gauss Elimination Method Gauss elimination method A general form is manipulated to be in upper triangular form . Forward elimination . Step 3 th – Eliminate in 4 equations – Third equation: pivot equation – Coefficient : pivot coefficient Back substitution ! 4.2 Gauss Elimination Method Gauss elimination method 4.2 Gauss Elimination Method Gauss elimination method . Answer 0.5 3 4 2 4.2 Gauss Elimination Method Gauss elimination method Matrix Back substitution ! 4.2 Gauss Elimination Method Gauss elimination method function x = Gauss(a,b) % The function solve a system of linear equations [a][x]=[b] using the Gauss % elimination method. % Input variables: % a The matrix of coefficients. % b A column vector of constants. % Output variable: % x A colum vector with the solution. ab = [a,b]; Append the column vector [ b] to the matrix [a]. [R, C] = size(ab); for j = 1:R-1 for i = j+1:R ab(i,j:C) = ab(i,j:C)-ab(i,j)/ab(j,j)*ab(j,j:C); Forward elimination end end x = zeros(R,1); x(R) = ab(R,C)/ab(R,R); Back substitution for i = R-1:-1:1 x(i)=(ab(i,C)-ab(i,i+1:R)*x(i+1:R))/ab(i,i); end 4.2 Gauss Elimination Method Gauss elimination method ab(i,j:C) = ab(i,j:C)-ab(i,j)/ab(j,j)*ab(j,j:C); 2: pivot equation 1~ 1 3 1~ 0 0 1~ 0 4.2 Gauss Elimination Method Gauss elimination method x(i)=(ab(i,C)-ab(i,i+1:R)*x(i+1:R))/ab(i,i); 4.2 Gauss Elimination Method Gauss elimination method 4.2 Gauss Elimination Method Potential difficulties when applying the Gauss elimination method The pivot element is zero. Pivot row is divided by the pivot element. Pivoting! . If the value of the pivot element is equal to zero, a problem will arise. The pivot element is small relative to the other terms in the pivot row. Problem can be easily remedied by exchanging the order of the two equations. In general, a more accurate solution is obtained when the equations are arranged (and rearranged every time a new pivot equation is used) such that the pivot equation has the largest possible pivot element. Round‐off errors can also be significant when solving large systems of equations even when all the coefficients in the pivot row are of the same order of magnitude. This can be caused by a large number of operations (multiplication, division, addition, and subtraction) associated with large systems. 4.2 Gauss Elimination Method Potential difficulties when applying the Gauss elimination method 4.2 Gauss Elimination Method Potential difficulties when applying the Gauss elimination method Remedy 4.3 Gauss Elimination with Pivoting Example First pivot coefficient: 0 Pivoting Exchange of rows 4.3 Gauss Elimination with Pivoting Additional comments The numerical calculations are less prone to error and will have fewer round‐off errors if the pivot element has a larger numerical absolute value compared to the other elements in the same row. Consequently, among all the equations that can be exchanged to be the pivot equation, it is better to select the equation whose pivot element has the largest absolute numerical value. Moreover, it is good to employ pivoting for the purpose of having a pivot equation with the pivot element that has a largest absolute numerical value at all times (even when pivoting is not necessary). Partial pivoting 4.3 Gauss Elimination with Pivoting Additional comments The numerical calculations are less prone to error and will have fewer round‐off errors if the pivot element has a larger numerical absolute value compared to the other elements in the same row. Consequently, among all the equations that can be exchanged to be the pivot equation, it is better to select the equation whose pivot element has the largest absolute numerical value. Moreover, it is good to employ pivoting for the purpose of having a pivot equation with the pivot element that has a largest absolute numerical value at all times (even when pivoting is not necessary). Full pivoting 4.3 Gauss Elimination with Pivoting Example 4‐3 4.3 Gauss Elimination with Pivoting Example 4‐3 function x = GaussPivot(a,b) % The function solve a system of linear equations ax=b using the Gauss % elimination method with pivoting. % Input variables: % a The matrix of coefficients. % b A column vector of constants. % Output variable: % x A colum vector with the solution. ab = [a,b] [R, C] = size(ab); for j = 1:R-1 % Pivoting section starts if ab(j,j)==0 Check if the pivot element is zero. for k=j+1:R If pivoting is required, search in the rows if ab(k,j)~=0 below for a row with nonzero pivot element. 1 abTemp=ab(j,:); ab(j,:)=ab(k,:); Swap ab(k,:)=abTemp; break end end end % Pivoting section ends for i = j+1:R ab(i,j:C) = ab(i,j:C)-ab(i,j)/ab(j,j)*ab(j,j:C); Forward elimination end end 4.3 Gauss Elimination with Pivoting Example 4‐3 x = zeros(R,1); x(R) = ab(R,C)/ab(R,R); Back substitution for i = R-1:-1:1 x(i)=(ab(i,C)-ab(i,i+1:R)*x(i+1:R))/ab(i,i); end Result 4.4 Gauss‐Jordan Elimination Method Gauss‐Jordan Elimination Result In this procedure, a system of equations that is given in a general form is manipulated into an equivalent system of equations in diagonal form with normalized elements along the diagonal. 4.4 Gauss‐Jordan Elimination Method Procedure In this procedure, a system of equations that is given in a general form is manipulated into an equivalent system of equations in diagonal form with normalized elements along the diagonal. The pivot equation is normalized by dividing all the terms in the equation by the pivot coefficient. This makes the pivot coefficient equal to 1. The pivot equation is used to eliminate the off‐diagonal terms in ALL the other equations. This means that the elimination process is applied to the equations (rows) that are above and below the pivot equation. In the Gaussian elimination method, only elements that are below the pivot element are eliminated. 4.4 Gauss‐Jordan Elimination Method Procedure The Gauss‐Jordan method can also be used for solving several systems of equations that have the same coefficients but different right‐hand‐side vectors . This is done by augmenting the matrix to include all of the vectors . The method is used in this way for calculating the inverse of a matrix. 4.4 Gauss‐Jordan Elimination Method Procedure Pivot coefficient is normalized! First elements in rows 2, 3, 4 are eliminated. 4.4 Gauss‐Jordan Elimination Method Procedure The second pivot coefficient is normalized! The second elements in rows 1, 3, 4 are eliminated.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages93 Page
-
File Size-