Norwegian University of Science and Technology Department of Mathematics MA5 Numerical Methods Spring 5 Solutions to exercise set 9 Find approximate values of the following integrals using the adaptive Simpson s rule from the textbook implemented in Matlab with ɛ = 5 6 and max recursion level dept equal to 6. Compare the actual error with ɛ. a b / dx + x x xdx The procedure has been implemented in the Matlab function adsimpson.m available on the course home page. The exact value of both integrals is π.59... a The procedure gives the approximation.59 to the digits given. The actual absolute error is about 6., well below ɛ. b The procedure gives the approximation.59 to the digits given. The actual absolute error is about., again well below ɛ. As a continuation of Exercise in Exercise set, compute a numerical approximation of the definite integral e x sinx dx, using the composite Gauss Legendre rule with n = and two subintervals, i.e. h =. You may want to use Matlab for the computations. The second Gauss Legendre rule with h = yields Qf,,, = 5 f + f + 5 + 5 f f + + f + 5 f +.. March 7, 5 Page of 5
Suppose we choose interpolation points in the interval [, ]: x = x = x = Remember that we obtain a quadrature formula by interpolating a function f at those points, and integrating exactly the resulting interpolation polynomial. The resulting formula has the format fxdx If = A k fx k a Explain why this quadrature formula integrates exactly polynomials of degree up to degree. Does it depend on the choice of x, x, x? b Using the preceding fact on the polynomials, x and x to find directly the weights A k. c Write down the Lagrange polynomials l, l and l for the interpolation points x k and compute the integrals A k = l kxdx. Do you find the same values of A k? If so, why? d Show that the quadrature formula integrates exactly polynomials of degree, but not. Hint: use the quadrature formula on the polynomials and. e Show that the quadrature formula is exact for the polynomial 5. Does this mean that the formula is exact for polynomials of degree 5? f Write the quadrature formula scaled to an arbitrary interval [a, b], in order to approximate b a fxdx. k= a This result does not depend on the choice of x, x, x as long as they are distinct. For any distinct points the interpolation polynomial must equal f, when f is a polynomial of degree at most. This follows from the uniqueness theorem of interpolating polynomials. Since the rule is generated by integrating the polynomial precisely, it also integrates f precisely in this case. b Using the fact that, x and x should be integrated exactly, gives the three equations: = = = dx = A + A + A dx = A + A dx = 6 A + A The second equation gives A = A, from the third we then get A = A = / and finally from the first A = /. March 7, 5 Page of 5
c From the definition we can immediately write down the Lagrange polynomials. l = = x x + l = l = 6 which are trivially integrated to give A = A = A = l dx = = 6x + 6 = x 6x + l dx = l dx = x x + dx = / 6x + 6 dx = / x 6x + dx = / so the resulting weights are the same. This must be the case. As discussed in a, since the functions, and are all polynomials of degree less than or equal to they match their interpolating polynomial through x, x, x. Consequently they will be integrated exactly when the weights are chosen as in c. However this was precisely the requirement we directly imposed in b, and since the resulting linear system had a unique solution, those weights must match those found in c. Note also that, and clearly form a basis for all polynomials of degree less than or equal to, i.e. any such polynomial can be written as a linear combination of these three functions. The linearity of integration and the quadrature rule then implies that the requirement in b is equivalent to the requirement that all polynomials of degree less than or equal to be integrated exactly. d We use the hint and check = = dx = 6 dx 56 + + = 9 Since,, and clearly form a basis for all polynomials of degree less than or equal to. It again follows from linearity of integration and the quadrature rule that the formula is exact for all such polynomials. Because is a polynomial of degree, the formula is clearly not exact for all polynomials of degree. e We use the hint and check = 5 dx = + March 7, 5 Page of 5
In fact it is readily observed that the formula will be exact for all n+ with n some nonnegative integer, since it will be exact for all f /, where fx is an odd function. This does not mean the formula is exact for general polynomials of degree 5. Suppose it were exact for one such polynomial px. Then px + k for some constant k would also be a polynomial of degree 5. However, since the formula is not exact for it follows from linearity that the quadrature rule will not be exact for this new polynomial. f A linear transformation gives b with A k and x k as before. a fxdx If = b a A k f a + b ax k k= Show that the quadrature formula constructed using the n + nodes x, x,..., x n can not possibly have degree of precision n+, i.e. integrate exactly all polynomials of degree up to and including n+. This implies that the degree of precision, n+, obtained by Gaussian quadrature is optimal. Hint: Consider the polynomial M, with Mx = x x x n Call the interval this quadrature formula applies to for [a, b], where we exclude the trivial case a = b and assume without loss of generality that b > a. Now, following the hint it is readily observed that M x = x x x n, is at all the nodes x, x,..., x n. This implies that for a quadrature formula n If = A k fx k, k= IM =. However M is obviously positive at all points except the nodes and continuous, and so the actual integral of M must be positive, i.e. b a M x dx >. Thus M will not be integrated exactly by the quadrature formula. The proof now follows from the realization that M is a polynomial of degree n +. 5 Cf. Cheney and Kincaid, Exercise 6..9 Assume that you are interpolating the function fx = sinx on the interval [, π] with a linear spline on a uniformly spaced grid. Estimate how many grid points will be required in order to guarantee that the interpolation error is smaller than? March 7, 5 Page of 5
Denote by S the interpolating linear spline with grid size h = π/n. Then we have the estimate h max Sx fx x [,π] max f x. x [,π] Now, and therefore Thus f x = sinx, max f x =. x [,π] max Sx fx x [,π] h. As a consequence, the error is guaranteed to be smaller than, if h <, which, since h = π/n, is equivalent to the estimate n > 6 π. March 7, 5 Page 5 of 5