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

FINITE DIFFERENCESBest known numerical

method of approximation

Page 3: Computational Modeling for Engineering MECN 6040

FINITE DIFFERENCE FORMULATIONOF DIFFERENTIAL EQUATIONS

finite difference form of the first derivative

Taylor series expansion of the function f about the point x,

The smaller the x, the smaller the error, and thus the more accurate the approximation.

3

Page 4: Computational Modeling for Engineering MECN 6040

THE BIG QUESTION:

How good are the FD approximations?

This leads us to Taylor series....

4

Page 5: Computational Modeling for Engineering MECN 6040

▪ Numerical Methods express functions in an approximate fashion: The Taylor Series.

▪ What is a Taylor Series?Some examples of Taylor series which you must have seen

EXPASION OF TAYLOR SERIES

!6!4!2

1)cos(642 xxxx

!7!5!3

)sin(753 xxxxx

!3!2

132 xxxe x

5

Page 6: Computational Modeling for Engineering MECN 6040

▪ The general form of the Taylor series is given by

provided that all derivatives of f(x) are continuous and exist in the interval [x,x+h], where h=∆xWhat does this mean in plain English?

GENERAL TAYLOR SERIES

32

!3!2hxfhxfhxfxfhxf

As Archimedes would have said, “Give me the value of the function at a single point, and the value of all (first, second, and so on) its derivatives at that single point, and I can give you the value of the function at any other point”6

Page 7: Computational Modeling for Engineering MECN 6040

▪ Example: Find the value of f(6) given that f(4)=125, f’(4)=74, f’’(4)=30, f’’’(4)=6 and all other higher order derivatives of f(x) at x=4 are zero.

▪ Solution: x=4, x+h=6 h=6-x=2▪ Since the higher order derivatives are

zero,

!324

!22424424

32

fffff

!326

!22302741256

32

f

860148125 341

7

Page 8: Computational Modeling for Engineering MECN 6040

THE TAYLOR SERIES

▪ (xi+1-xi)= h step size (define first)▪ Reminder term, Rn, accounts for all terms

from (n+1) to infinity.

nn

ii

n

iiiiiii

Rxxnf

xxfxxxfxfxf

)(!

)(!2

))(()()(

1

)(

2111

)1()1(

)!1()(

n

n

n hnfR

8

Page 9: Computational Modeling for Engineering MECN 6040

▪ Zero-order approximation

▪ First-order approximation

▪ Second-order approximation

)x(f)x(f i1i

)xx)(x(f)x(f)x(f i1iii1i

2i1ii1iii1i )xx(

!2f)xx)(x(f)x(f)x(f

9

Page 10: Computational Modeling for Engineering MECN 6040

▪ Example: Taylor Series Approximation of a polynomial Use zero- through fourth-order Taylor Series approximation to approximate the function:

▪ From xi=0 with h=1. That is, predict the function’s value at xi+1=1

▪ f(0)=1.2▪ f(1)=0.2 - True value

2.1x25.0x5.0x15.0x1.0xf 234

10

Page 11: Computational Modeling for Engineering MECN 6040

▪ Zero-order approximation

▪ First-order approximation

0.12.12.0EionapproximatvalueTrueE

2.1)1(f2.1)0(fxfxf

t

t

i1i

75.095.02.0E

95.0)1(25.02.1h)0('f0f1f25.0)0('f

25.0x1x45.0x4.0)x('f

h)x('fxfxf

t

23i

ii1i

11

Page 12: Computational Modeling for Engineering MECN 6040

▪ Second-order approximation

12

25.045.02.0E

45.0121)1(25.02.1

!2h)0(''fh)0('f0f1f

1)0(''f1x9.0x2.1)x(''f

!2h)x(''fh)x('fxfxf

t

22

2i

2i

ii1i

12

Page 13: Computational Modeling for Engineering MECN 6040

▪ Third-order approximation

1.03.02.0E

3.0619.01

21)1(25.02.1

!3h)0('''f

!2h)0(''fh)0('f0f1f

9.0)0(''f9.0x4.2)x('''f

!3h)x('''f

!2h)x(''fh)x('fxfxf

t

32

32

i

3i

2i

ii1i

13

Page 14: Computational Modeling for Engineering MECN 6040

▪ Fourth-order approximation

02.02.0E

2.02414.2

619.01

21)1(25.02.1

!4h)0(f

!3h)0('''f

!2h)0(''fh)0('f0f1f

4.2)0(f

4.2)x(f!4h)x(f

!3h)x('''f

!2h)x(''fh)x('fxfxf

t

432

4iv32

iv

iiv

4i

iv3i

2i

ii1i

14

Page 15: Computational Modeling for Engineering MECN 6040

15

Page 16: Computational Modeling for Engineering MECN 6040

▪ If we truncate the series after the first derivative term

TAYLOR SERIES TO ESTIMATE TRUNCATION ERRORS

nn

i1i

)n(

2i1ii1iii1i

R)tt(!n

v

)tt(!2''v)tt)(t('v)t(v)t(v

1i1iii1i R)tt)(t('v)t(v)t(v

)tt(R

)tt()t(v)t(v)t('v

i1i

1

i1i

i1ii

First-order approximation

Truncation Error

)tt(O i1i

16

Page 17: Computational Modeling for Engineering MECN 6040

▪ Forward Difference Approximation

NUMERICAL DIFFERENTIATION

)xx(O)xx()x(f)x(f)x('f i1i

i1i

i1ii

17

Page 18: Computational Modeling for Engineering MECN 6040

• The Taylor series expansion of f(x) about xi is

• From this:

• This formula is called the first forward divided difference formula and the error is of order O(h).

hxfxf

xxxfxfxf

xxxfxfxf

ii

ii

iii

iiiii

)()()()()(

))(()()(

1

1

1

11

NUMERICAL DIFFERENTIATION

18

Page 19: Computational Modeling for Engineering MECN 6040

• Or equivalently, the Taylor series expansion of f(x) about xi can be written as

• From this:

• This formula is called the first backward divided difference formula and the error is of order O(h).

hxfxf

xxxfxfxf

xxxfxfxf

ii

ii

iii

iiiii

)()()()()(

))(()()(

1

1

1

11

19

Page 20: Computational Modeling for Engineering MECN 6040

• A third way to approximate the first derivative is to subtract the backward from the forward Taylor series expansions:

• This yields to

• This formula is called the centered divided difference formula and the error is of order O(h2).

hxfxfxf

hxfxfxf

hxfxfxf

hxfxfxf

iii

iii

iii

iii

2)()()(

)(2)()(_________________________)()()(

)()()(

11

11

1

1

20

Page 21: Computational Modeling for Engineering MECN 6040

▪ Forward Difference Approximation

NUMERICAL DIFFERENTIATION

)xx(O)xx()x(f)x(f)x('f i1i

i1i

i1ii

21

Page 22: Computational Modeling for Engineering MECN 6040

▪ Backward Difference Approximation

)h(Oh

)x(f)x(f)x('f 1iii

22

Page 23: Computational Modeling for Engineering MECN 6040

▪ Centered Difference Approximation

)h(Oh2

)x(f)x(f)x('f 21i1ii

23

Page 24: Computational Modeling for Engineering MECN 6040

▪ Example: To find the forward, backward and centered difference approximation for f(x) at x=0.5 using step size of h=0.5, repeat using h=0.25. The true value is -0.9125

▪ h=0.5▪ xi-1=0 - f(xi-1)=1.2▪ xi=0.5 - f(xi)=0.925▪ Xi+1=1 - f(xi+1)=0.2

25.0x1x45.0x4.0x'f

2.1x25.0x5.0x15.0x1.0xf23

234

24

Page 25: Computational Modeling for Engineering MECN 6040

▪ Forward Difference Approximation

▪ Backward Difference Approximation

%9.58

45.15.0925.02.0)()()5.0(' 1

t

ii

hxfxff

%7.39

55.05.0

2.1925.0)()()5.0(' 1

t

ii

hxfxff

25

Page 26: Computational Modeling for Engineering MECN 6040

▪ Centered Difference Approximation

%6.9

11

2.12.02

)()()5.0(' 11

t

ii

hxfxff

26

Page 27: Computational Modeling for Engineering MECN 6040

▪ h=0.25▪ xi-1=0.25 - f(xi-1)=1.10351563▪ xi=0.5 - f(xi)=0.925▪ Xi+1=0.75 - f(xi+1)=0.63632813

▪ Forward Difference Approximation

%5.26

155.125.0

925.063632813.0h

)x(f)x(f)5.0('f

t

i1i

27

Page 28: Computational Modeling for Engineering MECN 6040

▪ Backward Difference Approximation

▪ Centered Difference Approximation

%4.2

934.05.010351563.163632813.0

2)()()5.0(' 11

t

ii

hxfxff

%7.21

714.025.010351563.1925.0

h)x(f)x(f)5.0('f

t

1ii

28

Page 29: Computational Modeling for Engineering MECN 6040

• The forward Taylor series expansion for f(xi+2) in terms of f(xi) is

• Combine equations:

212

21

22

22

)()()(2)(

_______________________________________2

)()()()(2

)2(2

)()2)(()()(

)2(2

)()2)(()()(

hxfxfxfxf

hxfhxfxfxf

hxfhxfxfxf

hxfhxfxfxf

iiii

iiii

iiii

iiii

FINITE DIFFERENCE APPROXIMATION OF HIGHER DERIVATIVE

29

Page 30: Computational Modeling for Engineering MECN 6040

• Solve for f ''(xi):

• This formula is called the second forward finite divided difference and the error of order O(h).

• The second backward finite divided difference which has an error of order O(h) is

221

212

)()(2)()(

)()(2)()(

hxfxfxfxf

hxfxfxfxf

iiii

iiii

30

Page 31: Computational Modeling for Engineering MECN 6040

• The second centered finite divided difference which has an error of order O(h2) is

211 )()(2)()(

hxfxfxfxf iii

i

31

Page 32: Computational Modeling for Engineering MECN 6040

• High accurate estimates can be obtained by retaining more terms of the Taylor series.

hxfh

xfxfxf

hxfxxxfxfxf

iiii

iiiiii

2)('')()()(

2)(''))(()()(

1

211

• The forward Taylor series expansion is:

• From this, we can write

High-Accuracy Differentiation Formulas

32

Page 33: Computational Modeling for Engineering MECN 6040

• Substitute the second derivative approximation into the formula to yield:

• By collecting terms:

• Inclusion of the 2nd derivative term has improved the accuracy to O(h2).

• This is the forward divided difference formula for the first derivative.

hxfxfxfxf

hhxfxfxf

hxfxfxf

iiii

iii

iii

2)(3)(4)()(

2

)()(2)()()()(

12

212

1

33

Page 34: Computational Modeling for Engineering MECN 6040

Forward Formulas

34

Page 35: Computational Modeling for Engineering MECN 6040

Backward Formulas

35

Page 36: Computational Modeling for Engineering MECN 6040

Centered Formulas

36

Page 37: Computational Modeling for Engineering MECN 6040

ExampleEstimate f '(1) for f(x) = ex + x using the centered formula of O(h4) with h = 0.25.

Solution

5.15.01225.125.01

175.025.015.05.012

12)()(8)(8)()(

2

1

1

2

2112

hxxhxx

xhxxhxx

hxfxfxfxfxf

ii

ii

i

ii

ii

iiiii

•From Tables

37

Page 38: Computational Modeling for Engineering MECN 6040

717.33

)149.2()867.2(8)740.4(8982.5)25.0(12

)5.0()75.0(8)25.1(8)5.1()(

ffffxf i

•In substituting the values:

38

Page 39: Computational Modeling for Engineering MECN 6040

ERROR▪ Truncation Error: introduced in the

solution by the approximation of the derivative▪ Local Error: from each term of the

equation▪ Global Error: from the

accumulation of local error▪ Roundoff Error: introduced in the

computation by the finite number of digits used by the computer

39

Page 40: Computational Modeling for Engineering MECN 6040

▪ Numerical solutions can give answers at only discrete points in the domain, called grid points.

▪ If the PDEs are totally replaced by a system of algebraic equations which can be solved for the values of the flow-field variables at the discrete points only, in this sense, the original PDEs have been discretized. Moreover, this method of discretization is called the method of finite differences.40

INTRODUCTION TO FINITE DIFFERENCE

(i,j)

Page 41: Computational Modeling for Engineering MECN 6040

x

Discretization: PDE FDE

Explicit Methods Simple No stable

Implicit Methods More complex Stables

¬∆x®

xm-1 xm m+1

yn+1

yn

yn-1

∆ym,nu

Page 42: Computational Modeling for Engineering MECN 6040
Page 43: Computational Modeling for Engineering MECN 6040
Page 44: Computational Modeling for Engineering MECN 6040
Page 45: Computational Modeling for Engineering MECN 6040

SUMMARY OF NODAL FINITE-DIFFERENCE RELATIONS FOR VARIOUS

CONFIGURATIONS:Case 1: Interior Node

Page 46: Computational Modeling for Engineering MECN 6040

Case 2: Node at an Internal Corner with Convection

Page 47: Computational Modeling for Engineering MECN 6040

Case 3: Node at Plane Surface with Convection

Page 48: Computational Modeling for Engineering MECN 6040

Case 4: Node at an External Corner with Convection

Page 49: Computational Modeling for Engineering MECN 6040

Case 5: Node at Plane Surface with Uniform Heat Flux

Page 50: Computational Modeling for Engineering MECN 6040

SOLVING THE FINITE DIFFERENCE EQUATIONS

Heat Transfer Solved Problems

Page 51: Computational Modeling for Engineering MECN 6040

THE MATRIX INVERSION METHOD

Page 52: Computational Modeling for Engineering MECN 6040
Page 53: Computational Modeling for Engineering MECN 6040
Page 54: Computational Modeling for Engineering MECN 6040

JACOBI ITERATION METHOD

Page 55: Computational Modeling for Engineering MECN 6040
Page 56: Computational Modeling for Engineering MECN 6040
Page 57: Computational Modeling for Engineering MECN 6040
Page 58: Computational Modeling for Engineering MECN 6040
Page 59: Computational Modeling for Engineering MECN 6040
Page 60: Computational Modeling for Engineering MECN 6040

GAUSS-SEIDEL ITERATION

Page 61: Computational Modeling for Engineering MECN 6040
Page 62: Computational Modeling for Engineering MECN 6040
Page 63: Computational Modeling for Engineering MECN 6040

ERROR DEFINITIONS▪ Use absolute value.▪ Computations are repeated until stopping

criterion is satisfied.

▪ If the following Scarborough criterion is met

63

sa Pre-specified % tolerance based on the knowledge of

your solution

)%n)-(2s 10 (0.5

Page 64: Computational Modeling for Engineering MECN 6040

USIG EXCEL

64

=MINVERSE(A2:C4)

=MMULT(A7:C9,E2:E4)

Matrix Inversion Method

Page 65: Computational Modeling for Engineering MECN 6040

65

Jacobi Iteration Method using Excel

Page 66: Computational Modeling for Engineering MECN 6040

66

Gauss-Seidel Iteration Method using Excel

Page 67: Computational Modeling for Engineering MECN 6040

A large industrial furnace is supported on a long column of fireclay brick, which is 1 m by 1 m on a side. During steady-state operation is such that three surfaces of the column are maintained at 500 K while the remaining surface is exposed to 300 K. Using a grid of ∆x=∆y=0.25 m, determine the two-dimensional temperature distribution in the column.

Ts=300 K

(1,1) (2,1) (3,1)

(1,2) (2,2) (3,2)

(1,3) (2,3) (3,3)

Page 68: Computational Modeling for Engineering MECN 6040

T11 T12 T13 T21 T22 T23 T31 T32 T33

-4 1 0 1 0 0 0 0 0 T11 -8001 -4 1 0 1 0 0 0 0 T12 -500

0 1 -4 0 0 1 0 0 0 T13

-1000

1 0 0 -4 1 0 1 0 0 T21 -3000 1 0 1 -4 1 0 1 0 T22 = 00 0 1 0 1 -4 0 0 1 T23 -5000 0 0 1 0 0 -4 1 0 T31 -8000 0 0 0 1 0 1 -4 1 T32 -500

0 0 0 0 0 1 0 1 -4 T33

-1000System of Linear Equations

Page 69: Computational Modeling for Engineering MECN 6040

69

Matrix Inversion Method

Page 70: Computational Modeling for Engineering MECN 6040

70

Iteration Method using Excel

Page 71: Computational Modeling for Engineering MECN 6040

71

Jacobi Iteration Method using Excel

Page 72: Computational Modeling for Engineering MECN 6040

72

Error Iteration Method using Excel

Page 73: Computational Modeling for Engineering MECN 6040

73

Gauss-Seidel Iteration Method using Excel

Page 74: Computational Modeling for Engineering MECN 6040

74

Error Iteration Method using Excel

Page 75: Computational Modeling for Engineering MECN 6040
Page 76: Computational Modeling for Engineering MECN 6040
Page 77: Computational Modeling for Engineering MECN 6040
Page 78: Computational Modeling for Engineering MECN 6040

78

Iteration Method using Excel

Page 79: Computational Modeling for Engineering MECN 6040
Page 80: Computational Modeling for Engineering MECN 6040

Top Related