15
Numerical Integration of Functions Berlin Chen Department of Computer Science & Information Engineering National Taiwan Normal University Reference: 1. Applied Numerical Methods with MATLAB for Engineers, Chapter 20 & Teaching material

Numerical Integration of Functions - 國立臺灣師範大學berlin.csie.ntnu.edu.tw/Courses/Numerical Methods/Lectures2012S...Numerical Integration of Functions ... Applied Numerical

Embed Size (px)

Citation preview

Page 1: Numerical Integration of Functions - 國立臺灣師範大學berlin.csie.ntnu.edu.tw/Courses/Numerical Methods/Lectures2012S...Numerical Integration of Functions ... Applied Numerical

Numerical Integration of Functions

Berlin ChenDepartment of Computer Science & Information Engineering

National Taiwan Normal University

Reference:1. Applied Numerical Methods with MATLAB for Engineers, Chapter 20 & Teaching material

Page 2: Numerical Integration of Functions - 國立臺灣師範大學berlin.csie.ntnu.edu.tw/Courses/Numerical Methods/Lectures2012S...Numerical Integration of Functions ... Applied Numerical

Chapter Objectives

• Understanding how Richardson extrapolation provides a means to create a more accurate integral estimate by combining two less accurate estimates

• Understanding how Gauss quadrature provides superior integral estimates by picking optimal abscissas at which to evaluate the function

• Knowing how to use MATLAB’s built-in functions quadand quadl to integrate functions

NM – Berlin Chen 2

Page 3: Numerical Integration of Functions - 國立臺灣師範大學berlin.csie.ntnu.edu.tw/Courses/Numerical Methods/Lectures2012S...Numerical Integration of Functions ... Applied Numerical

Richardson Extrapolation (1/2)

• Richard extrapolation methods use two estimates of an integral to compute a third, more accurate approximation.

• If two O(h2) estimates I(h1) and I(h2) are calculated for an integral using step sizes of h1 and h2, respectively, an improved O(h4) estimate may be formed using:

• For the special case where the interval is halved (h2=h1/2), this becomes:

NM – Berlin Chen 3

I I(h2 )1

(h1 /h2 )2 1

I(h2 ) I (h1)

I 43I(h2 )

13I (h1)

Page 4: Numerical Integration of Functions - 國立臺灣師範大學berlin.csie.ntnu.edu.tw/Courses/Numerical Methods/Lectures2012S...Numerical Integration of Functions ... Applied Numerical

Richardson Extrapolation (2/2)

• For the cases where there are two O(h4) estimates and the interval is halved (hm=hl/2), an improved O(h6) estimate may be formed using:

• For the cases where there are two O(h6) estimates and the interval is halved (hm=hl/2), an improved O(h8) estimate may be formed using:

NM – Berlin Chen 4

I 1615Im

115Il

I 6463Im

163Il

Page 5: Numerical Integration of Functions - 國立臺灣師範大學berlin.csie.ntnu.edu.tw/Courses/Numerical Methods/Lectures2012S...Numerical Integration of Functions ... Applied Numerical

Richardson Extrapolation: An Example (1/2)

NM – Berlin Chen 5

Example 20.1

Page 6: Numerical Integration of Functions - 國立臺灣師範大學berlin.csie.ntnu.edu.tw/Courses/Numerical Methods/Lectures2012S...Numerical Integration of Functions ... Applied Numerical

Richardson Extrapolation: An Example (2/2)

NM – Berlin Chen 6

Example 20.1

Page 7: Numerical Integration of Functions - 國立臺灣師範大學berlin.csie.ntnu.edu.tw/Courses/Numerical Methods/Lectures2012S...Numerical Integration of Functions ... Applied Numerical

The Romberg Integration Algorithm

• Note that the weighting factors for the Richardson extrapolation add up to 1 and that as accuracy increases, the approximation using the smaller step size is given greater weight

• In general,

– Where ij+1,k-1 and ij,k-1 are the more and less accurate integrals, respectively, and ij,k is the new approximation. k is the level of integration and j is used to determine which approximation is more accurate

NM – Berlin Chen 7

I j,k 4 k1 I j1,k1 I j ,k1

4 k1 1

Page 8: Numerical Integration of Functions - 國立臺灣師範大學berlin.csie.ntnu.edu.tw/Courses/Numerical Methods/Lectures2012S...Numerical Integration of Functions ... Applied Numerical

Romberg Algorithm Iterations

• The chart below shows the process by which lower level integrations are combined to produce more accurate estimates:

NM – Berlin Chen 8

Page 9: Numerical Integration of Functions - 國立臺灣師範大學berlin.csie.ntnu.edu.tw/Courses/Numerical Methods/Lectures2012S...Numerical Integration of Functions ... Applied Numerical

MATLAB Code for Romberg

NM – Berlin Chen 9

Page 10: Numerical Integration of Functions - 國立臺灣師範大學berlin.csie.ntnu.edu.tw/Courses/Numerical Methods/Lectures2012S...Numerical Integration of Functions ... Applied Numerical

Gauss Quadrature

• Gauss quadraturedescribes a class of techniques for evaluating the area under a straight line by joining any two points on a curve rather than simply choosing the endpoints

• The key is to choose the line that balances the positive and negative errors

NM – Berlin Chen 10

Page 11: Numerical Integration of Functions - 國立臺灣師範大學berlin.csie.ntnu.edu.tw/Courses/Numerical Methods/Lectures2012S...Numerical Integration of Functions ... Applied Numerical

Gauss-Legendre Formulas (1/2)

• The Gauss-Legendre formulas seem to optimize estimates to integrals for functions over intervals from -1 to 1

• Integrals over other intervals require a change in variables to set the limits from -1 to 1

• The integral estimates are of the form:

– Where the ci and xi are calculated to ensure that the method exactly integrates up to (2n-1)th order polynomials over the interval from -1 to 1

NM – Berlin Chen 11

I c0 f x0 c1 f x1 cn1 f xn1

Page 12: Numerical Integration of Functions - 國立臺灣師範大學berlin.csie.ntnu.edu.tw/Courses/Numerical Methods/Lectures2012S...Numerical Integration of Functions ... Applied Numerical

Gauss-Legendre Formulas (2/2)

NM – Berlin Chen 12

Page 13: Numerical Integration of Functions - 國立臺灣師範大學berlin.csie.ntnu.edu.tw/Courses/Numerical Methods/Lectures2012S...Numerical Integration of Functions ... Applied Numerical

Gauss-Legendre: An Example

NM – Berlin Chen 13

Example 20.3

Page 14: Numerical Integration of Functions - 國立臺灣師範大學berlin.csie.ntnu.edu.tw/Courses/Numerical Methods/Lectures2012S...Numerical Integration of Functions ... Applied Numerical

Adaptive Quadrature

• Methods such as Simpson’s 1/3 rule has a disadvantage in that it uses equally spaced points - if a function has regions of abrupt changes, small steps must be used over the entire domain to achieve a certain accuracy

• Adaptive quadrature methods for integrating functions automatically adjust the step size so that small steps are taken in regions of sharp variations and larger steps are taken where the function changes gradually

NM – Berlin Chen 14

Page 15: Numerical Integration of Functions - 國立臺灣師範大學berlin.csie.ntnu.edu.tw/Courses/Numerical Methods/Lectures2012S...Numerical Integration of Functions ... Applied Numerical

Adaptive Quadrature in MATLAB

• MATLAB has two built-in functions for implementing adaptive quadrature:– quad: uses adaptive Simpson quadrature; possibly

more efficient for low accuracies or nonsmooth functions

– quadl: uses Lobatto quadrature; possibly more efficient for high accuracies and smooth functions

• q = quad(fun, a, b, tol, trace, p1, p2, …)

– fun : function to be integrates– a, b: integration bounds– tol: desired absolute tolerance (default: 10-6)– trace: flag to display details or not– p1, p2, …: extra parameters for fun– quadl has the same arguments

NM – Berlin Chen 15