Numerical Integration and Differentiation Growth And

Numerical Integration and Differentiation Growth And

Numerical Integration and Differentiation Growth and Development Ra¨ulSantaeul`alia-Llopis MOVE-UAB and Barcelona GSE Spring 2017 Ra¨ulSantaeul`alia-Llopis(MOVE,UAB,BGSE) GnD: Numerical Integration and Differentiation Spring 2017 1 / 27 1 Numerical Differentiation One-Sided and Two-Sided Differentiation Computational Issues on Very Small Numbers 2 Numerical Integration Newton-Cotes Methods Gaussian Quadrature Monte Carlo Integration Quasi-Monte Carlo Integration Ra¨ulSantaeul`alia-Llopis(MOVE,UAB,BGSE) GnD: Numerical Integration and Differentiation Spring 2017 2 / 27 Numerical Differentiation The definition of the derivative at x∗ is 0 f (x∗ + h) − f (x∗) f (x∗) = lim h!0 h Ra¨ulSantaeul`alia-Llopis(MOVE,UAB,BGSE) GnD: Numerical Integration and Differentiation Spring 2017 3 / 27 • Hence, a natural way to numerically obtain the derivative is to use: f (x + h) − f (x ) f 0(x ) ≈ ∗ ∗ (1) ∗ h with a small h. We call (1) the one-sided derivative. • Another way to numerically obtain the derivative is to use: f (x + h) − f (x − h) f 0(x ) ≈ ∗ ∗ (2) ∗ 2h with a small h. We call (2) the two-sided derivative. We can show that the two-sided numerical derivative has a smaller error than the one-sided numerical derivative. We can see this in 3 steps. Ra¨ulSantaeul`alia-Llopis(MOVE,UAB,BGSE) GnD: Numerical Integration and Differentiation Spring 2017 4 / 27 • Step 1, use a Taylor expansion of order 3 around x∗ to obtain 0 1 00 2 1 000 3 f (x) = f (x∗) + f (x∗)(x − x∗) + f (x∗)(x − x∗) + f (x∗)(x − x∗) + O3(x) (3) 2 6 • Step 2, evaluate the expansion (3) at x = x∗ + h 0 1 00 2 1 000 3 f (x∗ + h) = f (x∗) + f (x∗)h + f (x∗)(h) + f (x∗)(h) + O3(x∗ + h) (4) 2 6 and rearrange to obtain the one-sided derivative formula: f (x∗ + h) − f (x∗) 0 1 00 1 000 2 O3(x∗ + h) = f (x∗) + f (x∗)(h) + f (x∗)(h) + (5) h 2 6 h • Step 3, evaluate the expansion (3) at x = x∗ − h 0 1 00 2 1 000 3 f (x∗ − h) = f (x∗) + f (x∗)(−h) + f (x∗)(−h) + f (x∗)(−h) + O3(x∗ − h) (6) 2 6 and combine (4) and (6) to obtain the two-sided derivative formula: f (x∗ + h) − f (x∗ − h) 0 1 000 2 O3(x∗ + h) − O3(x∗ − h) = f (x∗) + f (x∗)(h) + (7) 2h 6 2h Comparing (5) and (7) shows the error associated with the two-sided formula is smaller. Ra¨ulSantaeul`alia-Llopis(MOVE,UAB,BGSE) GnD: Numerical Integration and Differentiation Spring 2017 5 / 27 Computational Issues on Very Small Numbers • Exact arithmetic and computer arithmetic do not always give the same answers. This is not an issue of programming skills but a matter of computer precision. • For example, compute y = (1:0e − 20 + 1:0) − 1:0 and y = 1:0e − 20 + (1:0 − 1:0) where 1:0e − 20 is the computer's shorthand for 10−20. Exact arithmetic says the two statements above are identical because addition and substraction are associative. A computer, however, would evaluate the statements differently. The first statement would, incorrectly, likely result in x = 0 whereas the second one would, correctly, result in x = 10−20. • Usually, if one is using double precision in Fortran, numbers can be not precise if we reach 10−16. Ra¨ulSantaeul`alia-Llopis(MOVE,UAB,BGSE) GnD: Numerical Integration and Differentiation Spring 2017 6 / 27 For this reason, practice suggets for the two-sided formula an alternative 0 f (x∗ + h) − f (x∗ − h) f (x∗) ≈ (8) (x∗ + h) − (x∗ − h) with a small h. Note that the denominator might not be precisely 2h. That is why this formula helps to avoid trouble associated with a small h. Ra¨ulSantaeul`alia-Llopis(MOVE,UAB,BGSE) GnD: Numerical Integration and Differentiation Spring 2017 7 / 27 Numerical Integration • Goal: Compute the definite integral of a real-valued function f w.r.t. a weight function w over an interval I of <n, Z f (x) w(x) dx I • The weight function can be, for example • w(x) ≡ 1 ! the integral is the area under f • w(x) ≡ p.d.f. of a r.v. xe with support I ! the integral is E[f (xe)]. Ra¨ulSantaeul`alia-Llopis(MOVE,UAB,BGSE) GnD: Numerical Integration and Differentiation Spring 2017 8 / 27 • We study methods that approximate a definite integral with a weighted sum of function values, n Z X f (x) w(x) dx ≈ wi f (xi ) I i=0 Ra¨ulSantaeul`alia-Llopis(MOVE,UAB,BGSE) GnD: Numerical Integration and Differentiation Spring 2017 9 / 27 • We will see three classes of numerical integration (numerical quadrature) methods that differ on how the quadrature weights wi and the quadrature nodes xi are chosen. • Newton-Cotes methods approximate the integrand f between nodes using low-order polynomials and sum the integrals. • Gaussian Quadrature methods choose the nodes and weights that satisfy some moment-matching conditions. • Monte Carlo (and quasi-Monte Carlo) methods use equally weighted random or equidistributed nodes. Ra¨ulSantaeul`alia-Llopis(MOVE,UAB,BGSE) GnD: Numerical Integration and Differentiation Spring 2017 10 / 27 Newton-Cotes Methods • Univariate quadrature methods are designed to approximate the integral of a real-valued function f defined on a bounded interval [a; b] of the real line. • Two Newton-Cotes methods are widely used, • Trapezoid Rule • Simpson's Rule • Both rules are easy to implement and are typically adequate for computing the area under a continuous function. Ra¨ulSantaeul`alia-Llopis(MOVE,UAB,BGSE) GnD: Numerical Integration and Differentiation Spring 2017 11 / 27 Trapezoid Rule • First, partition the interval [a; b] into subintervals, (say, though not necessarily, equal length) • b−a Define the nodes xi = a + (i − 1)h for i = 1; :::; n with h = n−1 . • Second, approximate f over each subinterval [xi ; xi+1] using piecewise linear spline passing through (xi ; f (xi )) and (xi+1; f (xi+1)) Ra¨ulSantaeul`alia-Llopis(MOVE,UAB,BGSE) GnD: Numerical Integration and Differentiation Spring 2017 12 / 27 • Third, the area under each line segment defines a trapezoid approximates the area under f over the subinterval, Z xi+1 h f (x) dx ≈ [f (xi ) + f (xi+1)] xi 2 Summing up the areas of the trapezoides across the subintervals yields the Trapezoide rule: n Z b X f (x) dx ≈ wi f (xi ) a i h with w1 = wn = 2 and wi = h otherwise. Ra¨ulSantaeul`alia-Llopis(MOVE,UAB,BGSE) GnD: Numerical Integration and Differentiation Spring 2017 13 / 27 • Remarks: • It is simple and robust. • First-order exact: if not for rounding error, it will exactly compute the integral of any first-order polynomial (a line) • If the integrand is smooth, the trapezoid rule yields an approximation error that shrinks quadratically with the width of the subintervals, O(h2). Ra¨ulSantaeul`alia-Llopis(MOVE,UAB,BGSE) GnD: Numerical Integration and Differentiation Spring 2017 14 / 27 Simpson's Rule • First, partition the interval [a; b] into an even number of subintervals, (say, equal length) • b−a Define the nodes xi = a + (i − 1)h for i = 1; :::; n with h = n−1 and n is odd. • Second, approximate f over the jth pair of subintervals [xj−1; xj ] and [xj ; xj+1] using a piecewise quadratic function that passes through (xj−1; f (xj−1)), (xj ; f (xj )) and (xj+1; f (xj+1)) Ra¨ulSantaeul`alia-Llopis(MOVE,UAB,BGSE) GnD: Numerical Integration and Differentiation Spring 2017 15 / 27 • Third, the area under this quadratic function approximates the area under f over the subinterval, Z xj+1 h f (x) dx ≈ [f (xj−1) + 4f (xj ) + f (xj+1))] xj−1 3 Summing up the areas of the quadratic approximants across subintervals yields the Simpson's Rule: n Z b X f (x) dx ≈ wi f (xi ) a i h h h with w1 = wn = 3 and otherwise, wi = 4 3 if i is even, and wi = 2 3 if i is odd. Ra¨ulSantaeul`alia-Llopis(MOVE,UAB,BGSE) GnD: Numerical Integration and Differentiation Spring 2017 16 / 27 • Remarks: • Easy to implement, as the Trapezoide rule. • Even thought it is based on locally quadratic approximations of the integrand, it is third-order exact: if not for rounding error, it will exactly compute the integral of any cubic polynomial. • If the integrand is smooth, the Simpson's rule yields an approximation error that shrinks at twice the geometric rate of the error associated with the trapezoid rule, O(h4). • Simpson's rule is preferred to the Trapezoid rule when f is smooth because it offers twice the degree of approximation. • If f exhibits discontinuities, the trapezoid rule will often be more accurate. • Newton-Cotes rules based on 4th and higher order piecewise polynomial approximations exist, but rarely used. Ra¨ulSantaeul`alia-Llopis(MOVE,UAB,BGSE) GnD: Numerical Integration and Differentiation Spring 2017 17 / 27 • Higher dimensional integration: generalizations of the univariate Newton-Cotes quadrature schemes through tensor product principles. • Suppose one wishes to integrate a real-valued function defined on a 2 rectangle f(x1; x2) ja1 ≤ x1 ≤ b1; a2 ≤ x2 ≤ b2g in < . • One way to proceed is to compute the Newton-Cotes nodes and weights: • f(x1i ; w1i ) ji = 1; :::; n1g for the real interval (a1; b1), and • f(x2j ; w2j ) jj = 1; :::; n2g for the real interval (a2; b2) • The tensor product Newton-Cotes rule for the rectangle would comprise of the n = n1n2 grid points of the form • f(x1i ; w2j ) j i = 1; :::; n1; j = 1; :::; n2g with associated weights, • fwij = w1i w2j j i = 1; :::; n1; j = 1; :::; n2g • This construction principle can be applied to higher dimensions using repeated tensor product operations.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    27 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us