mecn 3500 lecture 4 numerical methods for engineering mecn 3500 professor: dr. omar e. meza castillo...

28
MECN 3500 MECN 3500 Lecture Lecture 4 4 Numerical Methods for Engineering Numerical Methods for Engineering MECN 3500 MECN 3500 Professor: Dr. Omar E. Meza Castillo Professor: Dr. Omar E. Meza Castillo [email protected] http://www.bc.inter.edu/facultad/omeza Department of Mechanical Engineering Department of Mechanical Engineering Inter American University of Puerto Rico Inter American University of Puerto Rico Bayamon Campus Bayamon Campus

Upload: milo-haynes

Post on 02-Jan-2016

234 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: MECN 3500 Lecture 4 Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar E. Meza Castillo omeza@bayamon.inter.edu

MEC

N 3

500

MEC

N 3

500

LectureLecture

44Numerical Methods for EngineeringNumerical Methods for Engineering

MECN 3500 MECN 3500

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

http://www.bc.inter.edu/facultad/omeza

Department of Mechanical EngineeringDepartment of Mechanical Engineering

Inter American University of Puerto RicoInter American University of Puerto Rico

Bayamon CampusBayamon Campus

Page 2: MECN 3500 Lecture 4 Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar E. Meza Castillo omeza@bayamon.inter.edu

Lecture 4Lecture 4MEC

N 3

500 I

nte

r -

Bayam

on

MEC

N 3

500 I

nte

r -

Bayam

on

22

Tentative Lectures ScheduleTentative Lectures Schedule

TopicTopic LectureLecture

Mathematical Modeling and Engineering Problem SolvingMathematical Modeling and Engineering Problem Solving 11

Introduction to MatlabIntroduction to Matlab 22

Numerical ErrorNumerical Error 33

Root FindingRoot Finding 33

System of Linear EquationsSystem of Linear Equations

Least Square Curve FittingLeast Square Curve Fitting

Polynomial Interpolation Polynomial Interpolation

Numerical IntegrationNumerical Integration

Ordinary Differential Equations Ordinary Differential Equations

Page 3: MECN 3500 Lecture 4 Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar E. Meza Castillo omeza@bayamon.inter.edu

Lecture 4Lecture 4MEC

N 3

500 I

nte

r -

Bayam

on

MEC

N 3

500 I

nte

r -

Bayam

on

Taylor TheoremTaylor Theorem

Truncation Errors and the Truncation Errors and the Taylor SeriesTaylor Series

33

Page 4: MECN 3500 Lecture 4 Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar E. Meza Castillo omeza@bayamon.inter.edu

Lecture 4Lecture 4MEC

N 3

500 I

nte

r -

Bayam

on

MEC

N 3

500 I

nte

r -

Bayam

on

To understand the use of Taylor Series in To understand the use of Taylor Series in the study of numerical methods.the study of numerical methods.

44

Course ObjectivesCourse Objectives

Page 5: MECN 3500 Lecture 4 Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar E. Meza Castillo omeza@bayamon.inter.edu

Lecture 4Lecture 4MEC

N 3

500 I

nte

r -

Bayam

on

MEC

N 3

500 I

nte

r -

Bayam

on

Truncation Errors: Truncation Errors: use approximation in use approximation in place of an exact mathematical procedure.place of an exact mathematical procedure.

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

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

55

IntroductionIntroduction

!6!4!2

1)cos(642 xxx

x

!7!5!3

)sin(753 xxx

xx

!3!2

132 xx

xe x

Page 6: MECN 3500 Lecture 4 Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar E. Meza Castillo omeza@bayamon.inter.edu

Lecture 4Lecture 4MEC

N 3

500 I

nte

r -

Bayam

on

MEC

N 3

500 I

nte

r -

Bayam

on

The general form of the Taylor series is The general form of the Taylor series is given bygiven by

provided that all derivatives of f(x) are provided that all derivatives of f(x) are continuous and exist in the interval [x,x+h] continuous and exist in the interval [x,x+h]

What does this mean in plain English?What does this mean in plain English?

66

General Taylor SeriesGeneral Taylor Series

32

!3!2h

xfh

xfhxfxfhxf

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” (fine print

excluded)

Page 7: MECN 3500 Lecture 4 Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar E. Meza Castillo omeza@bayamon.inter.edu

Lecture 4Lecture 4MEC

N 3

500 I

nte

r -

Bayam

on

MEC

N 3

500 I

nte

r -

Bayam

on

77

Page 8: MECN 3500 Lecture 4 Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar E. Meza Castillo omeza@bayamon.inter.edu

Lecture 4Lecture 4MEC

N 3

500 I

nte

r -

Bayam

on

MEC

N 3

500 I

nte

r -

Bayam

on

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

Solution: Solution: x=4, x+h=6 x=4, x+h=6 h=6-x=2 h=6-x=2

Since the higher order derivatives are zero,Since the higher order derivatives are zero,

88

General Taylor SeriesGeneral Taylor Series

!3

24

!2

2424424

32

fffff

!3

26

!2

2302741256

32

f

860148125 341

Page 9: MECN 3500 Lecture 4 Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar E. Meza Castillo omeza@bayamon.inter.edu

Lecture 4Lecture 4MEC

N 3

500 I

nte

r -

Bayam

on

MEC

N 3

500 I

nte

r -

Bayam

on The Taylor SeriesThe Taylor Series

(x(xi+1i+1-x-xii)= h)= h step sizestep size (define first) (define first)

Reminder term, RReminder term, Rnn, accounts for all terms , accounts for all terms from (n+1) to infinity.from (n+1) to infinity.

99

nn

ii

n

iiiiiii

Rxxn

f

xxf

xxxfxfxf

)(!

)(!2

))(()()(

1

)(

2111

)1()1(

)!1(

)(

n

n

n hn

fR

Page 10: MECN 3500 Lecture 4 Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar E. Meza Castillo omeza@bayamon.inter.edu

Lecture 4Lecture 4MEC

N 3

500 I

nte

r -

Bayam

on

MEC

N 3

500 I

nte

r -

Bayam

on The Taylor SeriesThe Taylor Series

Zero-order approximationZero-order approximation

First-order approximationFirst-order approximation

Second-order approximationSecond-order approximation

1010

)x(f)x(f i1i

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

2i1ii1iii1i )xx(

!2

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

Page 11: MECN 3500 Lecture 4 Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar E. Meza Castillo omeza@bayamon.inter.edu

Lecture 4Lecture 4MEC

N 3

500 I

nte

r -

Bayam

on

MEC

N 3

500 I

nte

r -

Bayam

on

1111

Page 12: MECN 3500 Lecture 4 Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar E. Meza Castillo omeza@bayamon.inter.edu

Lecture 4Lecture 4MEC

N 3

500 I

nte

r -

Bayam

on

MEC

N 3

500 I

nte

r -

Bayam

on

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

From xFrom xii=0 with h=1. That is, predict the =0 with h=1. That is, predict the function’s value at xfunction’s value at xi+1i+1=1=1

f(0)=1.2f(0)=1.2

f(1)=0.2 -f(1)=0.2 - True value True value

1212

The Taylor SeriesThe Taylor Series

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

Page 13: MECN 3500 Lecture 4 Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar E. Meza Castillo omeza@bayamon.inter.edu

Lecture 4Lecture 4MEC

N 3

500 I

nte

r -

Bayam

on

MEC

N 3

500 I

nte

r -

Bayam

on

Zero-order approximationZero-order approximation

First-order approximationFirst-order approximation

1313

The Taylor SeriesThe Taylor Series

0.12.12.0E

ionapproximatvalueTrueE

2.1)1(f

2.1)0(fxfxf

t

t

i1i

75.095.02.0E

95.0)1(25.02.1h)0('f0f1f

25.0)0('f

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

h)x('fxfxf

t

23i

ii1i

Page 14: MECN 3500 Lecture 4 Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar E. Meza Castillo omeza@bayamon.inter.edu

Lecture 4Lecture 4MEC

N 3

500 I

nte

r -

Bayam

on

MEC

N 3

500 I

nte

r -

Bayam

on

Second-order approximationSecond-order approximation

1414

The Taylor SeriesThe Taylor Series

25.045.02.0E

45.012

1)1(25.02.1

!2

h)0(''fh)0('f0f1f

1)0(''f

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

!2

h)x(''fh)x('fxfxf

t

22

2i

2i

ii1i

Page 15: MECN 3500 Lecture 4 Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar E. Meza Castillo omeza@bayamon.inter.edu

Lecture 4Lecture 4MEC

N 3

500 I

nte

r -

Bayam

on

MEC

N 3

500 I

nte

r -

Bayam

on

Third-order approximationThird-order approximation

1515

The Taylor SeriesThe Taylor Series

1.03.02.0E

3.06

19.01

2

1)1(25.02.1

!3

h)0('''f

!2

h)0(''fh)0('f0f1f

9.0)0(''f

9.0x4.2)x('''f!3

h)x('''f

!2

h)x(''fh)x('fxfxf

t

32

32

i

3i

2i

ii1i

Page 16: MECN 3500 Lecture 4 Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar E. Meza Castillo omeza@bayamon.inter.edu

Lecture 4Lecture 4MEC

N 3

500 I

nte

r -

Bayam

on

MEC

N 3

500 I

nte

r -

Bayam

on

Fourth-order approximationFourth-order approximation

1616

The Taylor SeriesThe Taylor Series

02.02.0E

2.024

14.2

6

19.01

2

1)1(25.02.1

!4

h)0(f

!3

h)0('''f

!2

h)0(''fh)0('f0f1f

4.2)0(f

4.2)x(f

!4

h)x(f

!3

h)x('''f

!2

h)x(''fh)x('fxfxf

t

432

4iv32

iv

iiv

4i

iv3i

2i

ii1i

Page 17: MECN 3500 Lecture 4 Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar E. Meza Castillo omeza@bayamon.inter.edu

Lecture 4Lecture 4MEC

N 3

500 I

nte

r -

Bayam

on

MEC

N 3

500 I

nte

r -

Bayam

on

1717

The Taylor SeriesThe Taylor Series

Page 18: MECN 3500 Lecture 4 Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar E. Meza Castillo omeza@bayamon.inter.edu

Lecture 4Lecture 4MEC

N 3

500 I

nte

r -

Bayam

on

MEC

N 3

500 I

nte

r -

Bayam

on

If we truncate the series after the first If we truncate the series after the first derivative termderivative term

1818

Taylor Series to Estimate Truncation ErrorsTaylor 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

Page 19: MECN 3500 Lecture 4 Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar E. Meza Castillo omeza@bayamon.inter.edu

Lecture 4Lecture 4MEC

N 3

500 I

nte

r -

Bayam

on

MEC

N 3

500 I

nte

r -

Bayam

on

Forward Difference ApproximationForward Difference Approximation

1919

Numerical DifferentiationNumerical Differentiation

)xx(O)xx(

)x(f)x(f)x('f i1i

i1i

i1ii

Page 20: MECN 3500 Lecture 4 Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar E. Meza Castillo omeza@bayamon.inter.edu

Lecture 4Lecture 4MEC

N 3

500 I

nte

r -

Bayam

on

MEC

N 3

500 I

nte

r -

Bayam

on

Backward Difference ApproximationBackward Difference Approximation

2020

Numerical DifferentiationNumerical Differentiation

)h(Oh

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

Page 21: MECN 3500 Lecture 4 Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar E. Meza Castillo omeza@bayamon.inter.edu

Lecture 4Lecture 4MEC

N 3

500 I

nte

r -

Bayam

on

MEC

N 3

500 I

nte

r -

Bayam

on

Centered Difference ApproximationCentered Difference Approximation

2121

Numerical DifferentiationNumerical Differentiation

)h(Oh2

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

Page 22: MECN 3500 Lecture 4 Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar E. Meza Castillo omeza@bayamon.inter.edu

Lecture 4Lecture 4MEC

N 3

500 I

nte

r -

Bayam

on

MEC

N 3

500 I

nte

r -

Bayam

on

2222

Page 23: MECN 3500 Lecture 4 Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar E. Meza Castillo omeza@bayamon.inter.edu

Lecture 4Lecture 4MEC

N 3

500 I

nte

r -

Bayam

on

MEC

N 3

500 I

nte

r -

Bayam

on

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

h=0.5h=0.5

xxi-1i-1=0 -=0 - f(x f(xi-1i-1)=1.2)=1.2

xxii=0.5 -=0.5 - f(x f(xii)=0.925)=0.925

XXi+1i+1=1 -=1 - f(x f(xi+1i+1)=0.2)=0.2

2323

The Taylor SeriesThe Taylor Series

25.0x1x45.0x4.0x'f

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

234

Page 24: MECN 3500 Lecture 4 Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar E. Meza Castillo omeza@bayamon.inter.edu

Lecture 4Lecture 4MEC

N 3

500 I

nte

r -

Bayam

on

MEC

N 3

500 I

nte

r -

Bayam

on

Forward Difference ApproximationForward Difference Approximation

Backward Difference ApproximationBackward Difference Approximation

2424

The Taylor SeriesThe Taylor Series

%9.58

45.15.0

925.02.0

h

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

t

i1i

%7.39

55.05.0

2.1925.0

h

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

t

1ii

Page 25: MECN 3500 Lecture 4 Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar E. Meza Castillo omeza@bayamon.inter.edu

Lecture 4Lecture 4MEC

N 3

500 I

nte

r -

Bayam

on

MEC

N 3

500 I

nte

r -

Bayam

on

Centered Difference ApproximationCentered Difference Approximation

2525

The Taylor SeriesThe Taylor Series

%6.9

15.0

2.12.0

h

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

t

1i1i

Page 26: MECN 3500 Lecture 4 Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar E. Meza Castillo omeza@bayamon.inter.edu

Lecture 4Lecture 4MEC

N 3

500 I

nte

r -

Bayam

on

MEC

N 3

500 I

nte

r -

Bayam

on

h=0.25h=0.25

xxi-1i-1=0.25 -=0.25 - f(x f(xi-1i-1)=1.10351563)=1.10351563

xxii=0.5 -=0.5 - f(x f(xii)=0.925)=0.925

XXi+1i+1=0.75 -=0.75 - f(x f(xi+1i+1)=0.63632813)=0.63632813

Forward Difference ApproximationForward Difference Approximation

2626

The Taylor SeriesThe Taylor Series

%5.26

155.125.0

925.063632813.0

h

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

t

i1i

Page 27: MECN 3500 Lecture 4 Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar E. Meza Castillo omeza@bayamon.inter.edu

Lecture 4Lecture 4MEC

N 3

500 I

nte

r -

Bayam

on

MEC

N 3

500 I

nte

r -

Bayam

on

Backward Difference ApproximationBackward Difference Approximation

Centered Difference ApproximationCentered Difference Approximation

2727

The Taylor SeriesThe Taylor Series

%4.2

934.025.0

10351563.163632813.0

h

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

t

1i1i

%7.21

714.025.0

10351563.1925.0

h

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

t

1ii

Page 28: MECN 3500 Lecture 4 Numerical Methods for Engineering MECN 3500 Professor: Dr. Omar E. Meza Castillo omeza@bayamon.inter.edu

Lecture 4Lecture 4MEC

N 3

500 I

nte

r -

Bayam

on

MEC

N 3

500 I

nte

r -

Bayam

on

Homework3 Homework3 www.bc.inter.edu/facultad/omeza

Omar E. Meza Castillo Ph.D.Omar E. Meza Castillo Ph.D.

2828