Numerical Integration of Functions Chapter 18 Numerical Integration of Functions
Numerical Integration Tabulated data – the accuracy of the integral is limited by the number of data points Continuous function – we can generate as many f(x) as required to attain the required accuracy Richardson extrapolation and Romberg integration Gauss Quadratures
Round-off errors may limit the precision of lower-order Newton-Cotes composite integration formula Use Romberg Integration for efficient integration
Romberg Integration More efficient methods to achieve better accuracy have been developed Romberg integration - uses Richardson extrapolation Idea behind Richardson extrapolation -improve the estimate by eliminating the leading term of truncation error at coarser grid levels
Richardson Extrapolation The exact integral can be represented as This is true for any h = (ba)/n Use trapezoidal rule as an example
Composite Trapezoidal Rule Evaluate the integral
Richardson Extrapolation Truncation error for trapezoidal rule Substitute into the exact integral Which leads to
Richardson Extrapolation Plugging back into I = I(h) + E(h) If h2 = h1/2, then
Richardson Extrapolation Combine two O(h2) estimates to get an O(h4) estimate Can also combine two O(h4) estimates to get an O(h6) estimate Combine two O(h6) estimates to get an O(h8) estimate Im and Il are more and less accurate estimates, respectively
Romberg Integration General form is called Romberg Integration j: level of accuracy - j+1 is more accurate (more segments) k: level of integration - k=1 is the original trapezoidal rule estimate (O(h2)), k=2 is improved (O(h4)), k=3 corresponds to O(h6), etc.
Romberg Integration Accelerated Trapezoidal Rule
Romberg Integration Accelerated Trapezoid Rule
Accelerated trapezoidal Rule Romberg Integration Accelerated trapezoidal Rule
» intg = romberg(‘example1’,0,pi,0.00001,2) 0.0000 0.0000 -5.5122 0.0000 -5.1677 0 -3.8758 0 0 » intg = Romberg(‘example1’,0,pi,0.00001,3) 0.0000 0.0000 -5.5122 -4.9221 0.0000 -5.1677 -4.9313 0 -3.8758 -4.9461 0 0 -4.6785 0 0 0 » intg = romberg(‘example1’,0,pi,0.00001,4) 0.0000 0.0000 -5.5122 -4.9221 -4.9349 0.0000 -5.1677 -4.9313 -4.9348 0 -3.8758 -4.9461 -4.9348 0 0 -4.6785 -4.9355 0 0 0 -4.8712 0 0 0 0 » intg = romberg(‘example1’,0,pi,0.00001,6) 0.0000 0.0000 -5.5122 -4.9221 -4.9349 -4.9348 -4.9348 0.0000 -5.1677 -4.9313 -4.9348 -4.9348 -4.9348 0 -3.8758 -4.9461 -4.9348 -4.9348 -4.9348 0 0 -4.6785 -4.9355 -4.9348 -4.9348 0 0 0 -4.8712 -4.9348 -4.9348 0 0 0 0 -4.9189 -4.9348 0 0 0 0 0 -4.9308 0 0 0 0 0
CVEN 302-501 Homework No. 12 Chapter 17 Problem 17.3 (25), 17.5 (25)– Hand Calculation Chapter 18 Problem 18.2 (25), 18.4 (25) Due on Monday, 11/17/2008 at the beginning of the period
Gauss Quadrature Assume a and b are limits of integration Trapezoidal rule should give exact results for constant and linear functions
Trapezoidal rule gives exact solution for constant and linear functions
Gauss Quadrature Now instead of trapezoidal, which has fixed end points (a,b), let them float 4 unknowns - x0 ,x1 ,c0 ,c1 4 equations - constant, linear (had before in trapezoidal rule), quadratic, cubic Integrate from -1 to 1 to simplify math
Trapezoidal vs. Gauss-Quadrature Exact for constant and linear functions Exact for constant, linear, quadratic and cubic functions
Gauss Quadrature The idea is that if we evaluate the function at certain points (non-uniformly distributed), and sum with certain weights, we will get accurate integral Evaluation points and weights are tabulated
Gauss-Legendre Quadrature Choose (c0 , c1 , x0 , x1) to yield highest possible accuracy
Gauss Quadratures Newton-Cotes Formulas use evenly-spaced functional values Gauss Quadratures (Gauss-Legendre formulas) change of variables so that the interval of integration is [1,1] select functional values at non-uniformly distributed points to achieve higher accuracy
Gauss Quadrature on [a, b] To go to [1,1] from other limits [a,b] - use linear transformation Change from a x b to 1 xd 1 Coordinate transformation
Gauss Quadrature on [a, b] Coordinate transformation from [a,b] to [1,1] a t1 t2 b
Gauss Quadrature on [1, 1] x0 x1 -1 1 Choose (c0 , c1 , x0 , x1) such that the method yields “exact integral” for f(x) = x0, x1, x2, x3
Gauss Quadrature on [1, 1] Exact integral for f = x0, x1, x2, x3 Four equations for four unknowns
Gauss Quadrature on [1, 1] x0 x1 x2 -1 1 Choose (c0, c1, c2, x0, x1, x2) such that the method yields “exact integral” for f(x) = x0, x1, x2, x3,x4, x5
Gauss Quadrature on [1, 1] Exact integral for f = x0, x1, x2, x3, x4, x5
Example: Gauss Quadrature Evaluate Coordinate transformation Two-point formula
Example: Gauss Quadrature Three-point formula Four-point formula
Gauss-Legendre Formulas
Gauss Quadrature
Gauss Quadrature k = 2 Exact Q = -4.9348 » I=Gauss_quad(‘example1’,0,pi,2); t = -0.5774 -0.7746 -0.8611 -0.9062 0.5774 0 -0.3400 -0.5385 0 0.7746 0.3400 0 0 0 0.8611 0.5385 0 0 0 0.9062 c = 1.0000 0.5556 0.3479 0.2369 1.0000 0.8889 0.6521 0.4786 0 0.5556 0.6521 0.5689 0 0 0.3479 0.4786 0 0 0 0.2369 tt = -0.5774 0.5774 cd = 1 » I I = -8.6878 » Q=quad8(‘example1’,0,pi) Q = -4.9348 k = 2 Exact Q = -4.9348
Gauss Quadrature k = 5 Exact Q = -4.9348 » I=Gauss_quad(‘example1’,0,pi,5); t = -0.5774 -0.7746 -0.8611 -0.9062 0.5774 0 -0.3400 -0.5385 0 0.7746 0.3400 0 0 0 0.8611 0.5385 0 0 0 0.9062 c = 1.0000 0.5556 0.3479 0.2369 1.0000 0.8889 0.6521 0.4786 0 0.5556 0.6521 0.5689 0 0 0.3479 0.4786 0 0 0 0.2369 tt = -0.9062 -0.5385 0.5385 0.9062 cd = 0.2369 0.4786 0.5689 » I I = -4.9333 Gauss Quadrature k = 5 Exact Q = -4.9348
Adaptive Quadrature Composite Simpson’s 1/3 rule requires the use of equally spaced points Use adaptive refinement in regions of relatively abrupt changes Estimate truncation error between two levels of refinement Automatically adjust the step size so that small steps are taken in regions of sharp variations while larger steps are used elsewhere MATLAB functions: quad and quadl
MATLAB Integration Methods trapz(x,y) * Composite trapezoid rule q = quad(‘func’,xmin,xmax) * Adaptive Simpson’s rule (p 439), more efficient for low accuracies or non- smooth functions q =quadl(‘func’,xmin, xmax) * Labatto quadrature – more efficient for high accuracies and smooth functions (p439)