NUMERICAL DIFFERENTIATION The derivative of f (x) at x 0 is: An approximation to this is: for small...

50
NUMERICAL DIFFERENTIATION NUMERICAL DIFFERENTIATION The derivative of f (x) at x 0 is: h x f h x f x f Limit h ) ( 0 0 0 0 An approximation to this is: h x f h x f x f ) ( 0 0 0 for small values of h. Forward Difference Formula

Transcript of NUMERICAL DIFFERENTIATION The derivative of f (x) at x 0 is: An approximation to this is: for small...

Page 1: NUMERICAL DIFFERENTIATION The derivative of f (x) at x 0 is: An approximation to this is: for small values of h. Forward Difference Formula.

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

Page 2: NUMERICAL DIFFERENTIATION The derivative of f (x) at x 0 is: An approximation to this is: 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

Page 3: NUMERICAL DIFFERENTIATION The derivative of f (x) at x 0 is: An approximation to this is: for small values of h. Forward Difference Formula.

Assume that a function goes through three points:

., and ,,, 221100 xfxxfxxfx

)()( xPxf

221100 xfxLxfxLxfxLxP

Lagrange Interpolating Polynomial

Page 4: NUMERICAL DIFFERENTIATION The derivative of f (x) at x 0 is: An approximation to this is: for small values of h. Forward Difference Formula.

21202

10

12101

20

02010

21

))((

))((

))((

))((

))((

))((

xfxxxx

xxxx

xfxxxx

xxxx

xfxxxx

xxxxxP

221100 xfxLxfxLxfxLxP

Page 5: NUMERICAL DIFFERENTIATION The derivative of f (x) at x 0 is: An approximation to this is: for small values of h. Forward Difference Formula.

)()( xPxf

21202

10

12101

20

02010

21

))((

2

))((

2

))((

2

xfxxxx

xxx

xfxxxx

xxx

xfxxxx

xxxxP

Page 6: NUMERICAL DIFFERENTIATION The derivative of f (x) at x 0 is: An approximation to this is: for small values of h. Forward Difference Formula.

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

Page 7: NUMERICAL DIFFERENTIATION The derivative of f (x) at x 0 is: An approximation to this is: for small values of h. Forward Difference Formula.

2212020 2

2

2

3xf

h

hxf

h

hxf

h

hxP

2100 432

1xfxfxf

hxP

hxfhxfxfh

xf 2432

10000

Three-point formula:

Page 8: NUMERICAL DIFFERENTIATION The derivative of f (x) at x 0 is: An approximation to this is: for small values of h. Forward Difference 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

Page 9: NUMERICAL DIFFERENTIATION The derivative of f (x) at x 0 is: An approximation to this is: for small values of h. Forward Difference Formula.

2212020 22

0xf

h

hxf

h

hxf

hxP

hxfhxfh

xf 000 2

1

Another Three-point formula:

Page 10: NUMERICAL DIFFERENTIATION The derivative of f (x) at x 0 is: An approximation to this is: for small values of h. Forward Difference 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)

Page 11: NUMERICAL DIFFERENTIATION The derivative of f (x) at x 0 is: An approximation to this is: for small values of h. Forward Difference Formula.

hOxfh

xfhxf

hOh

xfhxfxf

h

xfhxfxf

Forward Difference

Formula

xfh

xfh

hO 32

2

!32

Page 12: NUMERICAL DIFFERENTIATION The derivative of f (x) at x 0 is: An approximation to this is: for small values of h. Forward Difference Formula.

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)

Page 13: NUMERICAL DIFFERENTIATION The derivative of f (x) at x 0 is: An approximation to this is: for small values of h. Forward Difference Formula.

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)

Page 14: NUMERICAL DIFFERENTIATION The derivative of f (x) at x 0 is: An approximation to this is: for small values of h. Forward Difference Formula.

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

Page 15: NUMERICAL DIFFERENTIATION The derivative of f (x) at x 0 is: An approximation to this is: for small values of h. Forward Difference Formula.

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

Page 16: NUMERICAL DIFFERENTIATION The derivative of f (x) at x 0 is: An approximation to this is: for small values of h. Forward Difference Formula.

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

Page 17: NUMERICAL DIFFERENTIATION The derivative of f (x) at x 0 is: An approximation to this is: for small values of h. Forward Difference Formula.

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

Page 18: NUMERICAL DIFFERENTIATION The derivative of f (x) at x 0 is: An approximation to this is: for small values of h. Forward Difference Formula.

2

2hO

h

hxfhxfxf

xfh

xfh

hO 65

32

2

!6!3

h

hxfhxfxf

2

Second Three-point Formula

Page 19: NUMERICAL DIFFERENTIATION The derivative of f (x) at x 0 is: An approximation to this is: for small values of h. Forward Difference Formula.

h

xfhxfxf

Forward Difference

Formula

Summary of Errors

xfh

xfh

hO 32

2

!32Error term

Page 20: NUMERICAL DIFFERENTIATION The derivative of f (x) at x 0 is: An approximation to this is: for small values of h. Forward Difference Formula.

h

xfhxfhxfxf

2

342

First Three-point Formula

Summary of Errors continued

xfh

xfh

hO 43

32

2

!4

6

!3

2Error term

Page 21: NUMERICAL DIFFERENTIATION The derivative of f (x) at x 0 is: An approximation to this is: for small values of h. Forward Difference Formula.

h

hxfhxfxf

2

Second Three-point Formula

xfh

xfh

hO 65

32

2

!6!3Error term

Summary of Errors continued

Page 22: NUMERICAL DIFFERENTIATION The derivative of f (x) at x 0 is: An approximation to this is: for small values of h. Forward Difference Formula.

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

Page 23: NUMERICAL DIFFERENTIATION The derivative of f (x) at x 0 is: An approximation to this is: for small values of h. Forward Difference Formula.

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.

. ...

Page 24: NUMERICAL DIFFERENTIATION The derivative of f (x) at x 0 is: An approximation to this is: for small values of h. Forward Difference Formula.

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

Page 25: NUMERICAL DIFFERENTIATION The derivative of f (x) at x 0 is: An approximation to this is: for small values of h. Forward Difference Formula.

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

Page 26: NUMERICAL DIFFERENTIATION The derivative of f (x) at x 0 is: An approximation to this is: for small values of h. Forward Difference Formula.

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

Page 27: NUMERICAL DIFFERENTIATION The derivative of f (x) at x 0 is: An approximation to this is: for small values of h. Forward Difference Formula.

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

Page 28: NUMERICAL DIFFERENTIATION The derivative of f (x) at x 0 is: An approximation to this is: for small values of h. Forward Difference Formula.

xfh

xfh

hxfxfhxf 42

22 !4

22

xfh

h

hxfxfhxfxf 4

2

22

!4

22

2

2 2

h

hxfxfhxfxf

Page 29: NUMERICAL DIFFERENTIATION The derivative of f (x) at x 0 is: An approximation to this is: for small values of h. Forward Difference Formula.

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.

Page 30: NUMERICAL DIFFERENTIATION The derivative of f (x) at x 0 is: An approximation to this is: for small values of h. Forward Difference Formula.

y

xx 0 = a x 0 = b

f(a)

f(b)f(x)

Page 31: NUMERICAL DIFFERENTIATION The derivative of f (x) at x 0 is: An approximation to this is: for small values of h. Forward Difference Formula.

y

xx 0 = a x 0 = b

f(a)

f(b)

f(x)

Page 32: NUMERICAL DIFFERENTIATION The derivative of f (x) at x 0 is: An approximation to this is: for small values of h. Forward Difference Formula.

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

Page 33: NUMERICAL DIFFERENTIATION The derivative of f (x) at x 0 is: An approximation to this is: for small values of h. Forward Difference Formula.

Simpson’s Rule:

2

0

2

0

x

x

x

x

dxxPdxxf )()(

hxxhxx 20201 and

Page 34: NUMERICAL DIFFERENTIATION The derivative of f (x) at x 0 is: An approximation to this is: for small values of h. Forward Difference Formula.

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 )

Page 35: NUMERICAL DIFFERENTIATION The derivative of f (x) at x 0 is: An approximation to this is: for small values of h. Forward Difference Formula.

)()(

)()(

210 43

2

0

2

0

xfxfxfh

dxxPdxxfx

x

x

x

Page 36: NUMERICAL DIFFERENTIATION The derivative of f (x) at x 0 is: An approximation to this is: for small values of h. Forward Difference Formula.

y

xx 0 = a x 0 = b

f(a)

f(b)

f(x)

Page 37: NUMERICAL DIFFERENTIATION The derivative of f (x) at x 0 is: An approximation to this is: for small values of h. Forward Difference Formula.

y

xx 0 = a x 0 = b

f(a)

f(b)

f(x)

Page 38: NUMERICAL DIFFERENTIATION The derivative of f (x) at x 0 is: An approximation to this is: for small values of h. Forward Difference Formula.

y

xx 0 = a x 0 = b

f(a)

f(b)

f(x)

Page 39: NUMERICAL DIFFERENTIATION The derivative of f (x) at x 0 is: An approximation to this is: for small values of h. Forward Difference Formula.

y

xx 0 = a x 0 = b

f(a)

f(b)

f(x)

Page 40: NUMERICAL DIFFERENTIATION The derivative of f (x) at x 0 is: An approximation to this is: for small values of h. Forward Difference Formula.

Composite Numerical Integration

Page 41: NUMERICAL DIFFERENTIATION The derivative of f (x) at x 0 is: An approximation to this is: for small values of h. Forward Difference Formula.

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.

Page 42: NUMERICAL DIFFERENTIATION The derivative of f (x) at x 0 is: An approximation to this is: for small values of h. Forward Difference Formula.

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

Page 43: NUMERICAL DIFFERENTIATION The derivative of f (x) at x 0 is: An approximation to this is: for small values of h. Forward Difference Formula.

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

Page 44: NUMERICAL DIFFERENTIATION The derivative of f (x) at x 0 is: An approximation to this is: for small values of h. Forward Difference Formula.

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

Page 45: NUMERICAL DIFFERENTIATION The derivative of f (x) at x 0 is: An approximation to this is: for small values of h. Forward Difference Formula.

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

Page 46: NUMERICAL DIFFERENTIATION The derivative of f (x) at x 0 is: An approximation to this is: for small values of h. Forward Difference Formula.

by dividing the interval into 20 subintervals.

Find π

sin0

(x)dx

2021020

20

20

....., , , , ,π

π

kk

khax

n

abh

n

k

Page 47: NUMERICAL DIFFERENTIATION The derivative of f (x) at x 0 is: An approximation to this is: for small values of h. Forward Difference Formula.

9958861

2020

40

22

19

1

1

10

.

πsinπ

sinsinπ

)()()sin(π

k

n

kk

k

bfxfafh

dxx

Page 48: NUMERICAL DIFFERENTIATION The derivative of f (x) at x 0 is: An approximation to this is: for small values of h. Forward Difference Formula.

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

Page 49: NUMERICAL DIFFERENTIATION The derivative of f (x) at x 0 is: An approximation to this is: for small values of h. Forward Difference Formula.

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

Page 50: NUMERICAL DIFFERENTIATION The derivative of f (x) at x 0 is: An approximation to this is: for small values of h. Forward Difference Formula.

0000062

20

124

20

220

6010

1

9

10

.

)πsin(π)(

sin

πsinsin

π)sin(

π

k

k

k

kdxx