Additional exercises with Numerieke Analyse March 10, 017 1. (a) Given different points x 0, x 1, x [a, b] and scalars y 0, y 1, y, z 1, show that there exists at most one polynomial p P 3 with p(x i ) = y i, i = 0, 1,, p (x 1 ) = z 1. (b) Construct this p in the form p(x) = p (x)+α(x x 0 )(x x 1 )(x x ) with p being the Langange interpolation polynomial of degree corresponding to the set {(x i, y i ) : i = 0, 1, }. (c) Let f be four times differentiable. Show that for the polynomial p P 3 with p(x i ) = f(x i ), i = 0, 1,, p (x 1 ) = f (x 1 ) and any x [a, b], there exists a ξ = ξ(x) (a, b) with f(x) p(x) = (x x 0 )(x x 1 ) (x x ) f (4) (ξ). 4!. (a) Find weights w 0, w 0, w 1, w 1 such that b a for any f P 3. f(x)dx = w 0 f(a) + w 0 f (a) + w 1 f(b) + w 1 f (b) (b) Show that for f C 4, the error in this quadrature formula, i.e., true integral minus its approximation, is of the form C(b a) 5 f (4) (ξ) for some ξ [a, b], and give the constant C. (c) Splitting the interval into m equal subintervals, give the resulting composite quadrature formula. (d) Show that the error in this composite formula is equal to C (b a)5 f (4) (ξ) m 4 for some ξ [a, b]. 3. For a < b, {x 0,..., x n } R, show that there are unique weights w 0,..., w n such that n i=0 w if(x i ) = b f(x)dx for all f P a n. 1
4. (Runge phenomenon). Let f(x) = 1/(1 + x ). (a) For n = 1, 4, 8, 1 make plots on [ 5, 5] of the Lagrange interpolation polynomial p n with interpolation points x (n) k = 5 + 10k/n, k = 0,..., n, and of f p n. Use e.g. the MATLAB functions polyfit, poly and polyval. Where is the interpolation error large? (b) For n as above, approximate max x [ 5,5] f(x) p n (x) by evaluating this absolute error on say 150 equally distributed points. What do you notice? (c) Repeat the previous questions for the Chebychev roots x (n) 5 cos( (k+ 1 )π ), k = 0,..., n and compare the results. n+1 k = (d) Compare max x [ 5,5] (x x (n) 0 )... (x x (n) n ) for both sets of interpolation points and draw a conclusion. Hand in: For n = 8 and both choices of the interpolation points the values of max x [ 5,5] (x x (n) 0 )... (x x (n) n ) and plots of f p n, and the m-files you used to generate these results. 5. (Adaptive quadrature) Given a function f, let T [c,d] (m) be the result of the approximation of d f(x)dx by means of the composite trapezium c rule on m equal subintervals. Assuming that f is sufficiently smooth, we know that d c f(x)dx T [c,d] (m) = 1 (d c) [f (d) f (c)] + O(m 4 ) 1 m (a) Approximate the integral of x 3 over [a, b] = [ 1, 100] by the composite trapezium rule T [a,b] (m) for m = k. Find the smallest k, 10 such that the exact error is less than ε = 10 3. Explain the slow convergence. To improve the convergence rate of the above problem we may use an adaptive strategy: instead of dividing an interval into m equal subintervals, we can try to recursively subdivide only those subintervals where the trapezium rule makes a large error. For this we need to estimate the error of the trapezium rule on a given interval.
(b) Verify that the error estimate d c f(x)dx T [c,d] (m) T [c,d](m) T [c,d] (m) 3 is exact when the O(m 4 ) and O((m) 4 ) terms can be ignored. The right hand side is computable, and thus can be used for an estimate. An adaptive strategy now is: Compute T [a,b] (), and accept it as an approximation when the estimated error is less or equal to a desired tolerance ε. Otherwise, apply the procedure to b+a b b+a f(x)dx with tolerances ε/. a f(x)dx and (c) Write a recursive MATLAB function that implements the adaptive strategy. (d) Apply the adaptive routine to the function x 3 with a, b, ε as before. What is the exact error in the obtained approximation? How do the number of function evaluations that are required compare to that with the strategy used in (a)? Hand in m-files that you have used in (5a) and (5c), and the answers to the questions posed in (5d). 6. Let a < b, m N, h := b a m, x i := a + ih for i {0,..., m}, and for n {1,,...}, let S n := {s C n 1 (a, b) : s (xi 1,x i ) P n (1 i m)}. Furthermore, let I 1 : C[a, b]) S 1 the continuous piecewise linear interpolator, and let I 3 : C 1 [a, b]) S 3 the complete cubic spline interpolator defined by s(x i ) = f(x i ) (i {0,..., m}), (1) s (x 0 ) = f (x 0 ), s (x m ) = f (x m ). () where s is here a shorthand notation for I 3 (f). The aim of this exercise is to show that f I 3 (f) = O(h 4 ) when f is sufficiently smooth. From formula (11.5) from the book, we know that each s S 3 can be written as s [xi 1,x i ](x) = (x i x) 3 6h σ i 1 + (x x i 1) 3 σ i + α i (x x i 1 ) + β i (x i x), 6h 3
for some scalars α 1,..., α m, β 1,..., β m and, for i {0,..., m}, with σ i = s (x i ). By imposing (1) we obtain α i = f(x i) h h 6 σ i, β i = f(x i 1) h h 6 σ i 1. (a) By using the continuity of s in x 1,..., x m 1 and (), show that A[σ 0... σ m ] = b, where A R (m+1) (m+1) is defined by 4 1 4 1 A =..., 1 4 1 4 and b R m+1 by b i = 1 [ f (x m) h 1 [ f(x 1 ) f(x 0 ) f (x 0 )] h h 6 f(x i+1) f(x i )+f(x i 1 ) when i = 0, ] h when i {1,..., m 1}, f(xm) f(x m 1) h when i = m. Elementary linear algebra shows that A is invertible, and that A 1 1, i.e., that max i (A 1 x) i 1 max i x i (Indeed, writing A = 4(I (I 1 4 A)) and using that I 1 4 A = 1, shows that A 1 1 ), (b) Show that I 3 (f) 3 f. (Hint: Show that s = max 0 i m σ i and that max 0 i m b i 6 f.) (c) Show that I 3 is a projector, i.e., that I 3 (s) = s for any s S 3. (d) Show that for any p S 1 there exists a s S 3 with s = p. (e) Let s S 3 be such that s = I 1 (f ). Show that f I 3 (f) = f s I 3 (f s), and with that, show that f I 3 (f) 4 f s 1 h f (4). 4
n=0 n=1 n= n=3 n=4 0 h h 3h 4h 5h Figure 1: The functions S (n,0) for n = 0,..., 4. (f) Show that I 1 (f I 3 (f)) = 0, and with that show that as well as for some constant C > 0. f I 3 (f) 1 16 h4 f (4), f I 3 (f) Ch 3 f (4) 7. Let a < b, m N, n N 0 := N {0}, h := b a m and S n := {s C n 1 (a, b) : s (a+(i 1)h,a+ih) P n (1 i m)}, being the spline space of degree n w.r.t. the subdivision of [a, b] in m equal subintervals (and with C 1 (a, b) being the space of bounded functions on [a, b]). For convenience, we take a = 0. With n+1 ( ) n + 1 S (n) (x) := ( 1) k (x kh) n k +, k=0 we define S (n,l) (x) := S (n) (x lh) for l Z. (a) Show that S (n,l) [0,b] S n. (b) Show that supp S (n,l) [lh, (l + n + 1)h]. (c) Show that dim S n = m + n = #{l Z : S (n,l) [0,b] 0}. (d) Show that S (n+1,l) (x) = (n+1)(s (n,l)(x) S (n,l+1) (x)) (when n = 0 only for x hz). (e) From Exercise 11.6, we know that S (n+1,l) (x) = (x lh)s (n,l) (x) + ((n + + l)h x)s (n,l+1) (x). 5
Using induction to n, from this show that S (n,l) (x) = h n n!. l Z Now we are going to show that for all p Z, c l S (n,l) (ph,(p+1)h) = 0 = c l = 0 for p n 1 < l < p + 1. (3) l Z (f) Show that (3) holds for n = 0. (g) Now let (3) be valid for some n N 0. Let l Z c ls (n+1,l) and so l Z c ls (n+1,l) vanish on (ph, (p + 1)h). Using (7d), show that this implies that for some constant c R, c l = c for all p n < l < p + 1, and with that c l S (n+1,l) (ph,(p+1)h) = c S (n+1,l) (ph,(p+1)h) = ch n+1 (n + 1)! l Z l Z Conclude that (3) is valid for n + 1, and so for any n N 0. (h) Using (7a), (7c), and (3), show that { S(n,l) [0,b] : l { n,..., m 1} } is a basis for S n. 8. Consider the initial value problem(ivp): { y (x) = f(x, y(x)) 0 x 1 y(0) = 0 where f(x, y) = (1 + x)(1 + y ). (a) Verify that the exact solution is given by y(x) = tan(x + x /). A possible implementation of the Forward Euler method (FE) for solving this IVP is given below. 6
function Euler(N) % N is the number of the time steps f=@(x,y)(1+x)*(1+y.^); % defines the function f y=@(x) tan(x+x.^/); % defines exact solution h=1/n; % time step x=0:h:1; xfine=0:0.01:1 FE=zeros(1,N+1); % Forward Euler approximation solution err=zeros(1,n+1); % Error values of Forward Euler method FE(1)=0; for i=1:n FE(i+1)=FE(i)+h*f(x(i),FE(i)); end for i=1:n+1 err(i)=y(x(i))-fe(i); end plot(xfine,y(xfine)); hold on; plot(x,fe); (b) Run Forward Euler with h 1 = N = 10, 0, 40, 80, 160 and compare the errors. (c) To compare the error of FE with other numerical methods, solve the problem with the modified Euler method: { yi+1 = y i + 1 (k 1 + k ) where k 1 = hf(x i, y i ), k = hf(x i + h, y i + k 1 ) and the following Runge-Kutta scheme: y i+1 = y i + h(k 6 1 + k + k 3 + k 4 ) where k 1 = f(x i, y i ), k = f(x i + h, y i + h k 1 ), k 3 = f(x i + h, y i + h k ), k 4 = f(x i + h, y i + hk 3 ) (d) Plot the error in the point 1 vs. N for the three methods, and estimate the order of the methods. To do this, it is most convenient to use a log-log plot. 9. To illustrate the numerical solution of a so-called stiff ODE, consider the IVP { y (x) = λ(sin(x) y) + cos(x) 0 x 1, λ 1 y(0) = 0 7
with exact solution y(x) = sin(x). (a) Apply the FE method to this problem with λ = 00 and h 1 = N = 10, 90, 100, 105, 1000. (b) Implement the Backward Euler method (BE): y i+1 = y i + hf(x i+1, y i+1 ) and run it with the same values of h and λ. Compare the results. (c) With x i = ih, define the truncation error of the Backward Euler method by T (BE) i = y(x i+1) y(x i ) f(x i+1, y(x i+1 )) h and show that T (BE) i = h y (ξ) for some ξ [x i, x i+1 ]. Similarly, let T (FE) i = y(x i+1) y(x i ) f(x h i, y(x i )), which is known to be of the form h y (η) for some η [x i, x i+1 ]. (d) With e i := y(x i ) y e i and e (BE) i i+1 = (1 hλ)e i + ht e (BE) i+1 = e(be) i + ht (BE) i 1 + hλ := y(x i ) y (BE) i, show that. i, Show that for 1 i h 1, e (BE) i 1 h y, and, when h 1, 100 e i 1 h y. Explain the behaviour of the error of FE when N < 100. Is there a contradiction with the result of Theorem 1. applied to FE? 10. For x 0 < x 1 < < x n, where n, and k N, consider the spline space S (k) = {s C k 1 (x 0, x n ) : s (xi,x i+1 ) P k, i = 0,..., n}. (a) Show that the only s S (1) with s(x 0 ) = s(x n ) = 0 and such that for any i 0, j, i + j n, s (xi,x i+j ) has j 1 zeros, is the zero function. (Hint: Show that if s 0, then there exists i and j as above with s(x i ) = 0 and s(x i+j ) = 0 and s(x i+1 ) 0,..., s(x i+j 1 ) 0, and derive a contradiction.) 8
(b) Show that the only p P 3 (a, b) with p(a) = p(b) = 0 and p 0 is the zero polynomial. (c) Show that there exists at most one natural cubic spline interpolant, i.e., an t S (3) with t (x 0 ) = t (x n ) = 0 that for some given y 0,..., y n satisfies t(x i ) = y i (0 i n). (Hint: suppose two, and consider the difference.) 11. Archimedes (50 v. Chr.) obtained upper and lower bounds for π by measuring the perimeter of regular inscribed or circumscribed polygons for a circle with radius 1. In this exercise we consider inscribed polygons only. (a) Let T 0 (h) be the perimeter of regular inscribed polygon with n sides, where nh = 1. Show that T 0 (h) = h 1 sin(πh). (b) Show that there exist constants (c i ) such that m N π T 0 (h) = m c i h i + O(h m+ ) (h 0). i=1 (c) Determine α 1, β 1 such that T 1 (h/) := α 1 T 0 (h/) + β 1 T 0 (h) satisfies π T 1 (h/) = O(h 4 ) (h 0). Huygens used this idea already in 1654. Archimes measurements went to n = 96. Assuming that Huygens used these measurements, which we assume to be exact, what were the errors in the best approximations that they both obtained? (d) Improve Huygens, i.e., determine α, β such that T (h/4) := α T 1 (h/4) + β T 1 (h/) satisfies π T (h/4) = O(h 6 ) (h 0). What is the error in T (1/96)? 9
Figure : The inscribed regular polygons for h = 1/8 and h = 1/16. 1. To approximate a (a > 0) we apply the Newton scheme to f(x) = x a = 0. (a) Verify that this yields the following iteration: x i+1 = 1 (x i + a x i ). (b) Show that for any x 0 > a, the sequence (x i ) i 0 is monotone decreasing. (c) Show that for any 0 < x 0 < a, the sequence (x i ) i 1 is monotone decreasing. Now we consider the Newton iteration with x 0 = 1 (1 + a). (d) Show that x 0 is the result of one step of Newton iteration starting with x 1 = 1, and thus that x 0 > a. (e) Show that if for some i 0, x i x i+1 < ɛ, that then x i+1 a < ɛ, which provides a useful stopping criterion. 13. Skipped 10