2 differentiation mod.ppt [compatibility mode]

45
Introduction to Numerical Analysis for Engineers Differentiation

Upload: zulvicky-liandy

Post on 06-Dec-2015

223 views

Category:

Documents


0 download

DESCRIPTION

eeew

TRANSCRIPT

Introduction toNumerical Analysis for Engineers

Differentiation

Function Evaluation (1)

Problem: Compute f(x)

Easy for well known functionsFor example, f (x) = 1, f (x) = x2

Function Evaluation (2) Suppose f (x) is a black box

Difficult and/or expensive to compute For example: a complex function, an experiment, a procedure

Limited information about the function Suppose we know information about the function at a particular

domain location, x = c f (c), f ’(c), f ’’(c), f ’’’(c), …

x f (x)f

Taylor’s Series Evaluate f (x) about a point c, called the point of

expansion

Observations: An infinite series (x – c) is the distance from the point of expansion F (x) is a polynomial!!!

Some Common Derivatives

October 21, 2013 6Introduction Numerical Analysis for Engineer

Numerical Differentiation

Analytically, Calculus defines for us:

Geometrically: The tangent (line in 1D)

x

October 21, 2013 7Introduction Numerical Analysis for Engineer

Numerical Differentiation How do we program this?

The limit as h→ 0 … cannot set h = 0, so must approximate! What value of h is appropriate?

Choose a non-zero h Geometrically, rise/run or the slope of the secant curve

x x + h

Tangent Line

Secant Line

October 21, 2013 8Introduction Numerical Analysis for Engineer

Computing Errors

Analyze

Any precision problems???

Take 1/h As h gets smaller, this value becomes larger … good As h gets larger, this value gets smaller

… Truncation Error

October 21, 2013 9Introduction Numerical Analysis for Engineer

Round Off Error

Analyze

As h gets smaller, f (x) and f (x + h) get closer

x + hx x + h

October 21, 2013 10Introduction Numerical Analysis for Engineer

Round Off Error

Thus, f (x + h) – f (x) → 0 Loss of significance Easily get a random round-off bit as the most

significant digit in the subtraction

So, dividing by h leads to a very wrong answerfor f ’(x)

October 21, 2013 11Introduction Numerical Analysis for Engineer

Error Tradeoff As h gets smaller, truncation error decreases, but round off error increases

The trade off is a point of diminishing returns Always think and test!

Log error

Log step size

Truncation error

Round off error

Total errorPoint of

diminishingreturns

October 21, 2013 12Introduction Numerical Analysis for Engineer

Numerical Differentiation

This formula favors (or biasestowards) the right-hand side of the curve

Why not use the left? (f (x) – f(x - h))/h

x x + h

Secant Line

x - h

October 21, 2013 13Introduction Numerical Analysis for Engineer

Error Analysis … Taylor’s Theorem

Forward Differences Take Taylor’s to three terms … let’s take a look at

the error term

Theoreticallyspeaking

Contoh

October 21, 2013 14Introduction Numerical Analysis for Engineer

Gunakan forward difference, dengan nilai h seperti dibawah ini, untuk menghitung turunan pertama dengannumerik dari cos(x) pada x = π/3.(a) h = 0.1(b) h = 0.01(c) h = 0.001(d) h = 0.0001Hitung sampai 8 decimal.

Contoh

October 21, 2013 15Introduction Numerical Analysis for Engineer

Solusi eksak

October 21, 2013 16Introduction Numerical Analysis for Engineer

Error Analysis … Taylor’s Theorem

Backward Differences

Theoreticallyspeaking

Contoh

October 21, 2013 17Introduction Numerical Analysis for Engineer

Gunakan backward difference, dengan nilai h seperti dibawah ini, untuk menghitung turunan pertama dengannumerik dari cos(x) pada x = π/3.(a) h = 0.1(b) h = 0.01(c) h = 0.001(d) h = 0.0001Hitung sampai 8 decimal.

October 21, 2013 18Introduction Numerical Analysis for Engineer

Error Analysis … Taylor’s Theorem

Linear Convergence

October 21, 2013 19Introduction Numerical Analysis for Engineer

Numerical Differentiation You should be asking yourself … Can we do better?

Average both sides together???

x x + hx - h

f (x + h) – f (x – h)

2h

October 21, 2013 20Introduction Numerical Analysis for Engineer

Numerical Differentiation

Central Difference

Is this any better?

Forward difference Backward difference

October 21, 2013 21Introduction Numerical Analysis for Engineer

Central Differences

This formula does not seem very good Does not follow the calculus formula We don’t even evaluate at x (our location of interest)

It takes the slope of the secant with width 2h

x x + hx - h

Secant Line

October 21, 2013 22Introduction Numerical Analysis for Engineer

October 21, 2013 23Introduction Numerical Analysis for Engineer

Error Analysis … Taylor’s Theorem

OK, let’s stop guessing … Taylor’s will tell us

Solve for this

Four terms

October 21, 2013 24Introduction Numerical Analysis for Engineer

Central Differences

Central differences has much better convergence As h2 → 0, the error term has quadratic convergence

Theoreticallyspeaking

Contoh

October 21, 2013 25Introduction Numerical Analysis for Engineer

Gunakan central difference, dengan nilai h seperti di bawahini, untuk menghitung turunan pertama dengan numerikdari cos(x) pada x = π/3.(a) h = 0.1(b) h = 0.01(c) h = 0.001(d) h = 0.0001Hitung sampai 8 decimal.

Contoh

October 21, 2013 26Introduction Numerical Analysis for Engineer

Solusi eksak

October 21, 2013 27Introduction Numerical Analysis for Engineer

Let f(x) = cosh(x) and a = 2. Let h = 0.01 andapproximate f’ (a), f’’(a), using forward, backwardand central differences.Work to 8 decimal places and compare youranswers with the exact result,

Five Point Formula

October 21, 2013 28Introduction Numerical Analysis for Engineer

Five Point Formula

October 21, 2013 29Introduction Numerical Analysis for Engineer

Five Point Formula

October 21, 2013 30Introduction Numerical Analysis for Engineer

October 21, 2013 31Introduction Numerical Analysis for Engineer

Second Derivatives

What if we need the second derivative?

Any guesses?

October 21, 2013 32Introduction Numerical Analysis for Engineer

Second Derivatives

Add the terms Cancel the odd terms and double up the even ones

October 21, 2013 33Introduction Numerical Analysis for Engineer

Second Derivatives

Isolating the second derivative term yields:

With an error term of:

Third Derivative

October 21, 2013 34Introduction Numerical Analysis for Engineer

Third Derivative

October 21, 2013 35Introduction Numerical Analysis for Engineer

Fourth Derivative

October 21, 2013 36Introduction Numerical Analysis for Engineer

Fourth Derivative

October 21, 2013 37Introduction Numerical Analysis for Engineer

October 21, 2013 38Introduction Numerical Analysis for Engineer

October 21, 2013 39Introduction Numerical Analysis for Engineer

October 21, 2013 40Introduction Numerical Analysis for Engineer

October 21, 2013 41Introduction Numerical Analysis for Engineer

Contoh

October 21, 2013 42Introduction Numerical Analysis for Engineer

October 21, 2013 43Introduction Numerical Analysis for Engineer

Partial Derivatives

Nothing really special about partial derivatives Hold the other dimensions constant

Partial Derivatives

October 21, 2013 44Introduction Numerical Analysis for Engineer

October 21, 2013 45Introduction Numerical Analysis for Engineer