0
Upcoming SlideShare
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Standard text messaging rates apply

# Numerical differentiation integration

376

Published on

Numerical differentiation integration

Numerical differentiation integration

Published in: Education
1 Like
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

Views
Total Views
376
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
13
0
Likes
1
Embeds 0
No embeds

No notes for slide

### Transcript

• 1. NUMERICAL DIFFERENTIATION The derivative of f (x) at x0 is: f &#x2032;( x 0 ) = Limit h&#x2192; 0 f ( x0 + h) &#x2212; f ( x0 ) h An approximation to this is: f ( x0 + h) &#x2212; f ( x0 ) f &#x2032;( x 0 ) &#x2248; h for small values of h. Forward Difference Formula
• 2. Let f ( x ) = ln x and x0 = 1.8 Find an approximate value for f &#x2032;(1.8) h f (1.8) f (1.8 + h) 0.1 0.5877867 0.6418539 f (1.8 + h) &#x2212; f (1.8) h 0.5406720 0.01 0.5877867 0.5933268 0.5540100 0.001 0.5877867 0.5883421 0.5554000 The exact value of f &#x2032;(1.8) = 0.55 5
• 3. Assume that a function goes through three points: ( x0 , f ( x0 ) ) , ( x1 , f ( x1 ) ) and ( x2 , f ( x2 ) ) . f ( x) &#x2248; P( x) P ( x ) = L0 ( x ) f ( x0 ) + L1 ( x ) f ( x1 ) + L2 ( x ) f ( x2 ) Lagrange Interpolating Polynomial
• 4. P ( x ) = L0 ( x ) f ( x0 ) + L1 ( x ) f ( x1 ) + L2 ( x ) f ( x 2 ) ( x &#x2212; x1 )( x &#x2212; x2 ) P( x) = f ( x0 ) ( x0 &#x2212; x1 )( x0 &#x2212; x2 ) ( x &#x2212; x0 )( x &#x2212; x2 ) + f ( x1 ) ( x1 &#x2212; x0 )( x1 &#x2212; x2 ) ( x &#x2212; x0 )( x &#x2212; x1 ) + f ( x2 ) ( x2 &#x2212; x0 )( x2 &#x2212; x1 )
• 5. f &#x2032;( x ) &#x2248; P &#x2032;( x ) 2 x &#x2212; x1 &#x2212; x2 P &#x2032;( x ) = f ( x0 ) ( x0 &#x2212; x1 )( x0 &#x2212; x2 ) 2 x &#x2212; x0 &#x2212; x2 + f ( x1 ) ( x1 &#x2212; x0 )( x1 &#x2212; x2 ) 2 x &#x2212; x0 &#x2212; x1 + f ( x2 ) ( x2 &#x2212; x0 )( x2 &#x2212; x1 )
• 6. If the points are equally spaced, i.e., x1 = x0 + h and x 2 = x0 + 2h 2 x0 &#x2212; ( x0 + h) &#x2212; ( x0 + 2h) P &#x2032;( x0 ) = f ( x0 ) { x0 &#x2212; ( x0 + h)}{ x0 &#x2212; ( x0 + 2h)} 2 x0 &#x2212; x0 &#x2212; ( x0 + 2h) + f ( x1 ) { ( x0 + h) &#x2212; x0 }{ ( x0 + h) &#x2212; ( x0 + 2h)} 2 x0 &#x2212; x0 &#x2212; ( x0 + h) + f ( x2 ) { ( x0 + 2h) &#x2212; x0 }{ ( x0 + 2h) &#x2212; ( x0 + h)}
• 7. &#x2212; 3h &#x2212; 2h &#x2212;h P &#x2032;( x 0 ) = f ( x0 ) + f ( x1 ) + 2 f ( x 2 ) 2 2 2h &#x2212;h 2h 1 { &#x2212; 3 f ( x0 ) + 4 f ( x1 ) &#x2212; f ( x2 ) } P &#x2032;( x0 ) = 2h Three-point formula: 1 { &#x2212; 3 f ( x0 ) + 4 f ( x0 + h) &#x2212; f ( x0 + 2h) } f &#x2032;( x0 ) &#x2248; 2h
• 8. If the points are equally spaced with x0 in the middle: x1 = x0 &#x2212; h and x 2 = x0 + h 2 x0 &#x2212; ( x0 &#x2212; h) &#x2212; ( x0 + h) P &#x2032;( x0 ) = f ( x0 ) { x0 &#x2212; ( x0 &#x2212; h)}{ ( x0 &#x2212; ( x0 + h)} 2 x0 &#x2212; x0 &#x2212; ( x0 + h) + f ( x1 ) { ( x0 &#x2212; h) &#x2212; x0 }{ ( x0 &#x2212; h) &#x2212; ( x0 + h)} 2 x0 &#x2212; x0 &#x2212; ( x0 &#x2212; h) + f ( x2 ) { ( x0 + h) &#x2212; x0 }{ ( x0 + h) &#x2212; ( x0 &#x2212; h)}
• 9. 0 &#x2212;h h P &#x2032;( x 0 ) = f ( x0 ) + 2 f ( x1 ) + 2 f ( x 2 ) 2 &#x2212;h 2h 2h Another Three-point formula: 1 { f ( x0 + h) &#x2212; f ( x0 &#x2212; h) } f &#x2032;( x0 ) &#x2248; 2h
• 10. Alternate approach (Error estimate) Take Taylor series expansion of f(x+h) about x: 2 3 h ( 2) h ( 3) f ( x + h) = f ( x ) + hf &#x2032;( x ) + f ( x) + f ( x) + &#xF04C; 2 3! h2 ( 2 ) h3 ( 3 ) f ( x + h) &#x2212; f ( x ) = hf &#x2032;( x ) + f ( x) + f ( x) + &#xF04C; 2 3! f ( x + h) &#x2212; f ( x ) h ( 2) h2 ( 3 ) = f &#x2032;( x ) + f ( x ) + f ( x) + &#xF04C; h 2 3! .............. (1)
• 11. f ( x + h) &#x2212; f ( x ) = f &#x2032;( x ) + O ( h) h f ( x + h) &#x2212; f ( x ) f &#x2032;( x ) = &#x2212; O ( h) h f ( x + h) &#x2212; f ( x ) f &#x2032;( x ) &#x2248; h Forward Difference Formula h ( 2) h2 ( 3 ) O ( h) = f ( x ) + f ( x) +&#xF04C; 2 3!
• 12. 4h 2 ( 2 ) 8h 3 ( 3 ) f ( x + 2h) = f ( x ) + 2hf &#x2032;( x ) + f ( x) + f ( x) + &#xF04C; 2 3! 4h 2 ( 2 ) 8h 3 ( 3 ) f ( x + 2h) &#x2212; f ( x ) = 2hf &#x2032;( x ) + f ( x) + f ( x) + &#xF04C; 2 3! f ( x + 2h ) &#x2212; f ( x ) 2h ( 2 ) 4h 2 ( 3 ) = f &#x2032;( x ) + f ( x) + f ( x) + &#xF04C; 2h 2 3! ................. (2)
• 13. f ( x + h) &#x2212; f ( x ) h ( 2) h ( 3) = f &#x2032;( x ) + f ( x ) + f ( x) + &#xF04C; h 2 3! .............. (1) 2 f ( x + 2h ) &#x2212; f ( x ) 2h ( 2 ) 4h 2 ( 3 ) = f &#x2032;( x ) + f ( x) + f ( x) + &#xF04C; 2h 2 3! ................. (2) 2 X Eqn. (1) &#x2013; Eqn. (2)
• 14. f ( x + h) &#x2212; f ( x ) f ( x + 2h) &#x2212; f ( x ) 2 &#x2212; h 2h 2 h2 ( 3 ) 6 h3 ( 4 ) = f &#x2032;( x ) &#x2212; f ( x) &#x2212; f ( x) &#x2212; &#xF04C; 3! 4! &#x2212; f ( x + 2 h) + 4 f ( x + h) &#x2212; 3 f ( x ) 2h 2 3 2h ( 3 ) 6h ( 4 ) &#x2032;( x ) &#x2212; = f f ( x) &#x2212; f ( x) &#x2212; &#xF04C; 3! 4! = f &#x2032; ( x ) + O h2 ( )
• 15. &#x2212; f ( x + 2h ) + 4 f ( x + h ) &#x2212; 3 f ( x ) = f &#x2032;( x ) + O h2 2h ( ) &#x2212; f ( x + 2h ) + 4 f ( x + h ) &#x2212; 3 f ( x ) f &#x2032;( x ) = &#x2212; O h2 2h ( ) &#x2212; f ( x + 2h ) + 4 f ( x + h ) &#x2212; 3 f ( x ) f &#x2032;( x ) &#x2248; 2h Three-point Formula ( ) 2 h2 ( 3 ) 6 h3 ( 4 ) O h2 = &#x2212; f ( x) &#x2212; f ( x) &#x2212; &#xF04C; 3! 4!
• 16. The Second Three-point Formula Take Taylor series expansion of f(x+h) about x: h2 ( 2 ) h3 ( 3 ) f ( x + h) = f ( x ) + hf &#x2032;( x ) + f ( x) + f ( x) +&#xF04C; 2 3! Take Taylor series expansion of f(x-h) about x: 2 3 h ( 2) h ( 3) f ( x &#x2212; h) = f ( x ) &#x2212; hf &#x2032;( x ) + f ( x) &#x2212; f ( x) + &#xF04C; 2 3! Subtract one expression from another 2h 3 ( 3 ) 2h 6 ( 6 ) f ( x + h) &#x2212; f ( x &#x2212; h) = 2hf &#x2032;( x ) + f ( x) + f ( x) + &#xF04C; 3! 6!
• 17. 2h 3 ( 3 ) 2h 6 ( 6 ) f ( x + h) &#x2212; f ( x &#x2212; h) = 2hf &#x2032;( x ) + f ( x) + f ( x) + &#xF04C; 3! 6! f ( x + h) &#x2212; f ( x &#x2212; h) h2 ( 3) h5 ( 6 ) = f &#x2032;( x ) + f ( x) + f ( x) + &#xF04C; 2h 3! 6! f ( x + h) &#x2212; f ( x &#x2212; h) h 2 ( 3 ) h5 ( 6 ) f &#x2032;( x ) = &#x2212; f ( x) &#x2212; f ( x) &#x2212; &#xF04C; 2h 3! 6!
• 18. f &#x2032;( x ) = f ( x + h ) &#x2212; f ( x &#x2212; h) + O h2 2h ( ) ( ) h2 ( 3) h5 ( 6 ) O h2 = &#x2212; f ( x) &#x2212; f ( x) &#x2212; &#xF04C; 3! 6! f ( x + h) &#x2212; f ( x &#x2212; h ) f &#x2032;( x ) &#x2248; 2h Second Three-point Formula
• 19. Summary of Errors f ( x + h) &#x2212; f ( x ) f &#x2032;( x ) &#x2248; h Error term Forward Difference Formula h ( 2) h2 ( 3 ) O ( h) = f ( x ) + f ( x) +&#xF04C; 2 3!
• 20. Summary of Errors continued First Three-point Formula &#x2212; f ( x + 2h ) + 4 f ( x + h ) &#x2212; 3 f ( x ) f &#x2032;( x ) &#x2248; 2h ( ) 2 h2 ( 3 ) 6 h3 ( 4 ) Error term O h2 = &#x2212; f ( x) &#x2212; f ( x) &#x2212; &#xF04C; 3! 4!
• 21. Summary of Errors continued Second Three-point Formula f ( x + h) &#x2212; f ( x &#x2212; h ) f &#x2032;( x ) &#x2248; 2h ( ) h2 ( 3) h5 ( 6 ) O h2 = &#x2212; f ( x) &#x2212; f ( x) &#x2212; &#xF04C; Error term 3! 6!
• 22. Example: f ( x ) = xe x Find the approximate value of x f ( x) 1.9 12.703199 2.0 14.778112 2.1 2.2 17.148957 19.855030 f &#x2032;( 2 ) with h = 0.1
• 23. Using the Forward Difference formula: 1 f &#x2032; ( x0 ) &#x2248; { f ( x0 + h ) &#x2212; f ( x0 ) } h 1 f &#x2032; ( 2) &#x2248; { f ( 2.1) &#x2212; f ( 2 ) } 0.1 1 = { 17.148957 &#x2212; 14.778112} 0.1 = 23.708450
• 24. Using the 1st Three-point formula: 1 { &#x2212; 3 f ( x0 ) + 4 f ( x0 + h) &#x2212; f ( x0 + 2h) } f &#x2032;( x0 ) &#x2248; 2h 1 [ &#x2212; 3 f ( 2) + 4 f ( 2.1) &#x2212; f ( 2.2)] f &#x2032;( 2 ) &#x2248; 2 &#xD7; 0.1 1 [ &#x2212; 3 &#xD7; 14.778112 + 4 &#xD7; 17.148957 = 0.2 &#x2212; 19.855030 ] = 22.032310
• 25. Using the 2nd Three-point formula: 1 { f ( x0 + h) &#x2212; f ( x0 &#x2212; h) } f &#x2032;( x0 ) &#x2248; 2h 1 [ f ( 2.1) &#x2212; f (1.9)] f &#x2032;( 2 ) &#x2248; 2 &#xD7; 0.1 1 [ 17.148957 &#x2212; 12.703199 = 0.2 = 22.228790 The exact value of f &#x2032;( 2 ) is : 22.167168 ]
• 26. Comparison of the results with h = 0.1 The exact value of f &#x2032; ( 2 ) is 22.167168 Formula f &#x2032; ( 2) Error Forward Difference 23.708450 1.541282 1st Three-point 22.032310 0.134858 2nd Three-point 22.228790 0.061622
• 27. Second-order Derivative h2 ( 2 ) h3 ( 3 ) f ( x + h) = f ( x ) + hf &#x2032;( x ) + f ( x) + f ( x) + &#xF04C; 2 3! 2 3 h ( 2) h ( 3) f ( x &#x2212; h) = f ( x ) &#x2212; hf &#x2032;( x ) + f ( x) &#x2212; f ( x) + &#xF04C; 2 3! Add these two equations. 2h 2 ( 2 ) 2h4 ( 4 ) f ( x + h) + f ( x &#x2212; h) = 2 f ( x ) + f ( x) + f ( x) + &#xF04C; 2 4! 2h2 ( 2 ) 2 h4 ( 4 ) f ( x + h) &#x2212; 2 f ( x ) + f ( x &#x2212; h) = f ( x) + f ( x) +&#xF04C; 2 4!
• 28. f ( x + h) &#x2212; 2 f ( x ) + f ( x &#x2212; h) 2h ( 4 ) ( 2) = f ( x) + f ( x) + &#xF04C; 2 h 4! 2 f ( x + h ) &#x2212; 2 f ( x ) + f ( x &#x2212; h ) 2h 2 ( 4 ) f ( 2) ( x ) = &#x2212; f ( x) + &#xF04C; 2 h 4! f ( 2) f ( x + h) &#x2212; 2 f ( x ) + f ( x &#x2212; h) ( x) &#x2248; h2
• 29. NUMERICAL INTEGRATION b &#x222B; f ( x )dx = a area under the curve f(x) between x = a to x = b. 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.
• 30. y f(b) f(x) f(a) x 0 =a x 0 =b x
• 31. y f(b) f(x) f(a) x 0 =a x 0 =b x
• 32. 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 b &#x222B; a b&#x2212;a [ f ( a ) + f ( b )] f ( x )dx &#x2248; 2 h = [ f ( a ) + f ( b )] 2
• 33. Simpson&#x2019;s Rule: &#x222B; x2 x0 x2 f ( x )dx &#x2248; &#x222B; P ( x )dx x0 x1 = x0 + h and x 2 = x0 + 2h
• 34. &#x222B; x2 x0 P ( x ) dx = &#x222B; + &#x222B; + x2 x0 x2 x0 &#x222B; x2 x0 ( x &#x2212; x1 )( x &#x2212; x2 ) f ( x0 ) dx ( x0 &#x2212; x1 )( x0 &#x2212; x2 ) ( x &#x2212; x0 )( x &#x2212; x2 ) f ( x1 ) dx ( x1 &#x2212; x0 )( x1 &#x2212; x2 ) ( x &#x2212; x0 )( x &#x2212; x1 ) f ( x2 ) dx ( x2 &#x2212; x0 )( x2 &#x2212; x1 )
• 35. &#x222B; x2 x0 x2 f ( x )dx &#x2248; &#x222B; P ( x )dx x0 h = [ f ( x0 ) + 4 f ( x1 ) + f ( x 2 )] 3
• 36. y f(b) f(x) f(a) x 0 =a x 0 =b x
• 37. y f(b) f(x) f(a) x 0 =a x 0 =b x
• 38. y f(b) f(x) f(a) x 0 =a x 0 =b x
• 39. y f(b) f(x) f(a) x 0 =a x 0 =b x
• 40. Composite Numerical Integration
• 41. 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.
• 42. &#x2206; xIn Left Riemann = ( b &#x2212; a) / n sum, x1 = a the left- x2 x3 side sample of = afunction is the + &#x2206; x used as the = a + 2&#x2206;the x height of individual M rectangle. xi = a + ( i &#x2212; 1) &#x2206; x &#x222B; b a n f ( x ) dx &#x2248; &#x2211; f ( xi ) &#x2206; x i =1
• 43. &#x2206;x = ( b &#x2212; a) / n In Right Riemann sum, the right-side x1 = a + &#x2206; x sample of the x2 = a is used function+ 2&#x2206; x as the height of the x3 = a + 3&#x2206; x individual rectangle. M xi = a + i&#x2206; x n &#x222B; f ( x ) dx &#x2248; &#x2211; f ( x ) &#x2206; x b a i =1 i
• 44. In the ) / n &#x2206; x = ( b &#x2212; aMidpoint Rule, the sample at x1 = the (middle1of &#x2206; x / 2 ) a + 2 &#xD7;1 &#x2212; ) ( the x2 =subinterval1is( used 2 ) a + ( 2&#xD7; 2 &#x2212; ) &#x2206;x / as the height of the x3 = individual 1) ( &#x2206; x / 2 ) a + ( 2&#xD7;3&#x2212; M rectangle. xi = a + ( 2 &#xD7; i &#x2212; 1) ( &#x2206; x / 2 ) n &#x222B; f ( x ) dx &#x2248; &#x2211; f ( x ) &#x2206; x b a i =1 i
• 45. Composite Trapezoidal Rule: Divide the interval into n subintervals and apply Trapezoidal Rule in each subinterval. b &#x222B; a &#xF8F9; h&#xF8EE; f ( x )dx &#x2248; &#xF8EF; f ( a ) + 2&#x2211; f ( x k ) + f (b )&#xF8FA; 2&#xF8F0; k =1 &#xF8FB; n &#x2212;1 where b&#x2212;a h= and x k = a + kh for k = 0, 1, 2, ... , n n
• 46. &#x3C0; Find &#x222B; sin (x)dx 0 by dividing the interval into 20 subintervals. n = 20 b&#x2212;a &#x3C0; h= = n 20 k&#x3C0; x k = a + kh = , k = 0, 1, 2, ....., 20 20
• 47. &#x3C0; &#xF8F9; h&#xF8EE; &#x222B; sin( x )dx &#x2248; 2 &#xF8EF; f ( a ) + 2&#x2211; f ( xk ) + f (b)&#xF8FA; k =1 &#xF8F0; &#xF8FB; 0 n &#x2212;1 19 &#xF8F9; &#x3C0; &#xF8EE; &#xF8EB; k&#x3C0; &#xF8F6; = &#xF8EF;sin( 0 ) + 2&#x2211; sin&#xF8EC; 20 &#xF8F7; + sin( &#x3C0; ) &#xF8FA; 40 &#xF8F0; &#xF8ED; &#xF8F8; k =1 &#xF8FB; = 1.995886
• 48. Composite Simpson&#x2019;s Rule: Divide the interval into n subintervals and apply Simpson&#x2019;s Rule on each consecutive pair of subinterval. Note that n must be even. b &#x222B; a h&#xF8EE; f ( x )dx &#x2248; &#xF8EF; f ( a ) + 2 3&#xF8F0; n/ 2 + 4&#x2211; k =1 ( n / 2 ) &#x2212;1 &#x2211; f (x k =1 2k ) &#xF8F9; f ( x 2 k &#x2212;1 ) + f (b )&#xF8FA; &#xF8FB;
• 49. where b&#x2212;a h= and x k = a + kh for k = 0, 1, 2, ... , n n &#x3C0; Find &#x222B; sin (x)dx 0 by dividing the interval into 20 subintervals. b&#x2212;a &#x3C0; n = 20 h= = n 20 k&#x3C0; x k = a + kh = , k = 0, 1, 2, ....., 20 20
• 50. &#x3C0; 9 &#x3C0; &#xF8EE; &#xF8EB; 2k&#x3C0; &#xF8F6; &#x222B; sin( x )dx &#x2248; 60 &#xF8EF;sin( 0) + 2&#x2211; sin&#xF8EC; 20 &#xF8F7; &#xF8ED; &#xF8F8; k =1 &#xF8F0; 0 &#xF8F9; &#xF8EB; ( 2k &#x2212; 1)&#x3C0; &#xF8F6; + 4&#x2211; sin&#xF8EC; &#xF8F7; + sin( &#x3C0;)&#xF8FA; 20 &#xF8F8; &#xF8ED; k =1 &#xF8FB; = 2.000006 10