computational modeling for engineering mecn 6040

38
COMPUTATIONAL MODELING FOR ENGINEERING MECN 6040 Professor: Dr. Omar E. Meza Castillo [email protected] http://facultad.bayamon.inter.edu/omeza Department of Mechanical Engineering

Upload: angus

Post on 06-Feb-2016

59 views

Category:

Documents


0 download

DESCRIPTION

Computational Modeling for Engineering MECN 6040. Professor: Dr. Omar E. Meza Castillo [email protected] http://facultad.bayamon.inter.edu/omeza Department of Mechanical Engineering. Implementation of SOLUTION methods. Gaussian elimination, LU factorization, and others. Introduction. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Computational Modeling for Engineering MECN 6040

COMPUTATIONAL MODELING FOR ENGINEERINGMECN 6040

Professor: Dr. Omar E. Meza [email protected]

http://facultad.bayamon.inter.edu/omezaDepartment of Mechanical Engineering

Page 2: Computational Modeling for Engineering MECN 6040

IMPLEMENTATION OF SOLUTION METHODSGaussian elimination, LU factorization, and others

Page 3: Computational Modeling for Engineering MECN 6040

▪ 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.

▪ Thus, a linear equation in n variables is

a1x1+a2x2+ … +anxn = b

▪ A solution of such an equation consists of real numbers c1, c2, c3, … , cn. If you need to work more than one linear equations, a system of linear equations must be solved simultaneously.3

INTRODUCTION

Page 4: Computational Modeling for Engineering MECN 6040

▪ 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.

▪ Nowadays, easy access to computers makes the solution of large sets of linear algebraic equations possible and practical.

4

SOLVING SMALL NUMBER OF EQUATIONS

Page 5: Computational Modeling for Engineering MECN 6040

▪ There are many ways to solve a system of linear equations:▪ Graphical method▪ Cramer’s rule▪ Method of elimination▪ Computer methods.

5

SOLVING SMALL NUMBER OF EQUATIONS

Page 6: Computational Modeling for Engineering MECN 6040

6

THE GRAPHICAL METHOD

For two equations:

Solve both equations for x2:

2222121

1212111

bxaxa

bxaxa

22

21

22

212

1212

11

12

112 intercept(slope)

a

bx

a

ax

xxa

bx

a

ax

Page 7: Computational Modeling for Engineering MECN 6040

7

THE GRAPHICAL METHOD

Or equate and solve for x1

12

11

22

21

12

1

22

2

12

11

22

21

22

2

12

1

1

22

2

12

11

12

11

22

21

22

21

22

21

12

11

12

112

0

aa

aa

ab

ab

aa

aa

ab

ab

x

a

b

a

bx

a

a

a

a

a

bx

a

a

a

bx

a

ax

Page 8: Computational Modeling for Engineering MECN 6040

8

THE GRAPHICAL METHOD

Ill-conditioned(Slopes are too close)

No solution Infinite solutions

Page 9: Computational Modeling for Engineering MECN 6040

9

Page 10: Computational Modeling for Engineering MECN 6040

12

12

21

21

x3x3x2x

rearrange 3xx

3xx2

2x1 – x2 = 3x1 + x2 = 3

One solution

THE GRAPHICAL METHOD

10

Page 11: Computational Modeling for Engineering MECN 6040

2x1 – x2 = 3

2x1 – x2 = – 1

No solution

THE GRAPHICAL METHOD

11

Page 12: Computational Modeling for Engineering MECN 6040

6x1 – 3x2 = 92x1 – x2 = 3

Infinite solutions

THE GRAPHICAL METHOD

12

Page 13: Computational Modeling for Engineering MECN 6040

CRAMER’S RULE▪ Compute the determinant D

▪ 2 x 2 matrix

▪ 3 x 3 matrix

211222112221

1211 aaaaaa

aaD

3231

222113

3331

232112

3332

232211

333231

232221

131211

aa

aaa

aa

aaa

aa

aaa

aaa

aaa

aaa

D

13

Page 14: Computational Modeling for Engineering MECN 6040

CRAMER’S RULE▪ To find xk for the following system

▪ Replace kth column of as with bs (i.e., aik bi )14

nnnnnn

nn

nn

bxaxaxa

bxaxaxa

bxaxaxa

...

...

...

2211

22222121

11212111

)

)(

ijk D(a

matrix newDx

Page 15: Computational Modeling for Engineering MECN 6040

CRAMER’S RULE▪ 3 x 3 matrix

333231

232221

131211

aaa

aaa

aaa

D

33231

22221

11211

33

33331

23221

13111

22

33323

23222

13121

11

1

1

1

baa

baa

baa

DD

Dx

aba

aba

aba

DD

Dx

aab

aab

aab

DD

Dx

15

Page 16: Computational Modeling for Engineering MECN 6040

16

Page 17: Computational Modeling for Engineering MECN 6040

EXAMPLE 9.3

44.05.03.01.0

67.09.15.0

01.052.03.0

321

321

321

xxx

xxx

xxx

5.03.01.0

9.115.0

152.03.0

D

8.19

44.03.01.0

67.015.0

01.052.03.01

5.29

5.044.01.0

9.167.05.0

101.03.01

9.14

5.03.044.0

9.1167.0

152.001.01

33

22

11

DD

Dx

DD

Dx

DD

Dx

17

Page 18: Computational Modeling for Engineering MECN 6040

Eliminate x2

Subtract to get

2222121

1212111

bxaxa

bxaxa

2122221212112

1222122211122

baxaaxaa

baxaaxaa

21122211

1212112

21121122

2121221

2121221211211122

aaaa

babax

aaaa

babax

babaxaaxaa

ELIMINATION METHOD

Not very practical for large number (> 4) of equations

18

Page 19: Computational Modeling for Engineering MECN 6040

▪ 2 x 2 matrix

3)1(2)2(3

)18)(1()2(3

4)1(2)2(3

)2(2)18(2

2

1

x

x

22

1823

21

21

xx

xx

19

Page 20: Computational Modeling for Engineering MECN 6040

nnnnnn

n

n

b

b

b

x

x

x

aaa

aaa

aaa

2

1

2

1

21

22221

11211

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.20

Page 21: Computational Modeling for Engineering MECN 6040

In the first step of the forward elimination phase, x1 is eliminated from all equations except the first one.

The coefficient of x1 in the first equation is called the pivot element.

The second step is to eliminate x2 from the third equation through the nth equation.

Do the same for all variables x3 to xn-

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 x1, x2, …, xn.

NAVIE GAUSS ELIMINATION

21

Page 22: Computational Modeling for Engineering MECN 6040

Gauss Elimination Pseudocode

Forward elimination phase

Back substitution

NAVIE GAUSS ELIMINATION

22

Page 23: Computational Modeling for Engineering MECN 6040

Use Gauss elimination to solve

Carry 6 significant figuresSolution

1. Forward elimination: eliminate x1 from equation (2):

- (0.1/3)

5617.19293333.000333.7

3.193.071.0

261667.000666667.000333333.01.0

32

321

321

xx

xxx

xxx

23

NAVIE GAUSS ELIMINATION

Page 24: Computational Modeling for Engineering MECN 6040

24

Eliminate x1 from equation (3): - (0.3/3)

After eliminating x1 from equations (2) and (3), the system becomes

Eliminate x2 from equation (3):

+ (0.190000/7.00333)

After eliminating x2 from equation (3), the system becomes

Page 25: Computational Modeling for Engineering MECN 6040

25

2. Back Substitution: find the value of x3 from equation (3):

Substitute the value of x3 in equation (2) to find the value of x2:

Substitute the values of x2 and x3 in equation (1) to find the value of x1:

0000.70120.10

0843.703 x

50000.200333.7

)0000.7(293333.05617.19

5617.19)0000.7(293333.000333.7

2

2

x

x

00000.33

)0000.7(2.0)50000.2(1.085.7

85.7)0000.7(2.0)50000.2(1.03

1

1

x

x

Page 26: Computational Modeling for Engineering MECN 6040

0det AD

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

26

Page 27: Computational Modeling for Engineering MECN 6040

0000.10000.10000.1

0001.20000.30003.0

21

21

xx

xx

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)

27

Page 28: Computational Modeling for Engineering MECN 6040

TECHNIQUES FOR IMPROVING SOLUTIONS

▪ Scaling (Divide each row by the largest element in that row)

2

000,100000,1002

21

21

xx

xxWithout Scaling:

With Scaling:

2

100002.0

21

21

xx

xx

With Scaling and Pivoting:

100002.0

2

21

21

xx

xx

28

Page 29: Computational Modeling for Engineering MECN 6040

MATLAB SCRIPT FILE: NGAUSSELIM.M

29

Page 30: Computational Modeling for Engineering MECN 6040

30

Page 31: Computational Modeling for Engineering MECN 6040

>>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

31

Example 9.5

Page 32: Computational Modeling for Engineering MECN 6040

MATLAB SCRIPT FILE: GAUSSELIMPPIVOT.M

32

Page 33: Computational Modeling for Engineering MECN 6040

>>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 1S = -0.1857 0.2286 -0.1143 0.4714

14226

24110

13221

13201

4321

4321

4321

4321

xxxx

xxxx

xxxx

xxxx

Example

33

Page 34: Computational Modeling for Engineering MECN 6040

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

34

Page 35: Computational Modeling for Engineering MECN 6040

MATLAB SCRIPT FILE: GAUSSJORDAN.M

35

Page 36: Computational Modeling for Engineering MECN 6040

36

Page 37: Computational Modeling for Engineering MECN 6040

>>Dame la matriz aumentada

Cuantas filas tiene la matriz: 3Cuantas columnas tiene la matriz: 4fila : 1columna : 1Numero de esta fila y columna: 3fila : 2columna : 1Numero de esta fila y columna: 0.1fila : 3columna : 1Numero de esta fila y columna: 0.3 … Continuar ingresando los valores de la matriz aumentadaa = 3.0000 -0.1000 -0.2000 7.8500 0.1000 7.0000 -0.3000 -19.3000 0.3000 -0.2000 10.0000 71.4000a = 1.0000 0 0 3.0000 0 1.0000 0 -2.5000 0 0 1.0000 7.0000

resultado

71.4 10.0 0.2- 0.3

19.3- 0.3- 7.0 0.1

7.85 0.2- 0.1- 3.0

Example 9.12

37

Page 38: Computational Modeling for Engineering MECN 6040

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

38