Presentation is loading. Please wait.

Presentation is loading. Please wait.

Choi, Jong-In Lee, Ho-Keun Shim, Yoon-Sik

Similar presentations


Presentation on theme: "Choi, Jong-In Lee, Ho-Keun Shim, Yoon-Sik"— Presentation transcript:

1 Choi, Jong-In Lee, Ho-Keun Shim, Yoon-Sik
Chapter 3 SOLVING SYSTEMS OF LINEAR EQUATIONS Choi, Jong-In Lee, Ho-Keun Shim, Yoon-Sik

2 Chapter 3.1 GAUSSIAN ELIMINATION

3 EX 3.1 Three-by-Three System
Solving three equations in three unknowns

4 I 3.1.1 Using Matrix Notation Write in matrix-vector form : Ax = b
combine in the augmented matrix Basic Gaussian elimination procedure

5 II 3.1.1 Using Matrix Notation Pivot
At the kth stage of Gaussian elimination procedure, the appropriate multiple of the kth row is used to reduce each of the entries in the kth column below the kth row to zero kth row : pivot row kth column : pivot column element akk : pivot element ex : If at 3rd elimination procedure,

6 Ex 3.2 Circuit Analysis I The sum of the voltage drops around a closed loop is zero V=IR

7 II Ex 3.2 Circuit Analysis Step 1 The pivot is a11 = 30
Multiply the first row by 20/30 and add it to the second row Multiply the first row by 10/30 and add it to the third row

8 III Ex 3.2 Circuit Analysis Step 2 By back substitution,
The pivot is a22 = 125/3 Multiply the second row by 2/5 and add it to the third row to get By back substitution,

9 G.E. in MATLAB Function function x = Gauss( A , b )
% Gaussian Elimination function which can solve k systems of the form Ax=b1,....,Ax=bk at the same time function x = Gauss( A , b ) [n,k1] = size(A); [n1,k] = size(b); x = zeros(n,k); for i=1 : n-1 m = -A(i+1:n , i) / A(i,i); A(i+1:n , : ) = A(i+1:n , : ) + m*A(i,:); b(i+1:n , : ) = b(i+1:n , : ) + m*b(i,:); end x(n,:) = b(n,:) ./ A(n,n); for i=n-1 : -1 : 1 x(i,:) = ( b(i,:) - A(i , i+1:n) * x(i+1:n , : ) ) ./ A(i,i);

10 Using the MATLAB Function
Solving circuit analysis example % Actually using function : G.E. A = [ ]; b = [ 0 200 ]; x = Gauss(A,b); display(x); x = 3.0000 2.0000 5.0000 >> RUN

11 Ex 3.3 Forces on a Truss I node 3 # Assuming the forces in each truss are pulling together # Define forces to be positive if they - act to the right - act in an upward direction node 1 node 2

12 Ex 3.3 Forces on a Truss II Write in Ax=b form if :

13 Ex 3.3 Forces on a Truss III Let’s use MATLAB function that we made for two different W3

14 Ex 3.3 Forces on a Truss IV Let’s use MATLAB function that we made for two different W3 % Using G.E. function to Truss sa = sin(pi/6); ca = cos(pi/6); sb = sin(pi/3); cb = cos(pi/3); A = [ sa 0 ca 0 sb cb sa -sb ca cb ]; b = [ 0 0 100 75 0 0 ]; x = Gauss(A,b); display(x); x = >> RUN

15 I Discussion Measuring computational effort
Measure the number of multiplication and divisions A1,1 A1,2 A1,k-1 A1,k A1,k+1 A1,n A2,2 A2,k-1 A2,k A2,k+1 A2,n Ak-1,k-1 Ak-1,k Ak-1,k+1 Ak-1,n Ak,k Ak,k+1 Ak,n Ak+1,k Ak+1,k+1 Ak+1,n An,k An,k+1 An,n

16 II Discussion Measuring computational effort
Measure the number of multiplication and divisions The total number of multiplication and divisions

17 Discussion III An Ill-Conditioned matrix

18 GAUSSIAN ELIMINATION WITH ROW PIVOTING
Chapter 3.2 GAUSSIAN ELIMINATION WITH ROW PIVOTING

19 Introduction WHY HOW Reducing the inaccuracies
More accurate than Gaussian Elimination Avoiding (if possible) the failure Divide by zero HOW Pivoting!!

20 EX 3.4 Difficult System Rounding to two significant digits Result
Pivot Result

21 3.2.1 MATLAB Function for Gaussian Elimination with Row Pivoting

22 3.2.1 MATLAB Function for Gaussian Elimination with Row Pivoting
II function x = Gauss_pivot(A, b) [n, n1] = size(A); for i = 1 : (n - 1) [pivot, k] = max(abs(A(i : n, i))); if k > 1 temp1 = A(i, :); temp2 = b(i, :); A(i, :) = A(i + k - 1, :); b(i, :) = b(i + k - 1, :); A(i + k - 1, :) = temp1; b(i + k - 1, :) = temp2; end;

23 3.2.1 MATLAB Function for Gaussian Elimination with Row Pivoting
III Cont’ for h = (i + 1) : n m = A(h, i) / A(i, i); A(h, :) = A(h, :) - m * A(i, :); b(h, :) = b(h, :) - m * b(i, :); end; x(n, :) = b(n, :) ./ A(n, n); for i = (n - 1) : -1 : 1 x(i, :) = (b(i, :) - A(i, (i + 1) : n) * x((i + 1) : n, :)) ./ A(i, i);

24 EX 3.6 Forces in a Simple Truss
Triangular Truss 100kg

25 EX 3.6 Forces in a Simple Truss
II Cont.

26 Discussion Big coefficients Scaling Result

27 GAUSSIAN ELIMINATION FOR TRIDIAGONAL SYSTEM
Chapter 3.3 GAUSSIAN ELIMINATION FOR TRIDIAGONAL SYSTEM

28 I Tridiagonal Systems * Introduction of Tridiagonal System?
Special Linear System Arising in Application A general tridiagonal matrix is a matrix whose nonzero elements are found only on the diagonal, subdiagonal, and superdiagonal of the matrix. if |i-j| > 1 , 28

29 II Tridiagonal Systems In Storage
Only the diagonal, subdiagonal, and superdiagonal elements of the general tridiagonal matrix are stored. This is called tridiagonal storage mode. The elements of a general tridiagonal matrix, A, of order n are stored in three one-dimensional arrays, C, D, and E, each of length n. array C contains the subdiagonal elements, stored as follows: C = (*, a21, a32, a43, ..., an,n-1) array D contains the main diagonal elements, stored as follows: D = (a11, a22, a33, ..., ann) array E contains the superdiagonal elements, stored as follows: E = (a12, a23, a34, ..., an-1,n, *) where "*" means you do not store an element in that position in the array 29

30 III Tridiagonal Systems * Example of Tridiagonal Matrix… 2x1 –x2 = 1,
30

31 Gaussian Elimination for Tridiagonal Systems
* Example 3.7

32 Solving a Tridiagonal Systems Using the Thomas Method
B1 and An are zero. This algorithm takes advantage of the zero elements that are already present in the coefficient matrix and avoids unnecessary arithmetic operations. Thus, we need to store only the new vectors a and r. 32

33 Solving a Tridiagonal Systems Using the Thomas Method
II Step 1 : For the first equation Step 2 : For each of the equation Step 3 : For the last equation Step 4 : by back substitution

34 Solving a Tridiagonal Systems Using the Thomas Method
III * Example 3.8.q

35 Solving a Tridiagonal Systems Using the Thomas Method
IV * Example 3.8.s

36 MATLAB Function for Solving a Tridiagonal Systems
Function x=Thomas(a,d,b,r) N=length(d) A(1)=a(1)/d(1) R(1)=r(1)/d(1) For i=2 : n-1 Denom=d(i)-b(i)*a(i-1); If(denom==0), error(‘zero in denominator’), end A(i)=a(i)/denom; R(i)=(r(i)-b(i)*r(n-1))/denom; End R(n)=(r(n)-b(n)*r(n-1))/(d(n)-b(n)*a(n-1)); X(n)=r(n); For i=n-1 : -1 :1 X(i)=r(i)-a(i)*x(i+1);

37 Discussion of Thomas method
* The required multiplications and divisions for Thomas method. For the first equation, 2divisions are needed. For each of the next n-2 equations, 2multiplications and 2 divisions are needed. For the last equation, 2 multiplications and 1 division are required. The total for elimination is 5+4(n-2). For the back substitution, n-1 multiplications are needed.

38 Using the Thomas Method for a System that Would Require Pivoting for Gaussian Elimination
* Example 3.9

39 Using the Thomas Method for a System that Would Require Pivoting for Gaussian Elimination
II Example 3.9

40 Using the Thomas Method for a System that Would Require Pivoting for Gaussian Elimination
III * Example 3.9.s-3


Download ppt "Choi, Jong-In Lee, Ho-Keun Shim, Yoon-Sik"

Similar presentations


Ads by Google