Lecture 18 - Numerical Differentiation

Post on 01-Jan-2016

90 views 7 download

Tags:

description

Lecture 18 - Numerical Differentiation. CVEN 302 July 19, 2002. Lecture’s Goals. Finite Difference Schemes Taylor Series Expansion for Differentiation Basic Numerical Integration Trapezoidal Rule Simpson’s Rule Midpoint Gaussian Quadrature. v. v. dv. dt. t. t. a. y. t. - PowerPoint PPT Presentation

Transcript of Lecture 18 - Numerical Differentiation

Lecture 18 - Numerical Lecture 18 - Numerical Differentiation Differentiation

CVEN 302

July 19, 2002

Lecture’s GoalsLecture’s Goals

• Finite Difference Schemes

• Taylor Series Expansion for Differentiation

• Basic Numerical Integration– Trapezoidal Rule– Simpson’s Rule– Midpoint– Gaussian Quadrature

dvdt

v

ta

tdt

dva

v

t

b

avdty

y

DifferentiationDifferentiation IntegrationIntegration

Calculus - Numerical MethodsCalculus - Numerical Methods

Numerical DifferentiationNumerical Differentiation

• Estimate the derivatives (slope, curvature, etc.) of a function by using the function values at only a set of discrete points

• Ordinary differential equation (ODE)

• Partial differential equation (PDE)

Numerical DifferentiationNumerical Differentiation

• Represent the function by Taylor polynomials or Lagrange interpolation

• Evaluate the derivatives of the interpolation polynomial at selected nodal points

Numerical DifferentiationNumerical Differentiation A Taylor series or Lagrange interpolation of points can be used to find the derivatives. The Taylor series expansion is defined as:

!3!2

!3!2

0

30i

0

20i

00i0i

0i

xx

3

33

xx

2

22

xx0i

000

xfxx

xfxx

xfxxxfxf

xxx

dx

fdx

dx

fdx

dx

dfxxfxf

First Derivative at a Point

)x(f

i-2 i-1 i i+1 i+2

Numerical DifferentiationNumerical Differentiation

Use the Taylor series expansion to represent three points about single location:

3 !2

2

1 !2

i

2i1i

ii1ii1-i

ii

i

2i1i

ii1ii1i

xfxx

xfxxxfxf

xfxf

xfxx

xfxxxfxf

Numerical DifferentiationNumerical Differentiation

Assume that the data points are “equally spaced” and the equations can be written as:

3 !3

!2

2

1 !3

!2

i

3

i

2

ii1-i

ii

i

3

i

2

ii1i

xfx

xfx

xfxxfxf

xfxf

xfx

xfx

xfxxfxf

Forward DifferentiationForward Differentiation

For a forward first derivative, subtract eqn[2] from eqn[1]:

Rearrange the equation:

!3

!2 i

3

i

2

ii1i

xfx

xfx

xfxxfxf

!3

!2 i

3

i

2

i1ii

xfx

xfx

xfxfxfx

2

i 1 ii i i

2! 3!

f x f x x xf x f x f x

x

Forward DifferentiationForward Differentiation

As the x gets smaller the error will get smaller

The error is defined as:

Error i1i

i

x

xfxfxf

!3

!2

Error i

2

i

xfx

xfx

Backward DifferentiationBackward Differentiation

Subtract eqn[3] from eqn[2]:

The error is defined as:

Error 1-ii

i

x

xfxfxf

!3

!2

Error i

2

i

xfx

xfx

Central DifferentiationCentral Differentiation

Subtract eqn[3] from eqn[1]:

The error is defined as:

Error

21-i1i

i

x

xfxfxf

!3

Error i

2

xf

x

Differential ErrorDifferential Error

Notice that the errors of the forward and backward 1st derivative of the equations have an error of the order of O(x) and the central differentiation has an error of order O(x2). The central difference has an better accuracy and lower error that the others. This can be improved by using more terms to model the first derivative.

Numerical DifferentiationNumerical DifferentiationIf you want to improve the accuracy and decrease the error you will need to eliminate terms :

=

0

=

0

!3

8

!2

4 2 *

!3

!2

*

*

i

3

i

2

ii2-i

i

3

i

2

ii1-i

ii

xfx

xfx

xfxxfxfC

xfx

xfx

xfxxfxfB

xfxfA

0

Higher Order Errors in Higher Order Errors in DifferentiationDifferentiation

The terms become :

The terms become A=-3, B= 4 and C=-1

xOE 2

43 22-i1-iii

x

xfxfxfxf

04

2# 2

0

CB

CB

CBA

Higher Order 1st Derivative)x(f

i-2 i-1 i i+1 i+2

Parabolic curve

Backward difference xOE 2

43 22-i1-iii

x

xfxfxfxf

Forward difference xOE 2

43 2i1i2ii

x

xfxfxfxf

Higher Order DerivativesHigher Order Derivatives

To find higher derivatives, use the Taylor series expansions of term and eliminate the terms from the sum of equations. To improve the error in the problem add additional terms.

22ndnd Derivative of the Function Derivative of the Function

It will require three terms to get a central 2nd derivative of discrete set of data.

=

0

=

0

=

#

!3

!2

*

*

!3

!2

*

i

3

i

2

ii1-i

ii

i

3

i

2

ii1i

xfx

xfx

xfxxfxfC

xfxfB

xfx

xfx

xfxxfxfA

2nd Order Central Difference2nd Order Central DifferenceThe terms become :

The terms become A=1,B=-2 and C=1. Therefore

2#

0

0

CA

CA

CBA

xOE 2 2

21-ii1i

i

x

xfxfxfxf

Lagrange DifferentiationLagrange Differentiation

Another form of differentiation is to use the Lagrange interpolation between three points. The values can be determine for unevenly spaced points. Given:

3

1323

212

3212

311

3121

32

332211

yxxxx

xxxxy

xxxx

xxxxy

xxxx

xxxx

yxLyxLyxLxL

Lagrange DifferentiationLagrange Differentiation

Differentiate the Lagrange interpolation

Assume a constant spacing

31323

212

3212

31

13121

32

22

2

yxxxx

xxxy

xxxx

xxx

yxxxx

xxxxLxf

3221

2231

1232

2

22

2

2y

x

xxxy

x

xxxy

x

xxxxf

Lagrange DifferentiationLagrange Differentiation

Differentiate the Lagrange interpolation

Various locations

3221

2231

1232

2

22

2

2y

x

xxxy

x

xxxy

x

xxxxf

x

yyyy

x

xxxy

x

xxxy

x

xxxxf

2

43

2

22

2

2 32132

21122

31112

3211

x

yyy

x

xxxy

x

xxxy

x

xxxxf

22

22

2

2 1332

21222

31212

3222

x

yyyy

x

xxxy

x

xxxy

x

xxxxf

2

34

2

22

2

2 32132

21322

31312

3233

Lagrange DifferentiationLagrange Differentiation

To find a higher order derivative from the Lagrange interpolation for a three point Lagrange

3221

2231

1232

2

22

2

2y

x

xxxy

x

xxxy

x

xxxxf

2

321322212

2121

x

yyyy

xy

xy

xxf

Take the derivative

Partial DerivativesPartial Derivatives• Straightforward extension of one-

dimensional formula

(i-2, j) (i-1, j) (i, j) (i+1, j) (i+2, j)

(i, j+1)

(i, j+2)

(i, j-1)

(i, j-2)

(i+1, j+1)(i-1, j+1)

(i-1, j-1) (i+1, j-1)

(i-2, j) (i-1, j) (i, j) (i+1, j) (i+2, j)

(i, j+1)

(i, j+2)

(i, j-1)

(i, j-2)

(i+1, j+1)(i-1, j+1)

(i-1, j-1) (i+1, j-1)

121 h

1

x

uu

101 h2

1

x

u u

22

2

xx

x

Partial DerivativesPartial DerivativesLaplacian Operator

1

|

141

|

1

h

1

uuu

2

yyxx2

i-1 i i+1

j+1

j

j-1

Partial DerivativesPartial Derivatives

i-1 i i+1

j+1

j

j-1

Mixed Derivative

101

|||

000

|||

101

h4

1u

2xy

Bi-harmonic OperatorBi-harmonic Operator

i-1 i i+1

j+1

j

j-1

i-2 i+2j-2

j+2

1

|

282

|||

182081

|||

282

|

1

h4

1

x

u

y x

u2

x

uu

4

4

4

22

2

4

44

Richardson ExtrapolationRichardson ExtrapolationThis technique uses the concept of variable grid sizes to reduce the error. The technique uses a simple method for eliminating the error. Consider a second order central difference technique. Write the equation in the form:

xaxa

2 42

212

1-ii1ii

x

xfxfxfxf

Richardson ExtrapolationRichardson ExtrapolationThe central difference can be defined as

i 1 i i-1 2 4i 1 22

2 a a

f x f x f xf x x x

x

2 4

i 1 2

2 4

i 1 2

A a a

A a a 2 2 2

f x A x x x

x x xf x A

Write the equation with different grid sizes

Richardson ExtrapolationRichardson Extrapolation

Expand the terms:

2 4i 1 2

2 4

i 1 2

A a a 1

A a a 22 4 16

f x A x x x

x x xf x A

Richardson ExtrapolationRichardson ExtrapolationMultiply eqn [2] by 4 and subtract eqn [1] from it.

2 4

1 2

2 41 2

4A 4 4a 4a 2 4 16

A a a

x x xA

A x x x

4

23A 4 12a 2 16

x xA A x

Richardson ExtrapolationRichardson ExtrapolationThe equation can be rewritten as:

It can be rewritten in the form

4

2

4 2

A a 3 4

xA A x

x

4 61 2A b b B x x x

Richardson ExtrapolationRichardson ExtrapolationThe technique can be extrapolated to include the higher order error elimination by using a finer grid.

6

16 2

A 15

xB B x

O x

Richardson Extrapolation Richardson Extrapolation ExampleExample

The function is given:

Find the first derivative at x=1.25 using a central difference scheme and h = 0.25. The exact solution:

842 23 xxxxf

6875.3425.1425.13443 22 xxxf

Richardson Extrapolation Richardson Extrapolation ExampleExample

The data points are:

The derivatives using central difference

x f(x)1 -5

1.125 -4.6071.25 -4.1721.375 -3.6821.5 -3.125

7032.3

25.0

6074.46816.3

125.02

125.1375.125.1

75.35.0

5125.3

25.02

0.15.125.1

fff

fff

Richardson Extrapolation Richardson Extrapolation ExampleExample

The results of the central difference scheme are:

The Richardson Extrapolation uses these results to find a better solution

%425.0Error 7032.325.1

%69.1Error 75.325.1

f

f

4

4 3.7032 3.7521.25 3.6876 Error 0.003%

3 3

xA A x

f

SummarySummary

• Finite Difference Techniques

– Taylor Series

– Lagrange Polynomials

• Error Calculation

SummarySummary

• Finite Difference Techniques

– Forward Difference Scheme

– Backward Difference Scheme

– Central Difference Scheme

Homework

• Check the Homework webpage