Numerical Quadrature
Total Page:16
File Type:pdf, Size:1020Kb
Numerical Integration Numerical Differentiation Richardson Extrapolation Outline 1 Numerical Integration 2 Numerical Differentiation 3 Richardson Extrapolation Michael T. Heath Scientific Computing 2 / 61 Main Ideas ❑ Quadrature based on polynomial interpolation: ❑ Methods: ❑ Method of undetermined coefficients (e.g., Adams-Bashforth) ❑ Lagrangian interpolation ❑ Rules: ❑ Midpoint, Trapezoidal, Simpson, Newton-Cotes ❑ Gaussian Quadrature ❑ Quadrature based on piecewise polynomial interpolation ❑ Composite trapezoidal rule ❑ Composite Simpson ❑ Richardson extrapolation ❑ Differentiation ❑ Taylor series / Richardson extrapolation ❑ Derivatives of Lagrange polynomials ❑ Derivative matrices Quadrature Examples b = ecos x dx •I Za Di↵erential equations: n u(x)= u φ (x) XN j j 2 j=1 X Find u(x)suchthat du r(x)= f(x) XN dx − ? Numerical Integration Quadrature Rules Numerical Differentiation Adaptive Quadrature Richardson Extrapolation Other Integration Problems Integration For f : R R, definite integral over interval [a, b] ! b I(f)= f(x) dx Za is defined by limit of Riemann sums n R = (x x ) f(⇠ ) n i+1 − i i Xi=1 Riemann integral exists provided integrand f is bounded and continuous almost everywhere Absolute condition number of integration with respect to perturbations in integrand is b a − Integration is inherently well-conditioned because of its smoothing effect Michael T. Heath Scientific Computing 3 / 61 Numerical Integration Quadrature Rules Numerical Differentiation Adaptive Quadrature Richardson Extrapolation Other Integration Problems Numerical Quadrature Quadrature rule is weighted sum of finite number of sample values of integrand function To obtain desired level of accuracy at low cost, How should sample points be chosen? How should their contributions be weighted? Computational work is measured by number of evaluations of integrand function required Michael T. Heath Scientific Computing 4 / 61 Numerical Integration Quadrature Rules Numerical Differentiation Adaptive Quadrature Richardson Extrapolation Other Integration Problems Quadrature Rules An n-point quadrature rule has form n Qn(f)= wi f(xi) Xi=1 Points xi are called nodes or abscissas Multipliers wi are called weights Quadrature rule is open if a<x1 and xn <b closed if a = x1 and xn = b Can also have (x x … x ) a < b (Adams-Bashforth timesteppers) • 1 2 n · Michael T. Heath Scientific Computing 5 / 61 Numerical Integration Quadrature Rules Numerical Differentiation Adaptive Quadrature Richardson Extrapolation Other Integration Problems Quadrature Rules, continued Quadrature rules are based on polynomial interpolation Integrand function f is sampled at finite set of points Polynomial interpolating those points is determined Integral of interpolant is taken as estimate for integral of original function In practice, interpolating polynomial is not determined explicitly but used to determine weights corresponding to nodes If Lagrange is interpolation used, then weights are given by b wi = `i(x),i=1,...,n Za Michael T. Heath Scientific Computing 6 / 61 Numerical Integration Quadrature Rules Numerical Differentiation Adaptive Quadrature Richardson Extrapolation Other Integration Problems Method of Undetermined Coefficients Alternative derivation of quadrature rule uses method of undetermined coefficients To derive n-point rule on interval [a, b], take nodes x1,...,xn as given and consider weights w1,...,wn as coefficients to be determined Force quadrature rule to integrate first n polynomial basis functions exactly, and by linearity, it will then integrate any polynomial of degree n 1 exactly − Thus we obtain system of moment equations that determines weights for quadrature rule Michael T. Heath Scientific Computing 7 / 61 Quadrature Overview b n I(f):= f(t) dt w f , =: Q (f) f := f(t ) ⇡ i i n i i a i=1 Z X Idea is to minimize the number of function evaluations. • Small n is good. • Several strategies: • – global rules – composite rules – composite rules + extrapolation – adaptive rules 1 Global (Interpolatory) Quadrature Rules Generally, approximate f(t)bypolynomialinterpolant,p(t). • n f(t) p(t)= l (t) f ⇡ i i i=1 X b b I(f)= f(t) dt p(t) dt =: Q (f) ⇡ n Za Za b n n b n Qn(f)= li(t) fi dt = li(t) dt fi = wi fi. a i=1 ! i=1 a i=1 Z X X ✓Z ◆ X b wi = li(t) dt Za We will see two types of global (interpolatory) rules: • – Newton-Cotes — interpolatory on uniformly spaced nodes. – Gauss rules — interpolatory on optimally chosen point sets. 2 Examples Midpoint rule: l (t)=1 • i b b w = l (t) dt = 1 dt =(b a) 1 1 − Za Za Trapezoidal rule: • t b t a l (t)= − ,l(t)= − 1 a b 2 b a − − b b w = l (t) dt = 1(b a)= l (t) dt = w 1 1 2 − 2 2 Za Za Simpson’s rule: • b b b a w1 = l1(t) dt = −6 = l3(t) dt = w3 Za Za b b t a t b 2 w = l (t) dt = − − dt = (b a) 2 2 b a a b 3 − Za Za ✓ − ◆✓ − ◆ These are the Newton-Cotes quadrature rules for n=1, 2, and 3, • respectively. – The midpoint rule is open. – Trapezoid and Simpson’s rules are closed. 3 Finding Weights: Method of Undetermined Coefficients METHOD OF UNDETERMINED COEFFICIENTS Example 1: Find wi for [a, b]=[1, 2], n =3. First approach: f =1,t,t2. • 3 I(1) = w 1=1 i · i=1 X 3 1 2 I(t)= w t = t2 i · i 2 i=1 1 X 3 1 2 I(t2)= w t2 = t3 i · i 3 i=1 1 X Results in 3 3matrixforthew s. ⇥ i Second approach: Choose f so that some of the coefficients multiplying • the wisvanish. 3 2 3 I = w (1 )(1 2) = (t )(t 2) dt 1 1 − 2 − − 2 − Z1 3 3 2 I = w ( 1)( 2) = (t 1)(t 2) dt 2 2 2 − 2 − − − Z1 3 2 3 I = w (2 1)(2 )= (t 1)(t ) dt 3 3 − − 2 − − 2 Z1 Corresponds to the Lagrange interpolant approach. 5 METHOD OF UNDETERMINED COEFFICIENTS Example 1: Find wi for [a, b]=[1, 2], n =3. First approach: f =1,t,t2. • 3 I(1) = w 1=1 i · i=1 X 3 1 2 I(t)= w t = t2 i · i 2 i=1 1 X 3 1 2 I(t2)= w t2 = t3 i · i 3 Finding Weights: Method ofi=1 Undetermined1 Coefficients X Results in 3 3matrixforthew s. ⇥ i Second approach: Choose f so that some of the coefficients multiplying • the wisvanish. 3 2 3 I = w (1 )(1 2) = (t )(t 2) dt 1 1 − 2 − − 2 − Z1 3 3 2 I = w ( 1)( 2) = (t 1)(t 2) dt 2 2 2 − 2 − − − Z1 3 2 3 I = w (2 1)(2 )= (t 1)(t ) dt 3 3 − − 2 − − 2 Z1 Corresponds to the Lagrange interpolant approach. 5 Method of Undetermined Coefficients Example 2: Find wi for [a, b]=[0, 1], n =3,butusingfi = f(ti)=f(i), with i =-2,-1,and0.(Theti’s are outside the interval (a, b).) Result should be exact for f(t) lP ,lP,andlP. • 2 0 1 2 Take f=1, f=t,andf=t2. • 1 wi =1= 1 dt 0 X Z 1 1 2w 2 w 1 = = tdt − − − − 2 Z0 1 1 2 4w 2 + w 1 = = t dt − − 3 Z0 Find • 5 16 23 w 2 = w 1 = w0 = . − 12 − − 12 12 This example is useful for finding integration coefficients for explicit time- • stepping methods that will be seen in later chapters. 6 Numerical Integration Quadrature Rules Numerical Differentiation Adaptive Quadrature Richardson Extrapolation Other Integration Problems Example: Undetermined Coefficients Derive 3-point rule Q3(f)=w1f(x1)+w2f(x2)+w3f(x3) on interval [a, b] using monomial basis Take x1 = a, x2 =(a + b)/2, and x3 = b as nodes First three monomials are 1, x, and x2 Resulting system of moment equations is b w 1+w 1+w 1= 1 dx = x b = b a 1 · 2 · 3 · |a − Za b w a + w (a + b)/2+w b = xdx=(x2/2) b =(b2 a2)/2 1 · 2 · 3 · |a − Za b w a2 + w ((a + b)/2)2 + w b2 = x2 dx =(x3/3) b =(b3 a3)/3 1 · 2 · 3 · |a − Za Michael T. Heath Scientific Computing 8 / 61 Numerical Integration Quadrature Rules Numerical Differentiation Adaptive Quadrature Richardson Extrapolation Other Integration Problems Example, continued In matrix form, linear system is 111w b a 1 − a (a + b)/2 b w = (b2 a2)/2 2 3 2 23 2 − 3 a2 ((a + b)/2)2 b2 w (b3 a3)/3 3 − 4 5 4 5 4 5 Solving system by Gaussian elimination, we obtain weights b a 2(b a) b a w = − ,w= − ,w= − 1 6 2 3 3 6 which is known as Simpson’s rule Michael T. Heath Scientific Computing 9 / 61 Numerical Integration Quadrature Rules Numerical Differentiation Adaptive Quadrature Richardson Extrapolation Other Integration Problems Method of Undetermined Coefficients More generally, for any n and choice of nodes x1,...,xn, Vandermonde system 11 1 w1 b a ··· 2 − 2 x1 x2 xn w2 (b a )/2 2 . ···. 3 2 . 3 = 2 −. 3 . .. 6 n 1 n 1 n 17 6 7 6 n n 7 6x − x − x 7 6wn7 6(b a )/n7 6 1 2 ··· n− 7 6 7 6 − 7 4 5 4 5 4 5 determines weights w1,...,wn Michael T. Heath Scientific Computing 10 / 61 Numerical Integration Quadrature Rules Numerical Differentiation Adaptive Quadrature Richardson Extrapolation Other Integration Problems Stability of Quadrature Rules Absolute condition number of quadrature rule is sum of magnitudes of weights, n w | i| Xi=1 If weights are all nonnegative, then absolute condition number of quadrature rule is b a, same as that of − underlying integral, so rule is stable If any weights are negative, then absolute condition number can be much larger, and rule can be unstable Michael T.