Ma 449: Numerical Applied Mathematics Model Solutions to Homework Assignment 5 Prof. Wickerhauser Exercise 4(a,b) of Section 4.1, p.195. (a) Taylor polynomial of degree 5: 2 3 4 5 1 - x + x - x + x - x (b) Error term: 6 x -------- 7 (1 + c) for some c between 0 and x. Exercises 9 of Section 4.1, p.196. The error term for the degree-N Taylor expansion of exp(x) at x0=0 is x^(1+n) exp(c)/(1+n)!, where 00, the coefficient of x^N in T_N(x) is 2^{N-1}. Proof: First strengthen the claim to include that T_N(x) is a polynomial of degree N in x. This is true for T_1 and T_2. Suppose it is true for T_N and T_{N-1} where N is any integer greater than 1. Use the recurrence T_{N+1}(x) = 2*x*T_N(x) - T_{N-1}(x) to conclude that T_{N+1}(x) is a polynomial of degree N+1 in X, and that the coefficient of x^{N+1} in T_{N+1}(x) is 2 times the coefficient of x^N in T_N(x), hence is 2^N. Exercise 4 of Section 4.5, p.241. Property 3: T_N(x) is an even function of x for even N and an odd function of x for odd N. Proof: By induction. The statement is true for T_0(x)=1 and T_1(x)= x. Now suppose that N>1 and use the recurrence to evaluate T_{N}(-x) = 2*(-x)*T_{N-1}(-x) - T_{N-2}(-x) If N is even, then N-2 is even but N-1 is odd, so by the inductive hypothesis, T_N(-x) = 2*(-x)*[-T_{N-1}(x)] - T_{N-2}(x) = 2*x*T_{N-1}(x) - T_{N-2}(x) = T_N(x) Else N is odd, so N-2 is odd but N-1 is even, so again by the inductive hypothesis T_N(-x) = 2*(-x)*T_{N-1}(x) - [-T_{N-2}(x)] = -[2*x*T_{N-1}(x) - T_{N-2}(x)] = -T_N(x) Hence T_N has the same parity as N for all N. Algorithm 2(a,b,c,d) of Section 4.5, p.242. MATLAB PROGRAM: function [C,X,Y]=cheby(fun,n,a,b) %Input - fun is the function to be approximated % - n is the degree of the Chebyshev interpolating polynomial % - a is the left endpoint % - b is the right endpoint %Output - C is the coefficient list for the polynomial % - X contains the abscissas % - Y contains the ordinates % If fun is defined as an M-file function use the call % [C,X,Y]=cheby('fun(x)',m,a,b) % NUMERICAL METHODS: Matlab Programs % (c) 2004 by John H. Mathews and Kurtis D. Fink % Complementary Software to accompany the textbook: % NUMERICAL METHODS: Using Matlab, Fourth Edition % ISBN: 0-13-065248-2 % Prentice-Hall Pub. Inc. % One Lake Street % Upper Saddle River, NJ 07458 if nargin==2, a=-1;b=1;end d=pi/(2*n+2); C=zeros(1,n+1); for k=1:n+1 X(k)=cos((2*k-1)*d); end X=(b-a)*X/2+(a+b)/2; x=X; Y=eval(fun); for k =1:n+1 z=(2*k-1)*d; for j=1:n+1 C(j)=C(j)+Y(k)*cos((j-1)*z); end end C=2*C/(n+1); C(1)=C(1)/2; OUTPUT: Call the function in "cheby.m" from the Matlab console as follows, to calculate the coefficients of the interpolating polynomials: >> format long >> a=-1; b=1; fun='sin(x)'; (a) >> n=4; c4=cheby(fun,n,a,b) c4 = 0 0.880101161015327 0 -0.039123703313740 0 (b) >> n=5; c5=cheby(fun,n,a,b) c5 = 0 0.880101171513789 0 -0.039126718463837 0 0.000502520112057 (c) >> n=6; c6=cheby(fun,n,a,b) c6 = 0 0.880101171489829 0 -0.039126707941377 0 0.000499504961922 0 (d) >> n=7; c7=cheby(fun,n,a,b) c7 = 0 0.880101171489867 0 -0.039126707965375 0 0.000499515484383 0 -0.000003015150136 Plot the interpolations as follows: >> x=-1:0.01:1; y=sin(x); plot(x,y) % lots of x values for a smooth-looking plot >> y4 = c4*[x.^0; x.^1; x.^2; x.^3; x.^4]; plot(x,y4) >> y5 = c5*[x.^0; x.^1; x.^2; x.^3; x.^4; x.^5]; plot(x,y5) >> y6 = c6*[x.^0; x.^1; x.^2; x.^3; x.^4; x.^5; x.^6]; plot(x,y6) >> y7 = c7*[x.^0; x.^1; x.^2; x.^3; x.^4; x.^5; x.^6; x.^7]; plot(x,y7) >> % plot differences to see the errors: >> plot(x,y-y5) >> plot(x,y-y4) >> plot(x,y-y6) >> plot(x,y-y7) >> plot(x,y4-y7) >> plot(x,y4-y5) Exercise 2(a,b) of Section 4.6, p.248. (a) Write R_{1,1}(x)=(a+bx)/(c+dx) and obtain the values of a,b,c,d for f(x)=ln(1+x)/x = 1-x/2+x^2/3-x^3/4+... by the method of undetermined coefficients: Since R_{1,1}(0)=f(0)=1, we must have a/c=1 ==> a=c. With that, and since R'_{1,1}(0)=f'(0)= -1/2, we must have (bc-ad)/c^2 = (b-d)/c = -1/2 ==> b=(-c+2d)/2. With that, and since R''_{1,1}(0)=f''(0)=2/3, we must have 2 (ad^2 -bcd)/ c^3 = 2/3 ==> b=c/6, d=2c/3. We can choose c=6 so that all four coefficients are integers. This yields a=c=6, b=c/6=1, and d=2c/3=4, so that R_{1,1}(x) = (6+x)/(6+4x). (b) Set R_{2,1}(x)=xR_{1,1}(x) = (6x+x^2)/(6+4x). Then R_{2,1}(0) = 0 = ln(1+0). But also, R'_{2,1}(x)=R_{1,1}(x)+xR'_{1,1}(x) ==> R'_{2,1}(0)=R_{1,1}(0)=1. Likewise, R''_{2,1}(x)=2R'_{1,1}(x)+xR''_{1,1}(x) ==> R''_{2,1}(0) = 2R'_{1,1}(0) = -1. Finally, $R'''_{2,1}(x) = 3R''_{1,1}(x)+xR'''_{1,1}(x) ==> R'''_{2,1}(0)=3R'_{1,1}(0) = 2. These are exactly the first 3 derivatives of ln(1+x) evaluated at x=0, so the function R_{2,1}(x) is indeed the Pade approximant. Algorithm 3(a,b) of Section 4.6, p.250. (a) The following Matlab commands generate the needed graphs: >> x=-1:0.01:1; z=tan(x); % lots of x values for a smooth-looking plot >> t9=x+(1/3)*x.^3 + (2/15)*x.^5 + (17/315)*x.^7 + (62/2835)*x.^9; >> r54 = (945*x-105*x.^3 + x.^5)./(945-420*x.^2+15*x.^4); >> plot(x,z) % original function >> plot(x,t9) % Taylor approximation >> plot(x,r54) % Pade approximation >> plot(x,t9-z) % difference: Taylor - Exact >> plot(x,r54-z) % difference: Pade - Exact (b) From those graphs, it seems that the greatest approximation error occurs at the right endpoint, x=1: | T9(1) - tan(1) | ~ 1.5 e -2 | R54(1) - tan(1) | ~ 3.1 e -7 The Pade approximation seems much better.