420 likes | 870 Views
Chapter 3. SOLVING SYSTEMS OF LINEAR EQUATIONS. Choi, Jong-In Lee, Ho-Keun Shim, Yoon-Sik. Chapter 3.1. GAUSSIAN ELIMINATION. EX 3.1 Three-by-Three System. Solving three equations in three unknowns. 3.1.1 Using Matrix Notation. I. Write in matrix-vector form : Ax = b.
E N D
Chapter 3 SOLVING SYSTEMS OF LINEAR EQUATIONS Choi, Jong-In Lee, Ho-Keun Shim, Yoon-Sik
Chapter 3.1 GAUSSIAN ELIMINATION
EX 3.1 Three-by-Three System • Solving three equations in three unknowns
3.1.1 Using Matrix Notation I • Write in matrix-vector form : Ax = b combine in the augmented matrix • Basic Gaussian elimination procedure
3.1.1 Using Matrix Notation II • 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,
Ex 3.2 Circuit Analysis I • The sum of the voltage drops around a closed loop is zero • V=IR
Ex 3.2 Circuit Analysis II • 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
Ex 3.2 Circuit Analysis III • Step 2 • 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,
G.E. in MATLAB Function % 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); end
Using the MATLAB Function • Solving circuit analysis example % Actually using function : G.E. A = [ 30 -20 -10 -20 55 -10 -10 -10 50 ]; b = [ 0 0 200 ]; x = Gauss(A,b); display(x); x = 3.0000 2.0000 5.0000 >> RUN
Ex 3.3 Forces on a Truss I node 3 node 1 • # 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 2
Ex 3.3 Forces on a Truss II • Write in Ax=b form • if :
Ex 3.3 Forces on a Truss III • Let’s use MATLAB function that we made for two different W3
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 = [ 1 0 0 0 sa 0 0 1 0 1 ca 0 0 0 1 0 0 sb 0 0 0 -1 0 -cb 0 0 0 0 -sa -sb 0 0 0 0 -ca cb ]; b = [ 0 0 0 0 0 0 0 0 100 75 0 0 ]; x = Gauss(A,b); display(x); x = 25.0000 18.7500 0 0 75.0000 56.2500 43.3013 32.4760 -50.0000 -37.5000 -86.6025 -64.9519 >> RUN
Discussion I • Measuring computational effort • Measure the number of multiplication and divisions
Discussion II • Measuring computational effort • Measure the number of multiplication and divisions • The total number of multiplication and divisions
Discussion III • An Ill-Conditioned matrix
Chapter 3.2 GAUSSIAN ELIMINATION WITH ROW PIVOTING
Introduction • WHY • Reducing the inaccuracies • More accurate than Gaussian Elimination • Avoiding (if possible) the failure • Divide by zero • HOW • Pivoting!!
EX 3.4 Difficult System • Rounding to two significant digits Pivot Result
3.2.1 MATLAB Function for Gaussian Elimination with Row Pivoting I
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;
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; 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); end;
100kg EX 3.6 Forces in a Simple Truss I • Triangular Truss
EX 3.6 Forces in a Simple Truss II • Cont.
Discussion • Big coefficients Scaling Result
Chapter 3.3 GAUSSIAN ELIMINATION FOR TRIDIAGONAL SYSTEM
Tridiagonal Systems I * 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
Tridiagonal Systems II 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
Tridiagonal Systems III * Example of Tridiagonal Matrix… 2x1 –x2 = 1, -x1 +2x2 –x3 = 0, -x2 +2x3 –x4 = 0, -x3 +2x4 = 1. 30
Gaussian Eliminationfor Tridiagonal Systems * Example 3.7
Solving a Tridiagonal Systems Using the Thomas Method I • B1 and An are zero. • This algorithm takes advantage of the zero elements that are • alreadypresent in the coefficient matrix and avoids unnecessary arithmetic • operations. • Thus, we need to store only the new vectors a and r. 32
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
Solving a Tridiagonal Systems Using the Thomas Method III * Example 3.8.q
Solving a Tridiagonal Systems Using the Thomas Method IV * Example 3.8.s
MATLAB Functionfor 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); end
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.
Using the Thomas Method for a System that Would Require Pivoting for Gaussian Elimination I * Example 3.9
Using the Thomas Method for a System that Would Require Pivoting for Gaussian Elimination II • Example 3.9
Using the Thomas Method for a System that Would Require Pivoting for Gaussian Elimination III * Example 3.9.s-3