Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Numerical Methods What computers can’t do • Solve (by reasoning) general mathematical problems they can only repetitively apply arithmetic primitives to input. • Solve problems exactly. • Represent all numbers. Only a finite subset of the numbers between 0 and 1 can be represented. Numerical Integration • In NA, take visual view of integration as area under the curve • Many integrals that occur in science or engineering practice do not have a closed form solution – must be solved using numerical integration Trapezoidal Rule • The area under the curve from [a, fa] to [b, fb] is initially approximated by a trapezoid: I1 = ( b – a ) * ( fa + fb ) / 2 Simple trapezoid over large interval is prone to error. Divide interval into halves… fc I2 = ( b – a )/2 * ( fa + 2*fc + fb ) / 2 (Note that interior sides count twice, since they belong to 2 traps.) Trapezoidal rule b a f ( x)dx x Tn [ f ( x0 ) 2 f ( x1 ) 2 f ( x2 ) 2 f ( xn 1 ) f ( xn )] 2 ba where x and xi a i x n This gives us a better approximation than either left or right rectangles. Example Single Application of the Trapezoidal Rule f(x) = 0.2 +25x – 200x2 + 675x3 – 900x4 + 400x5 Integrate f(x) from a=0 to b=0.8 b 0.8 True integral value : I f ( x )dx 1.64053 a 0 Solution: f(a)=f(0) = 0.2 and f(b)=f(0.8) = 0.232 f (a ) f (b) 2 0.2 0.232 0.8 0.1728 2 Trapezoida l Rule : I ( b a ) which represents an error of : E t 1.64053 0.1728 1.46773 t 89.5% Simpson’s rule • • • • .. Another approach Rather than use straight line of best fit, Use parabola of best fit (curves) Converges more quickly Simpson’s Rules • More accurate estimate of an integral is obtained if a high-order polynomial is used to connect the points. These formulas are called Simpson’s rules. Simpson’s 1/3 Rule: results when a 2nd order Lagrange interpolating polynomial is used for f(x) a=x0 b b=x2 b I f ( x)dx f 2 ( x)dx a Using x1 where f 2 ( x ) is a second - order polynomial. a a x0 b x2 ( x x1 )( x x2 ) ( x x0 )( x x2 ) ( x x0 )( x x1 ) I f ( x0 ) f ( x1 ) f ( x2 )dx ( x x )( x x ) ( x x )( x x ) ( x x )( x x ) 0 1 0 2 1 0 1 2 2 0 2 1 x0 x2 after integratio n and algebraic manipulation, the following formula results : I h f ( x0 ) 4 f ( x1 ) f ( x2 ) 3 h ba 2 SIMPSON'S 1/3 RULE The Multiple-Application Simpson’s 1/3 Rule • Just as the trapezoidal rule, Simpson’s rule can be improved by dividing the integration interval into a number of segments of equal width. • However, it is limited to cases where values are equispaced, there are an even number of segments and odd number of points. h I ba n x2 x0 I n # of seg. a x0 x4 f ( x)dx f ( x)dx 0 2 x2 b xn xn f n 2 ( x)dx xn2 h f ( x0 ) 4 f ( x1 ) f ( x2 ) 3 h f ( x2 ) 4 f ( x3 ) f ( x4 ) 3 h f ( xn 2 ) 4 f ( xn 1 ) f ( xn ) 3 n 1 n2 h I f ( x0 ) 4 f ( xi ) 2 f ( x j ) f ( xn ) 3 i 1, 3, 5... j 2, 4, 6... Simpson’s rule b a f ( x)dx x Sn [ f ( x0 ) 4 f ( x1 ) 2 f ( x2 ) 4 f ( x3 ) 3 2 f ( xn 2 ) 4 f ( xn 1 ) f ( xn )] ba where n is even and x n Simpson’s rule can also be interpreted as fitting parabolas to sections of the curve. Simpson’s rule will usually give a very good approximation with relatively few subintervals. Simpson’s 3/8 Rule Fit a 3rd order Lagrange interpolating polynomial to four points and integrate b b a a Simpson’s 1/3 and 3/8 rules can be applied in tandem to handle multiple applications with odd number of intervals I f ( x)dx f 3 ( x)dx 3h I f ( x0 ) 3 f ( x1 ) 3 f ( x2 ) f ( x3 ) 8 (b a ) h 3 I (b a) f ( x0 ) 3 f ( x1 ) 3 f ( x2 ) f ( x3 ) 8 13 Rn APPROXIMATIONEquation 2 • If we choose xi* to be the right endpoint, xi* = xi and we have: b a n f ( x) dx Rn f ( xi ) x – The approximation Rn is called right endpoint approximation. i 1 • The M figure shows APPROXIMATION n the midpoint approximation Mn. THE MIDPOINT RULE b a f ( x) dx M n x [ f ( x1 ) f ( x 2 ) ... f ( x n )] • wherex b a n and xi 12 ( xi 1 xi ) midpoint of [ xi 1 , xi ] APPROXIMATE INTEGRATION • Approximate the integral with n = 5, using: a. Trapezoidal Rule Example 1 2 1 • b. Midpoint Rule (1/ x) dx APPROXIMATE INTEGRATION Example 1 a • With n = 5, a = 1 and b = 2, we have: ∆x = (2 – 1)/5 = 0.2 – So, the Trapezoidal Rule gives: 2 1 1 0.2 dx T5 [ f (1) 2 f (1.2) 2 f (1.4) x 2 2 f (1.6) 2 f (1.8) f (2)] 2 2 2 1 1 2 0.1 1 1.2 1.4 1.6 1.8 2 0.695635 APPROXIMATE INTEGRATION Example 1 b • The midpoints of the five subintervals are: 1.1, 1.3, 1.5, 1.7, 1.9 APPROXIMATE Example 1 b INTEGRATION • So, the Midpoint Rule gives: 2 1 1 dx x [ f (1.1) f (1.3) f (1.5) x f (1.7) f (1.9)] 1 1 1 1 1 1 5 1.1 1.3 1.5 1.7 1.9 0.691908 ERROR ESTIMATES Example 3 a. Use the Midpoint Rule with n = 10 to 1 2 approximate the integral x 0 e dx. b. Give an upper bound for the error involved in this approximation. Example 3 a ERROR ESTIMATES • As a = 0, b = 1, and n = 10, the Midpoint Rule gives: 1 e 0 x2 dx x [ f (0.05) f (0.15) ... f (0.85) f (0.95)] e e e e e 0.1 0.3025 0.4225 0.5625 0.7225 0.9025 e e e e e 1.460393 0.0025 0.0225 0.0625 0.1225 0.2025