Lecture 12: Numericl Qudrture J.K. Ryn@tudelft.nl WI3097TU Delft Institute of Applied Mthemtics Delft University of Technology 5 December 2012 () Numericl Qudrture 5 December 2012 1 / 46
Outline 1 Review Newton-Rphson Systems of Nonliner Equtions Riemnn integrtion 2 Errors for Riemnn integrtion 3 Newton-Cotes Qudrture () Numericl Qudrture 5 December 2012 2 / 46
Newton-Rphson method We need to determine the solution to the problem: Find x such tht f (x) = 0 Assumptions f (x) C 2 [, b] (two continuous derivtives) x is n pproximtion to the root, α. f ( x) 0 x α = ɛ is smll. () Numericl Qudrture 5 December 2012 3 / 46
Newton-Rphson method By expnding f (x) in Tylor series round x, nd plugging in x = α, we hve: 0 = f (α) = f ( x)+(α x)f ( x)+ 1 2 (α x)2 f (ξ(α)), ξ(α) (α, x). This gives us the Newton-Rphson method: α = x f ( x) f ( x) () Numericl Qudrture 5 December 2012 4 / 46
Newton-Rphson method Algorithm 1 Given α 0 2 Define α n = α n 1 f (α n 1) f (α n 1 ) 3 If α n α n 1 ɛ then STOP! α = α n. 4 Else go to Step 2. () Numericl Qudrture 5 December 2012 5 / 46
Vritions to Newton s method Secnt Method (Chord Newton) Newton-Rphson, α n = α n 1 f (α n 1) f (α n 1 ) Replce f (α n 1 ) by n pproximtion, So tht α n = α n 1 f (α n 1 ) f (α n 1) f (α n 2 ) α n 1 α n 2 f (α n 1 ) f (α n 1 ) f (α n 2 ) (α n 1 α n 2 ) This is the Secnt Method () Numericl Qudrture 5 December 2012 6 / 46
Vritions to Newton s method Method of flse position Combines the ides of Chord Newton nd Bisection methods. Given two pproximtions α 0, α 1 such tht f (α 0 )f (α 1 ) < 0 : While n N 0 If qq 1 < 0 then else q 0 = f (α 0 ) q 1 = f (α 1 ), n = 2 α = α 1 q 1 (α 1 α 0 ) q 1 q 0 q = f (α), n = n + 1 α 0 = α q 0 = q α 1 = α q 1 = q () Numericl Qudrture 5 December 2012 7 / 46
Systems of Nonliner Equtions We cn write the system of equtions f 1 (x 1, x 2, x 3,..., x n ) = 0, f 2 (x 1, x 2, x 3,..., x n ) = 0, f 3 (x 1, x 2, x 3,..., x n ) = 0, f n (x 1, x 2, x 3,..., x n ) = 0, s F(x) = 0. () Numericl Qudrture 5 December 2012 8 / 46
Systems of Nonliner Equtions The Newton-Rphson method is then x (p) = x (p 1) J 1 (x (p 1) )F(x (p 1) ) where J(x) = Jcobin = f 1 f 1 x 1 x 2 f 2 f 2 x 1 x 2 f n 1 x n 1 f n x n 1 f n 1 x n f n x n () Numericl Qudrture 5 December 2012 9 / 46
Riemnn integrtion Recll from Clculus the formul for Riemnn integrtion: 1 Define prtition, P of intervl [, b] : = x 0 < x 1 < x 2 < < x n = b, where the length of the subintervls is given by h k = x k x k 1, k 1. 2 Define scttering, T, to be set of intermedite points: x k 1 t k x k, k = 1,..., n. 3 The Riemnn sum is then given by R n (f ) = n f (t k )h k. k=1 () Numericl Qudrture 5 December 2012 10 / 46
Riemnn integrtion Rectngle rule Recll tht b f (x) dx = lim n R n(f ) = lim n n f (t k )h k. k=1 where h = h k = b n. To obtin the Rectngle rule, we tke t k to be n endpoint of the subintervl. Tht is, t k = x k 1 (left endpoint) OR t k = x k (right endpoint). Then I R = h n f (x k 1 ) OR I R = h k=1 n f (x k ). k=1 () Numericl Qudrture 5 December 2012 11 / 46
Riemnn integrtion Midpoint rule For the Midpoint rule, we tke t k to be the midpoint of the subintervls: t k = 1 2 (x k 1 + x k ). The Midpoint rule is then n I M = h f (t k ). k=1 () Numericl Qudrture 5 December 2012 12 / 46
Riemnn integrtion Errors The errors for these methods re Rectngle rule: b first order method. Midpoint rule: b which is second order. f (x) dx I R 1 2 M 1(b )h, f (x) dx I M 1 24 M 2(b )h 2, But! Don t forget there is lso rounding error. () Numericl Qudrture 5 December 2012 13 / 46
Riemnn integrtion Errors Wht is the totl ffect of the errors? Let ˆf (x) = f (x) + ɛ(x) be the perturbed exct solution. Then b b (f (x) ˆf (x)) dx f (x) ˆf (x) dx ɛ mx (b ). () Numericl Qudrture 5 December 2012 14 / 46
Riemnn integrtion Errors Consider the rectngle rule, I R (f ) = h n f (x k ). k=1 In this cse, the error is b (f (x) ˆf (x)) dx b f (x) dx I R (f ) + I R (f ) I R (ˆf ) }{{}}{{} Rounding error Approximtion error 1 n 2 M 1(b )h + h f (x k ) ˆf (x k ) }{{} k=1 ɛ(x k ) () Numericl Qudrture 5 December 2012 15 / 46
Riemnn integrtion Errors The totl error is given by b (f (x) ˆf (x)) dx 1 2 M 1(b )h + h n ɛ(x k ) k=1 If we ssume ɛ(x) ɛ mx, then b (f (x) ˆf (x)) dx 1 n 2 M 1(b )h + h ɛ mx k=1 So tht b 1 2 M 1(b )h + }{{} hn ɛ mx =(b ) ( ) 1 (f (x) ˆf (x)) dx 2 M 1h + ɛ mx (b ) () Numericl Qudrture 5 December 2012 16 / 46
Qudrture Errors Remember: The pproximtion errors should dominte. 1 2 M 1h > ɛ mx h > 2 M 1 ɛ mx () Numericl Qudrture 5 December 2012 17 / 46
Qudrture Errors Assume Exct Approximte Exct f (x) ˆf (x) f (x) ɛ. Recll, the reltive error is given by b = f (x) dx b b f (x) dx ˆf (x) dx b f (x) dx b f (x) dx ɛ = Reltive error. () Numericl Qudrture 5 December 2012 18 / 46
Qudrture Errors Definition (Condition number) For numericl qudrture, the condition number is given by K I = b f (x) dx b f (x) dx. If K I >> 1, then the problem is ill-posed. () Numericl Qudrture 5 December 2012 19 / 46
Qudrture Exmple: Condition Number Exmple The profits or losses per dy of cr mnufcturer depend on the seson. Assume the following profit formuls for the first nd third qurters: w spr (t) = 0.01 + sin(π(t 1/2)), t [0, 1], w fll (t) = 0.01 + sin(π(t + 1/2)). Totl first qurter profit is given by 1 0 w spr (t) dt. Is this well-posed problem? Wht re the first nd third qurter profits if we use the rectngle rule with n = 50? () Numericl Qudrture 5 December 2012 20 / 46
Qudrture Exmple: Condition Number To find out if the problem is well-posed, we need to find the condition number: K I = 1 0 1 w spr(t) dt 0 w spr(t) dt where 1 0 w spr (t) dt = 1 (0.01 + sin(π(t 1/2))) dt 0 = 0.01t 1 0 1 π cos(π(t 1/2)) = 0.01 () Numericl Qudrture 5 December 2012 21 / 46
Qudrture Exmple: Condition Number 1 0 1 w spr (t) dt = = 0.01 + sin(π(t 1/2)) dt 0 1/2 0 1 + (0.01 + sin(π(t 1/2))) dt (0.01 + sin(π(t 1/2))) dt 1/2 ( = 0.01 + 1 ) ( + 0.01 + 1 ) π π =0.02 + 2 π 0.6566 () Numericl Qudrture 5 December 2012 22 / 46
Qudrture Exmple: Condition Number The condition number is then K I = 1 0 1 w spr(t) dt 0 w spr(t) dt = 0.6466 0.01 65.66 Lrge condition number so ill-posed. If we use the rectngle rule with n = 50, w spr = 0.01 w fll = 0.03. Probbly need bigger n. () Numericl Qudrture 5 December 2012 23 / 46
Newton-Cotes Qudrture Let us look t nother method for evluting b f (x) dx. Ide: Replce f (x) by n pproximtion nd then integrte. b f (x) dx b p(x) dx. For exmple, using liner interpolnt, we cn replce f (x) by p 1 (x) : (b x)f () + (x )f (b) p 1 (x) =. b () Numericl Qudrture 5 December 2012 24 / 46
Newton-Cotes Qudrture Then we hve the Trpezoidl rule over one domin: T 1 (f ) = b where x 1 = nd x 2 = b. p 1 (x) dx = 1 (b )(f () + f (b)). 2 () Numericl Qudrture 5 December 2012 25 / 46
Newton-Cotes Qudrture However, we cn obtin better pproximtion by breking the intervl [, b] into smller subintervls. () Numericl Qudrture 5 December 2012 26 / 46
Newton-Cotes Qudrture Define n to be the number of subintervls nd h = b n. Define the nodes to be x j = + jh, j = 0, 1,..., n. Then I(f ) = b f (x) dx = x1 x 0 f (x) dx + + n = k=1 xn 1 xk x2 x n 2 f (x) dx + x k 1 f (x) dx. x 1 f (x) dx + xn x n 1 x3 x 2 f (x) dx f (x) dx () Numericl Qudrture 5 December 2012 27 / 46
Newton-Cotes Qudrture We then use liner interpoltion for ech integrl: xk x k 1 f (x) dx x k x k 1 (f (x k 1 ) + f (x k )) = h 2 2 (f (x k 1) + f (x k )). So tht I(f ) = b f (x) dx = = n k=1 n k=1 xk x k 1 f (x) dx h 2 (f (x k 1) + f (x k )) T (f )= h n 1 2 (f (x 0) + f (x n )) + h k=1 f (x k ) which is the Trpezoidl Rule. () Numericl Qudrture 5 December 2012 28 / 46
Newton-Cotes Qudrture The error is given by b f (x) dx T (f ) (b ) h 2 f (ξ). 12 Rectngle rule is O(h). Trpezoidl rule is O(h 2 ). But require the sme mount of work, but the Trpezoidl rule is higher order. () Numericl Qudrture 5 December 2012 29 / 46
Newton-Cotes Qudrture Exmple Evlute 4 0 dx 1 + x 2 using the trpezoidl rule with two subintervls. Compre it to the exct solution. () Numericl Qudrture 5 December 2012 30 / 46
Newton-Cotes Qudrture The exct solution is given by 4 0 dx 1 + x 2 = 2 0 dx 1 + x 2 + 4 = tn 1 (4) 1.3258 2 dx 1 + x 2 () Numericl Qudrture 5 December 2012 31 / 46
Newton-Cotes Qudrture Now, let us evlute the integrl using the Trpezoidl rule with n = 2. Then Then = 0, b = 4, h = 4 0 2 = 2. x 0 = = 0, x 1 = x 0 + h = 2, x 2 = b = 4. () Numericl Qudrture 5 December 2012 32 / 46
Newton-Cotes Qudrture Then T (f ) = h n 1 2 (f (x 0) + f (x n )) + h k=1 = h 2 (f (x 0) + f (x 2 )) + hf (x 1 ) f (x k ) = 2 2 ( 1 1 + 0 2 + 1 1 + 4 2 ) + 2 1 1 + 2 2 = 1 + 1 17 + 2 5 = 124 85 1.4588 () Numericl Qudrture 5 December 2012 33 / 46
Newton-Cotes Qudrture The error is bounded by b f (x) dx T (f ) (b ) h 2 f (ξ) 12 ξ [0,4] 4 12 22 mx 16 12 2 = 8 3 2(3ξ 2 1) (1 + x 2 ) 3 }{{} = 2 t ξ=0 The ctul error is b f (x) dx T (f ) n=1 = tn 1 (4) 1.4588 = 0.1330 () Numericl Qudrture 5 December 2012 34 / 46
Qudrture Summry There re two pproches to pproximting b f (x) dx Approximting the entire intervl using the ide of re under curve: Riemnn integrtion: Rectngle nd Midpoint rule Approximting f (x) using liner interpoltion nd then integrting Trpezoidl rule. () Numericl Qudrture 5 December 2012 35 / 46
Qudrture Exmple Exmple We wnt to determine the integrl 1 1 ((10x) 3 + 0.001) dx. 1 The reltive rounding error in the function vlues is less thn ɛ. Determine the reltive error in the integrl due to rounding errors. 2 Use the composite midpoint rule s the numericl qudrture method nd ɛ < 10 8. Give resonble vlue for the step size, h. () Numericl Qudrture 5 December 2012 36 / 46
Qudrture Exmple 1. Reltive error due to rounding errors. In this exmple, = 1, b = 1, nd f (x) = (10x) 3 + 0.001. Assume f (x) ˆf (x) f (x) ɛ. Then, the reltive error is b f (x) dx b ˆf (x) dx b b f (x) dx b f (x) ˆf (x) dx b f (x) dx f (x) dx ɛ b f (x) dx = Kɛ () Numericl Qudrture 5 December 2012 37 / 46
Qudrture Exmple Reltive error = Kɛ where K = b f (x) dx b f (x) dx. This is just the condition number. Let us determine the vlue of K. () Numericl Qudrture 5 December 2012 38 / 46
Qudrture Exmple First, the numertor: b 1 f (x) dx = = (10x) 3 + 0.001 dx 1 0.01 1 + 1 ((10x) 3 + 0.001) dx 0.01 = ( 1 4 103 x 4 + 0.001x =500 ((10x) 3 + 0.001) dx ) 0.01 1 ( ) 1 1 + 4 103 x 4 + 0.001x 0.0 () Numericl Qudrture 5 December 2012 39 / 46
Qudrture Exmple Now, the denomintor: b f (x) dx = 1 ((10x) 3 + 0.001) dx 1 ( 1 1 = 4 103 x 4 + 0.001x) =0.002 1 () Numericl Qudrture 5 December 2012 40 / 46
Qudrture Exmple Therefore, the reltive error is given by b f (x) dx b ˆf (x) dx b b f (x) dx f (x) ˆf (x) dx b f (x) dx = Kɛ = 500 0.002 ɛ = 2.5 105 ɛ We cn see from the condition number tht this problem is ill-posed. () Numericl Qudrture 5 December 2012 41 / 46
Qudrture Exmple 2. Determining the step size. Let the rounding error be given by ɛ < 10 8. We need for the pproximtion error to be less thn the rounding error where f (x) ˆf (x) f (x) ɛ. Therefore the bsolute error is given through 1 1 1 f (x) dx ˆf (x) dx 1 1 f (x) dx ˆf (x) dx 1 ɛ 1 1 f (x) dx () Numericl Qudrture 5 December 2012 42 / 46
Qudrture Exmple So tht the roundoff error is 1 1 1 f (x) dx ˆf (x) dx 1 1 ɛ (10x) 3 + 0.001 dx 1 500ɛ = 2.00 10 4 if ɛ = 4 10 8. () Numericl Qudrture 5 December 2012 43 / 46
Qudrture Exmple The pproximtion error is given by where M = b 24 h2 M mx f (x) = mx 6000x. x [ 1,1] x [ 1,1] Thus, the pproximtion error is bounded by 1 f (x) dx I M (f ) 2 24 h2 6000 = 500h 2. 1 () Numericl Qudrture 5 December 2012 44 / 46
Qudrture Exmple We need to choose the step size, h, so tht the pproximtion error is less thn the rounding error: 500h 2 < 500ɛ h < ɛ = 6.32 10 4 if ɛ = 4 10 8. () Numericl Qudrture 5 December 2012 45 / 46
Mteril ddressed 1 Review Newton-Rphson Systems of Nonliner Equtions Riemnn integrtion 2 Errors for Riemnn integrtion 3 Newton-Cotes Qudrture Mteril in book: Chpter 4 Useful exercises: Ch4: 1-5 () Numericl Qudrture 5 December 2012 46 / 46