numerical differentiation integration

Post on 01-Nov-2014

648 Views

Category:

Education

19 Downloads

Preview:

Click to see full reader

DESCRIPTION

Numerical differentiation integration

TRANSCRIPT

NUMERICAL DIFFERENTIATIONNUMERICAL DIFFERENTIATION

The derivative of f (x) at x0 is:

h

xfhxfxf Limit

h

)( 0000

An approximation to this is:

h

xfhxfxf

)( 000

for small values of h.

Forward Difference Formula

810 . and ln)(Let xxxfFind an approximate value for 81.f

0.1 0.5877867 0.6418539 0.5406720

0.01 0.5877867 0.5933268 0.5540100

0.001 0.5877867 0.5883421 0.5554000

).( 81f ).( hf 81 h

fhf ).().( 8181 h

The exact value of 555081 .. f

Assume that a function goes through three points:

., and ,,, 221100 xfxxfxxfx

)()( xPxf

221100 xfxLxfxLxfxLxP

Lagrange Interpolating Polynomial

21202

10

12101

20

02010

21

))((

))((

))((

))((

))((

))((

xfxxxx

xxxx

xfxxxx

xxxx

xfxxxx

xxxxxP

221100 xfxLxfxLxfxLxP

)()( xPxf

21202

10

12101

20

02010

21

))((

2

))((

2

))((

2

xfxxxx

xxx

xfxxxx

xxx

xfxxxx

xxxxP

20000

000

10000

000

00000

0000

)()2()2(

)(2

)2()()(

)2(2

)2()(

)2()(2

xfhxhxxhx

hxxx

xfhxhxxhx

hxxx

xfhxxhxx

hxhxxxP

If the points are equally spaced, i.e.,

hxxhxx 20201 and

2212020 2

2

2

3xf

h

hxf

h

hxf

h

hxP

2100 432

1xfxfxf

hxP

hxfhxfxfh

xf 2432

10000

Three-point formula:

hxxhxx 0201 and If the points are equally spaced with x0 in the middle:

20000

000

10000

000

00000

0000

)()()(

)(2

)()()(

)(2

)(()(

)()(2

xfhxhxxhx

hxxx

xfhxhxxhx

hxxx

xfhxxhxx

hxhxxxP

2212020 22

0xf

h

hxf

h

hxf

hxP

hxfhxfh

xf 000 2

1

Another Three-point formula:

Alternate approach (Error estimate)

Take Taylor series expansion of f(x+h) about x:

xfh

xfh

xfhxfhxf 33

22

!32

xfh

xfh

xfhxfhxf 33

22

!32

xfh

xfh

xfh

xfhxf 32

2

!32.............. (1)

hOxfh

xfhxf

hOh

xfhxfxf

h

xfhxfxf

Forward Difference

Formula

xfh

xfh

hO 32

2

!32

xfh

xfh

xfhxfhxf 33

22

!3

8

2

422

xfh

xfh

xfhxfhxf 33

22

!3

8

2

422

xfh

xfh

xfh

xfhxf 32

2

!3

4

2

2

2

2

................. (2)

xfh

xfh

xfh

xfhxf 32

2

!32.............. (1)

xfh

xfh

xfh

xfhxf 32

2

!3

4

2

2

2

2

................. (2)

2 X Eqn. (1) – Eqn. (2)

xfh

xfh

xf

h

xfhxf

h

xfhxf

43

32

!4

6

!3

2

2

22

2

43

32

!4

6

!3

2

2

342

hOxf

xfh

xfh

xf

h

xfhxfhxf

2

2

342hOxf

h

xfhxfhxf

2

2

342hO

h

xfhxfhxfxf

h

xfhxfhxfxf

2

342

Three-point Formula

xfh

xfh

hO 43

32

2

!4

6

!3

2

Take Taylor series expansion of f(x+h) about x:

xfh

xfh

xfhxfhxf 33

22

!32Take Taylor series expansion of f(x-h) about x:

xfh

xfh

xfhxfhxf 33

22

!32

The Second Three-point Formula

Subtract one expression from another

xfh

xfh

xfhhxfhxf 66

33

!6

2

!3

22

xfh

xfh

xfhhxfhxf 66

33

!6

2

!3

22

xfh

xfh

xfh

hxfhxf 65

32

!6!32

xfh

xfh

h

hxfhxfxf 6

53

2

!6!32

2

2hO

h

hxfhxfxf

xfh

xfh

hO 65

32

2

!6!3

h

hxfhxfxf

2

Second Three-point Formula

h

xfhxfxf

Forward Difference

Formula

Summary of Errors

xfh

xfh

hO 32

2

!32Error term

h

xfhxfhxfxf

2

342

First Three-point Formula

Summary of Errors continued

xfh

xfh

hO 43

32

2

!4

6

!3

2Error term

h

hxfhxfxf

2

Second Three-point Formula

xfh

xfh

hO 65

32

2

!6!3Error term

Summary of Errors continued

Example:

xxexf

Find the approximate value of 2f

1.9 12.703199

2.0 14.778112

2.1 17.148957

2.2 19.855030

x xf

with 10.h

Using the Forward Difference formula:

0 0 0

1f x f x h f x

h

12 2 1 2

0 11

17 148957 14 7781120 1

23 708450

f f . f.

. ...

Using the 1st Three-point formula:

032310.22

855030.19

148957.174778112.1432.0

1

)2.2()1.2(4)2(31.02

12

ffff

hxfhxfxfh

xf 2432

10000

Using the 2nd Three-point formula:

228790.22

703199.12148957.172.0

1

)9.1()1.2(1.02

12

fff

The exact value of 22.167168 :is 2f

hxfhxfh

xf 000 2

1

Comparison of the results with h = 0.1

Formula Error

Forward Difference 23.708450 1.541282

1st Three-point 22.032310 0.134858

2nd Three-point 22.228790 0.061622

2f

The exact value of 2f is 22.167168

Second-order Derivative

xfh

xfh

xfhxfhxf 33

22

!32

xfh

xfh

xfhxfhxf 33

22

!32

Add these two equations.

xfh

xfh

xfhxfhxf 44

22

!4

2

2

22

2 4

2 42 22

2 4!

h hf x h f x f x h f x f x

xfh

xfh

hxfxfhxf 42

22 !4

22

xfh

h

hxfxfhxfxf 4

2

22

!4

22

2

2 2

h

hxfxfhxfxf

NUMERICAL INTEGRATIONNUMERICAL INTEGRATION

b

a

dxxf )( area under the curve f(x) between

. to bxax

In many cases a mathematical expression for f(x) is unknown and in some cases even if f(x) is known its complex form makes it difficult to perform the integration.

y

xx 0 = a x 0 = b

f(a)

f(b)f(x)

y

xx 0 = a x 0 = b

f(a)

f(b)

f(x)

Area of the trapezoid

The length of the two parallel sides of the trapezoid are: f(a) and f(b)

The height is b-a

)()(

)()()(

bfafh

bfafab

dxxfb

a

2

2

Simpson’s Rule:

2

0

2

0

x

x

x

x

dxxPdxxf )()(

hxxhxx 20201 and

2 2

0 0

2

0

2

0

1 20

0 1 0 2

0 21

1 0 1 2

0 12

2 0 2 1

x x

x x

x

x

x

x

( x x )( x x )P x dx f x dx

( x x )( x x )

( x x )( x x )f x dx

( x x )( x x )

( x x )( x x )f x dx

( x x )( x x )

)()(

)()(

210 43

2

0

2

0

xfxfxfh

dxxPdxxfx

x

x

x

y

xx 0 = a x 0 = b

f(a)

f(b)

f(x)

y

xx 0 = a x 0 = b

f(a)

f(b)

f(x)

y

xx 0 = a x 0 = b

f(a)

f(b)

f(x)

y

xx 0 = a x 0 = b

f(a)

f(b)

f(x)

Composite Numerical Integration

Riemann Sum

The area under the curve is subdivided into n subintervals. Each subinterval is treated as a rectangle. The area of all subintervals are added to determine the area under the curve.

There are several variations of Riemann sum as applied to composite integration.

In Left Riemann sum, the left-side sample of the function is used as the height of the individual rectangle.

a b

Left Riemann Sumy

xx

1

2

3 2

1i

x b a / n

x a

x a x

x a x

x a i x

1

nb

iai

f x dx f x x

In Right Riemann sum, the right-side sample of the function is used as the height of the individual rectangle.

a b

Right Riemann Sumy

x

x

1

2

3

2

3

i

x b a / n

x a x

x a x

x a x

x a i x

1

nb

iai

f x dx f x x

In the Midpoint Rule, the sample at the middle of the subinterval is used as the height of the individual rectangle.

a b

Midpoint Ruley

xx

1

2

3

2 1 1 2

2 2 1 2

2 3 1 2

2 1 2i

x b a / n

x a x /

x a x /

x a x /

x a i x /

1

nb

iai

f x dx f x x

Composite Trapezoidal Rule:

Divide the interval into n subintervals and apply Trapezoidal Rule in each subinterval.

)()()( bfxfafh

dxxfn

kk

b

a

1

1

22

where

nkkhaxn

abh k , ... , , ,for and 210

by dividing the interval into 20 subintervals.

Find π

sin0

(x)dx

2021020

20

20

....., , , , ,π

π

kk

khax

n

abh

n

k

9958861

2020

40

22

19

1

1

10

.

πsinπ

sinsinπ

)()()sin(π

k

n

kk

k

bfxfafh

dxx

Composite Simpson’s Rule:

Divide the interval into n subintervals and apply Simpson’s Rule on each consecutive pair of subinterval. Note that n must be even.

)()(

)()(

/

)/(

bfxf

xfafh

dxxf

n

kk

n

kk

b

a

2

112

12

12

4

23

nkkhaxn

abh k , ... , , ,for and 210

where

by dividing the interval into 20 subintervals.

Find π

sin0

(x)dx

2021020

2020

....., , , , ,π

π

kk

khax

n

abhn

k

0000062

20

124

20

220

6010

1

9

10

.

)πsin(π)(

sin

πsinsin

π)sin(

π

k

k

k

kdxx

top related