Presentation is loading. Please wait.

Presentation is loading. Please wait.

MECN 3500 Inter - Bayamon Lecture 7 Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar E. Meza Castillo

Similar presentations


Presentation on theme: "MECN 3500 Inter - Bayamon Lecture 7 Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar E. Meza Castillo"— Presentation transcript:

1 MECN 3500 Inter - Bayamon Lecture 7 Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar E. Meza Castillo omeza@bayamon.inter.edu http://www.bc.inter.edu/facultad/omeza Department of Mechanical Engineering Inter American University of Puerto Rico Bayamon Campus

2 Lecture 7 MECN 3500 Inter - Bayamon 2 Tentative Lectures Schedule TopicLecture Mathematical Modeling and Engineering Problem Solving 1 Introduction to Matlab 2 Numerical Error 3 Root Finding 4-5-6 System of Linear Equations 7 Least Square Curve Fitting Polynomial Interpolation Numerical Integration Ordinary Differential Equations

3 Lecture 7 MECN 3500 Inter - Bayamon Gauss Elimination Linear Algebraic Equations 3

4 Lecture 7 MECN 3500 Inter - Bayamon  To solve linear algebraic equations using the technique Gauss Elimination. 4 Course Objectives

5 Lecture 7 MECN 3500 Inter - Bayamon An equation of the form ax+by+c=0 or equivalently ax+by=-c is called a linear equation in x and y variables. 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 is a linear equation in three variables, x, y, and z. ax+by+cz=d is a linear equation in three variables, x, y, and z. Thus, a linear equation in n variables is Thus, a linear equation in n variables is a 1 x 1 +a 2 x 2 + … +a n x n = b A solution of such an equation consists of real numbers c 1, c 2, c 3, …, c n. If you need to work more than one linear equations, a system of linear equations must be solved simultaneously. A solution of such an equation consists of real numbers c 1, c 2, c 3, …, c n. If you need to work more than one linear equations, a system of linear equations must be solved simultaneously. 5 Introduction

6 Lecture 7 MECN 3500 Inter - Bayamon For small number of equations (n ≤ 3) linear equations can be solved readily by simple techniques such as “method of elimination.” For small number of equations (n ≤ 3) linear equations can be solved readily by simple techniques such as “method of elimination.” Linear algebra provides the tools to solve such systems of linear equations. Linear algebra provides the tools to solve such systems of linear equations. Nowadays, easy access to computers makes the solution of large sets of linear algebraic equations possible and practical. Nowadays, easy access to computers makes the solution of large sets of linear algebraic equations possible and practical. 6 Solving Small Number of Equations

7 Lecture 7 MECN 3500 Inter - Bayamon There are many ways to solve a system of linear equations: There are many ways to solve a system of linear equations:  Graphical method  Cramer’s rule  Method of elimination  Computer methods. 7 Solving Small Number of Equations

8 Lecture 7 MECN 3500 Inter - Bayamon 8 The Graphical Method  For two equations:  Solve both equations for x 2:

9 Lecture 7 MECN 3500 Inter - Bayamon 9 The Graphical Method  Or equate and solve for x 1

10 Lecture 7 MECN 3500 Inter - Bayamon 10 The Graphical Method Ill-conditioned (Slopes are too close) No solutionInfinite solutions

11 Lecture 7 MECN 3500 Inter - Bayamon 11

12 Lecture 7 MECN 3500 Inter - Bayamon 2x 1 – x 2 = 3 x 1 + x 2 = 3 One solution The Graphical Method 12

13 Lecture 7 MECN 3500 Inter - Bayamon 2x 1 – x 2 = 3 2x 1 – x 2 = – 1 No solution The Graphical Method 13

14 Lecture 7 MECN 3500 Inter - Bayamon 6x 1 – 3x 2 = 9 2x 1 – x 2 = 3 Infinite solutions The Graphical Method 14

15 Lecture 7 MECN 3500 Inter - Bayamon 2x 1 – x 2 = 3 2.1x 1 – x 2 = 3 Ill conditioned The Graphical Method 15

16 Lecture 7 MECN 3500 Inter - Bayamon Cramer’s Rule  Compute the determinant D  2 x 2 matrix  3 x 3 matrix 16

17 Lecture 7 MECN 3500 Inter - Bayamon Cramer’s Rule  To find x k for the following system  Replace k th column of as with bs (i.e., a ik  b i ) 17

18 Lecture 7 MECN 3500 Inter - Bayamon Cramer’s Rule  3 x 3 matrix 18

19 Lecture 7 MECN 3500 Inter - Bayamon 19

20 Lecture 7 MECN 3500 Inter - Bayamon Example 9.3 20

21 Lecture 7 MECN 3500 Inter - Bayamon Eliminate x 2  Subtract to get Elimination Method Not very practical for large number (> 4) of equations 21

22 Lecture 7 MECN 3500 Inter - Bayamon Example 9.3  2 x 2 matrix 22

23 Lecture 7 MECN 3500 Inter - Bayamon The system can be written in a matrix format as NAVIE GAUSS Elimination  Gauss elimination is the most important algorithm to solve systems of linear equations.  It involves by combining equations to eliminate unknowns. It involves 2 phases: 1.Forward elimination phase: reduce the set of equations to an upper triangular system. 2.Back substitution: work from the last equation up. 23

24 Lecture 7 MECN 3500 Inter - Bayamon  In the first step of the forward elimination phase, x 1 is eliminated from all equations except the first one.  The coefficient of x 1 in the first equation is called the pivot element.  The second step is to eliminate x 2 from the third equation through the n th equation.  Do the same for all variables x 3 to x n-1.  The goal is to set up upper triangular matrix  The back-substitution phase starts from the last equation up, to find the values of x 1, x 2, …, x n. NAVIE GAUSS Elimination 24

25 Lecture 7 MECN 3500 Inter - Bayamon Gauss Elimination Pseudocode Forward elimination phase Back substitution NAVIE GAUSS Elimination 25

26 Lecture 7 MECN 3500 Inter - Bayamon Use Gauss elimination to solve Carry 6 significant figures. Solution 1. Forward elimination: eliminate x 1 from equation (2):  - (0.1/3)    NAVIE GAUSS Elimination 26

27 Lecture 7 MECN 3500 Inter - Bayamon NAVIE GAUSS Elimination 27 Eliminate x 1 from equation (3): - (0.3/3)   After eliminating x 1 from equations (2) and (3), the system becomes Eliminate x 2 from equation (3): + (0.190000/7.00333)   After eliminating x 2 from equation (3), the system becomes

28 Lecture 7 MECN 3500 Inter - Bayamon NAVIE GAUSS Elimination 28 2. Back Substitution: find the value of x 3 from equation (3): Substitute the value of x 3 in equation (2) to find the value of x 2 : Substitute the values of x 2 and x 3 in equation (1) to find the value of x 1 :

29 Lecture 7 MECN 3500 Inter - Bayamon Pitfalls of Elimination Methods  Division by zero (Partially solved by the pivoting technique)  Round-off errors (Important when large number of equation are to be solved)  Ill-conditioned systems: Small changes in coefficients result in large changes in the solution. When 29

30 Lecture 7 MECN 3500 Inter - Bayamon Techniques for Improving Solutions  Use of more significant figures (The simplest remedy)  Pivoting (Determine the largest available coefficient in the column below the pivot element and switch rows so that the largest element is the pivot element.) 30

31 Lecture 7 MECN 3500 Inter - Bayamon Techniques for Improving Solutions Scaling (Divide each row by the largest element in that row) Scaling (Divide each row by the largest element in that row) Without Scaling: With Scaling: With Scaling and Pivoting: 31

32 Lecture 7 MECN 3500 Inter - Bayamon MATLAB Script File: NGaussElim.m 32

33 Lecture 7 MECN 3500 Inter - Bayamon 33

34 Lecture 7 MECN 3500 Inter - Bayamon >>Enter Matrix A > [3 -0.1 -0.2; 0.1 7 -0.3; 0.3 -0.2 10] A = 3.0000 -0.1000 -0.2000 0.1000 7.0000 -0.3000 0.3000 -0.2000 10.0000 >>Enter Solution Vector B > [7.85 -19.3 71.4] B = 7.8500 -19.3000 71.4000 S = 3.0000 -2.5000 7.0000 >>Enter Matrix A > [3 -0.1 -0.2; 0.1 7 -0.3; 0.3 -0.2 10] A = 3.0000 -0.1000 -0.2000 0.1000 7.0000 -0.3000 0.3000 -0.2000 10.0000 >>Enter Solution Vector B > [7.85 -19.3 71.4] B = 7.8500 -19.3000 71.4000 S = 3.0000 -2.5000 7.0000 34 Example 9.5

35 Lecture 7 MECN 3500 Inter - Bayamon MATLAB Script File: GaussElimPPivot.m 35

36 Lecture 7 MECN 3500 Inter - Bayamon >>Enter Matrix A > [1 0 2 3; -1 2 2 -3; 0 1 1 4; 6 2 2 4] A = 1 0 2 3 -1 2 2 -3 0 1 1 4 6 2 2 4 >>Enter Solution Vector B > [1 -1 2 1] B = 1 -1 2 1 S = -0.1857 0.2286 -0.1143 0.4714 >>Enter Matrix A > [1 0 2 3; -1 2 2 -3; 0 1 1 4; 6 2 2 4] A = 1 0 2 3 -1 2 2 -3 0 1 1 4 6 2 2 4 >>Enter Solution Vector B > [1 -1 2 1] B = 1 -1 2 1 S = -0.1857 0.2286 -0.1143 0.4714 Example 36

37 Lecture 7 MECN 3500 Inter - Bayamon  It is a variation of Gauss elimination. Both methods use row operations to eliminate variables  The major difference is that what an unknown is eliminated, it is eliminated from all other equations.  Also, all rows (equations) are normalized by dividing by their pivot elements.  The elimination phase produces an identity matrix.  It does not involve the back substitution phase. GAUSS-JORDAN Method 37

38 Lecture 7 MECN 3500 Inter - Bayamon MATLAB Script File: GaussJordan.m 38

39 Lecture 7 MECN 3500 Inter - Bayamon 39

40 Lecture 7 MECN 3500 Inter - Bayamon >>Dame la matriz aumentada Cuantas filas tiene la matriz: 3 Cuantas columnas tiene la matriz: 4 fila : 1 columna : 1Numero de esta fila y columna: 3 fila : 2 columna : 1Numero de esta fila y columna: 0.1 fila : 3 columna : 1Numero de esta fila y columna: 0.3 … Continuar ingresando los valores de la matriz aumentada a = 3.0000 -0.1000 -0.2000 7.8500 0.1000 7.0000 -0.3000 -19.3000 0.3000 -0.2000 10.0000 71.4000 a = 1.0000 0 0 3.0000 0 1.0000 0 -2.5000 0 0 1.0000 7.0000 resultado >>Dame la matriz aumentada Cuantas filas tiene la matriz: 3 Cuantas columnas tiene la matriz: 4 fila : 1 columna : 1Numero de esta fila y columna: 3 fila : 2 columna : 1Numero de esta fila y columna: 0.1 fila : 3 columna : 1Numero de esta fila y columna: 0.3 … Continuar ingresando los valores de la matriz aumentada a = 3.0000 -0.1000 -0.2000 7.8500 0.1000 7.0000 -0.3000 -19.3000 0.3000 -0.2000 10.0000 71.4000 a = 1.0000 0 0 3.0000 0 1.0000 0 -2.5000 0 0 1.0000 7.0000 resultado Example 9.12 40

41 Lecture 7 MECN 3500 Inter - Bayamon MATLAB’s Methods To solve the system Enter the following commands >> A=[3 -.1 -.2;.1 7 -0.3;.3 -.2 10]; >> b=[7.85;-19.3;71.4]; >> inv(A)*b ans = 3.0000 -2.5000 7.0000 Enter the following commands >> A=[3 -.1 -.2;.1 7 -0.3;.3 -.2 10]; >> b=[7.85;-19.3;71.4]; >> inv(A)*b ans = 3.0000 -2.5000 7.0000 41

42 Lecture 7 MECN 3500 Inter - Bayamon Homework6  www.bc.inter.edu/facultad/omeza www.bc.inter.edu/facultad/omeza Omar E. Meza Castillo Ph.D. 42


Download ppt "MECN 3500 Inter - Bayamon Lecture 7 Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar E. Meza Castillo"

Similar presentations


Ads by Google