Lecture 17 Integrtion: Guss Qudrture Dvid Semerro University of Illinois t Urbn-Chmpign Mrch 0, 014 Dvid Semerro (NCSA) CS 57 Mrch 0, 014 1 / 9
Tody: Objectives identify the most widely used qudrture method is it chep? is it effective? how does it compre to Newton-Cotes (Trpezoid, Simpson, etc)? Mteril Section 5.4 Dvid Semerro (NCSA) CS 57 Mrch 0, 014 / 9
Qudrture up until now, our qudrture methods were of the form f (x) dx n w j f (x j ) j=0 where x j re eqully spced nodes Trpezoid: Simpson: f (x) dx b 6 f (x) dx b f () + b f (b) (b ) f () + f ( + b Similr for higher order polynomil Newton-Cotes rules ) + b 6 f (b) Dvid Semerro (NCSA) CS 57 Mrch 0, 014 / 9
Qudrture with Freedom! These qudrture rules hve one thing in common: they re restrictive e.g. Simpson: f (x) dx b 6 (b ) f () + f ( + b ) + b 6 f (b) Trpezoid, Simpson, etc (Newton-Cotes) re bsed on eqully spced nodes We know one thing lredy from interpoltion: eqully spced nodes result in wiggle. Wht other choice do we hve? (...recll how we fixed wiggle in interpoltion: by moving the loction of the nodes) Dvid Semerro (NCSA) CS 57 Mrch 0, 014 4 / 9
Gussin Qudrture free ourselves from eqully spced nodes combine selection of the nodes nd selection of the weights into one qudrture rule Gussin Qudrture Choose the nodes nd coefficients optimlly to mximize the degree of precision of the qudrture rule: f (x) dx n w j f (x j ) j=0 Gol Seek w j nd x j so tht the qudrture rule is exct for relly high polynomils Dvid Semerro (NCSA) CS 57 Mrch 0, 014 5 / 9
Gussin Qudrture f (x) dx n w j f (x j ) j=0 we hve n + 1 points x j [, b], x 0 < x 1 < < x n < x n b. we hve n + 1 rel coefficients w j so there re n + totl unknowns to tke cre of there were only unknowns in the cse of trpezoid ( weights) there were only unknowns in the cse of Simpson ( weights) there were only n + 1 unknowns in the cse of generl Newton-Cotes (n + 1 weights) Dvid Semerro (NCSA) CS 57 Mrch 0, 014 6 / 9
Gussin Qudrture f (x) dx n w j f (x j ) j=0 we hve n + 1 points x j [, b], x 0 < x 1 < < x n < x n b. we hve n + 1 rel coefficients w j so there re n + totl unknowns to tke cre of there were only unknowns in the cse of trpezoid ( weights) there were only unknowns in the cse of Simpson ( weights) there were only n + 1 unknowns in the cse of generl Newton-Cotes (n + 1 weights) n + unknowns (using n + 1 nodes) cn be used to exctly interpolte nd integrte polynomils of degree up to n + 1 Dvid Semerro (NCSA) CS 57 Mrch 0, 014 6 / 9
Better Nodes Exmple The first thing we do is SIMPLIFY consider the cse of n = 1 (-point) consider [, b] = [, 1] for simplicity we know how the trpezoid rule works Question: cn we possibly do better using only function evlutions? Gol: Find w 0, w 1, x 0, x 1 so tht is s ccurte s possible... f (x) dx w 0 f (x 0 ) + w 1 f (x 1 ) Dvid Semerro (NCSA) CS 57 Mrch 0, 014 7 / 9
Grphicl View Consider x + 1 dx = 4.75 1 Dvid Semerro (NCSA) CS 57 Mrch 0, 014 8 / 9
Derive... Agin, we re considering [, b] = [, 1] for simplicity: f (x) dx w 0 f (x 0 ) + w 1 f (x 1 ) Gol: find w 0, w 1, x 0, x 1 so tht the pproximtion is exct up to cubics. So try ny cubic: This implies tht: f (x) = c 0 + c 1 x + c x + c x f (x) dx = ( c0 + c 1 x + c x + c x ) dx ( = w 0 c0 + c 1 x 0 + c x 0 + c x0) + ( ) w 1 c0 + c 1 x 1 + c x 1 + c x 1 Dvid Semerro (NCSA) CS 57 Mrch 0, 014 9 / 9
Derive... f (x) dx = ( c0 + c 1 x + c x + c x ) dx ( = w 0 c0 + c 1 x 0 + c x 0 + c x0) + ( ) w 1 c0 + c 1 x 1 + c x 1 + c x 1 Rerrnge into constnt, liner, qudrtic, nd cubic terms: ) 1 c 0 (w 0 + w 1 dx c (w 0 x 0 + w 1 x 1 x dx ) ) 1 + c 1 (w 0 x 0 + w 1 x 1 x dx + ( ) 1 + c w 0 x 0 + w 1 x 1 x dx = 0 Since c 0, c 1, c nd c re rbitrry, then their coefficients must ll be zero. Dvid Semerro (NCSA) CS 57 Mrch 0, 014 10 / 9
Derive... This implies: w 0 + w 1 = w 0 x 0 + w 1 x 1 = Some lgebr leds to: dx = w 0 x 0 + w 1 x 1 = x dx = x dx = 0 w 0 x 0 + w 1 x 1 = x dx = 0 Therefore: w 0 = 1 w 1 = 1 x 0 = x 1 = ( ) ( ) f (x) dx f + f Dvid Semerro (NCSA) CS 57 Mrch 0, 014 11 / 9
Over nother intervl? ( ) ( ) f (x) dx f + f f (x) dx? integrting over [, b] insted of [, 1] needs trnsformtion: chnge of vribles wnt t = c 1 x + c 0 with t = t x = nd t = 1 t x = b let t = b x b+ b (verify) let x = b t + b+ then dx = b dt Dvid Semerro (NCSA) CS 57 Mrch 0, 014 1 / 9
Over nother intervl? f (x) dx? let x = b t + b+ then dx = b dt f (x) dx = now use the qudrture formul over [, 1] ( ) (b )t + b + b f dt note: using two points, n = 1, gve us exct integrtion for polynomils of degree less *1+1 = nd less. Dvid Semerro (NCSA) CS 57 Mrch 0, 014 1 / 9
Over nother intervl? Previous exmple... 1 x + 1 dx = 4.75 1 f (x)dx = 1 [ 1 f ( ) t + f dt ( ) + + f ( )] where x = +t Dvid Semerro (NCSA) CS 57 Mrch 0, 014 14 / 9
Over nother intervl? Evluting... 1 [ x + 1 dx 1 f [ ( 1 f 1 x + 1 dx ( + 9 + 6 ) ) + f + f ( ( 9 6 )] )] 1 [f (1.788651) + f (1.115)] 1 [6.78 +.77787] = 4.749885 where f (x) = x + 1 Dvid Semerro (NCSA) CS 57 Mrch 0, 014 15 / 9
Extending Guss Qudrture we need more to mke this work for more thn two points A sensible qudrture rule for the intervl [, 1] bsed on 1 node would use the node x = 0. This is root of φ(x) = x Notice: ± 1 re the roots of φ(x) = x 1 generl φ(x)? Dvid Semerro (NCSA) CS 57 Mrch 0, 014 16 / 9
Guss Qudrture Theorem Krl Friedrich Guss proved the following result: Let q(x) be nontrivil polynomil of degree n + 1 such tht x k q(x)dx = 0 (0 k n) nd let x 0, x 1,..., x n be the zeros of q(x). Then f (x)dx n A i f (x i ), A i = i=0 l i (x)dx will be exct for ll polynomils of degree t most n + 1. Dvid Semerro (NCSA) CS 57 Mrch 0, 014 17 / 9
Sketch of Proof Let f (x) be polynomil of degree n + 1. Then we cn write f (x) = p(x)q(x) + r(x), where p(x) nd r(x) re of degree t most n (This is bsiclly dividing f by q with reminder r). Then by the hypothesis, p(x)q(x)dx = 0. Further, f (x i ) = p(x i )q(x i ) + r(x i ) = r(x i ). Thus, f (x)dx = r(x)dx n f (x i ) i=0 l i (x)dx But this is exct becuse r(x) is (t most) degree n polynomil. Thus, we need to find the polynomils q(x). Dvid Semerro (NCSA) CS 57 Mrch 0, 014 18 / 9
Orthogonl Polynomils Orthogonlity of Functions Two functions g(x) nd h(x) re orthogonl on [, b] if g(x)h(x) dx = 0 so the nodes we re using re roots of orthogonl polynomils these re the Legendre Polynomils Dvid Semerro (NCSA) CS 57 Mrch 0, 014 19 / 9
Legendre Polynomils given on the exm φ 0 = 1 φ 1 = x φ = x 1 φ = 5x x. In generl: φ n (x) = n 1 n xφ n (x) n 1 n φ n (x) Dvid Semerro (NCSA) CS 57 Mrch 0, 014 0 / 9
1 0.75 0.5 0.5 1-0.75-0.5-0.5 0 0.5 0.5 0.75 1-0.5-0.5-0.75-1 Notes on Legendre Roots The Legendre Polynomils re orthogonl (nice!) The Legendre Polynomils increse in polynomils order (like monomils) The Legendre Polynomils don t suffer from poor conditioning (unlike monomils) The Legendre Polynomils don t hve closed form expression (recursion reltion is needed) The roots of the Legendre Polynomils re the nodes for Gussin Qudrture (GL nodes) Dvid Semerro (NCSA) CS 57 Mrch 0, 014 1 / 9
Qudrture Nodes (see) Often listed in tbles Weights determined by extension of bove Roots re symmetric in [, 1] Exmple: 1 if(n==0) x = 0; w = ; if(n==1) 4 x(1) = -1/sqrt(); x() = -x(1); 5 w(1) = 1; w() = w(1); 6 if(n==) 7 x(1) = -sqrt(/5); x() = 0; x() = -x(1); 8 w(1) = 5/9; w() = 8/9; w() = w(1); 9 if(n==) 10 x(1) = -0.861161159405; x(4) = -x(1); 11 x() = -0.998104584856; x() = -x(); 1 w(1) = 0.4785484517454; w(4) = w(1); 1 w() = 0.6514515486546; w() = w(); 14 if(n==4) 15 x(1) = -0.90617984598664; x(5) = -x(1); 16 x() = -0.584691010568; x(4) = -x(); 17 x() = 0; 18 w(1) = 0.696885056189; w(5) = w(1); 19 w() = 0.4786867049966; w(4) = w(); 0 w() = 0.568888888888889; 1 if(n==5) x(1) = -0.9469514015; x(6) = -x(1); x() = -0.661098646665; x(5) = -x(); 4 x() = -0.861918608197; x(4) = -x(); 5 w(1) = 0.17144979170; w(6) = w(1); 6 w() = 0.607615704819; w(5) = w(); 7 w() = 0.467919457691; w(4) = w(); Dvid Semerro (NCSA) CS 57 Mrch 0, 014 / 9
View of Nodes Order 1.0000 1.0000 Order 0.5556 0.8889 0.5556 Order 4 0.479 0.651 0.651 0.479 Order 5 0.69 0.4786 0.5689 0.4786 0.69 Order 6 0.171 0.608 0.4679 0.4679 0.608 0.171-1 -0.5 0 0.5 1 Dvid Semerro (NCSA) CS 57 Mrch 0, 014 / 9
Theory The connection between the roots of the Legendre polynomils nd exct integrtion of polynomils is estblished by the following theorem. Theorem Suppose tht x 0, x 1,..., x n re roots of the nth Legendre polynomil P n (x) nd tht for ech i = 0, 1,..., n the numbers w i re defined by w i = n j = 0 j i x x 1 j dx = l i (x) dx x i x j Then f (x)dx = n w i f (x i ), where f (x) is ny polynomil of degree less or equl to n + 1. i=0 Dvid Semerro (NCSA) CS 57 Mrch 0, 014 4 / 9
Do not!!!! When evluting qudrture rule f (x)dx = n w i f (x i ). i=0 do not generte the nodes nd weights ech time. Use lookup tble... Dvid Semerro (NCSA) CS 57 Mrch 0, 014 5 / 9
Exmple.5 Approximte x ln x dx using Gussin qudrture with n = 1. 1 ( 1 ) ( ) Solution As derived erlier we wnt to use f (x) dx f + f From erlier we know tht we re interested in.5 ( ) (1.5 1)t + (1.5 + 1) 1.5 1 f (x) dx = f dt 1 Therefore, we re looking for the integrl of 1 1 ( ) x + 5 f dx = 1 ( ) ( ) x + 5 x + 5 ln dx 4 4 4 4 4 Using Gussin qudrture, our numericl integrtion becomes: ( ) ( ) ( ) ( ) 1 + 5 + 5 + 5 + 5 ln + ln = 0.19687 4 4 4 4 4 Dvid Semerro (NCSA) CS 57 Mrch 0, 014 6 / 9
Exmple Approximte 0 x e x dx using Gussin qudrture with n = 1. Solution We gin wnt to convert our limits of integrtion to -1 to 1. Using the sme process s the erlier exmple, we get: 0 x e x dx = 1 ( ) t + 1 e (t+1)/ dt. Using the Gussin roots we get: ( 1 x e x dx 1 + 1 0 ) ( e ( +1)/ + + 1 ) e ( +1)/ = 0.1594104 Dvid Semerro (NCSA) CS 57 Mrch 0, 014 7 / 9
Numericl Question How does n point Guss qudrture compre with n point Newton-Cotes... Dvid Semerro (NCSA) CS 57 Mrch 0, 014 8 / 9
Exmples with Python... Exmple int guss.py: bse routine for Guss qudrture Exmple int guss test.py: integrte 5 0 xe x dx with 1 1 subintervl, incresing number of nodes nodes, increses number of intervls (pnels) Result: fewer totl evlutions in GL qudrture with 1 subintervl nd mny nodes versus nodes nd mny subpnels. Also more ccurte. Dvid Semerro (NCSA) CS 57 Mrch 0, 014 9 / 9