Math 449 - Homework 6 - Solutions 1) Exercise 7, section 4.4, page 229. f(x)=3*(sin(pi*x/6))^2 (a) Divided-difference table: k | x_k f[x_k] f[ , ] f[ , , ] f[ , , , ] f[ , , , , ] __|____________________________________________________ 0 | 0.0 0.00 | 1 | 1.0 0.75 0.75 | 2 | 2.0 2.25 1.50 0.375 | 3 | 3.0 3.00 0.75 -0.375 -0.250 | 4 | 4.0 2.25 -0.75 -0.750 -0.125 0.03125 (b) Write down the Newton polynomials P_1(x), P_2(x), P_3(x), and P_4(x). P_0(x) = 0.00 P_1(x) = 0.00 + 0.75(x-0) P_2(x) = 0.00 + 0.75(x-0) + 0.375(x-0)(x-1) P_3(x) = 0.00 + 0.75(x-0) + 0.375(x-0)(x-1) - 0.250(x-0)(x-1)(x-2) P_4(x) = 0.00 + 0.75(x-0) + 0.375(x-0)(x-1) - 0.250(x-0)(x-1)(x-2) + 0.03125(x-0)(x-1)(x-2)(x-3) So we have: P_4(x) = 0.75x + 0.375x(x-1) - 0.25x(x-1)(x-2) + 0.03125x(x-1)(x-2)(x-3) (c) At x=1.5 and 3.5 we have x 1.5 3.5 ____________________________ P_0 0.0 0.0 P_1 1.1250 2.6250 P_2 1.4062 5.9062 P_3 1.5000 2.6250 P_4 1.5176 2.8301 f(x) 1.5000 2.7990 (d) The values of f(x) at the interpolated points 1.5 and 3.5 are shown on the last row of the previous table. ************************************************************************** 2) Exercise 1 (a, b) of section 4.5, page 241. We start with T_2(x) = 2x^2 - 1 T_3(x) = 4x^3 - 3x and use the recurrence relation T_k = 2xT_(k-1) - T_(k-2) to obtain T_4 and T_5: (a) T_4(x) = 2xT_3(x) - T_2(x) = 2x(4x^3 - 3x) - (2x^2 - 1) = 8x^4 - 8x^2 + 1 (b) T_5(x) = 2xT_4(x) - T_3(x) = 2x(8x^4 - 8x^2 + 1) - (4x^3 - 3x) = 16x^5 - 20x^3 + 5x. ************************************************************************** 3) Algorithms and programs 4 (a) of section 4.5, p. 242. Compute the coefficients {c_k : k=0, 1, 2, ...} for the Chebyshev polynomial approximation P_N(x) to f(x)=log(x+2) over [-1,1] for N=4. See below for instructions on using program 4.3. (a) C = [0.6238 0.5359 -0.0718 0.0128 -0.0025] To obtain the Chebyshev coefficients, use the program cheby below. For example, for f(x)=log(x+2) and N=4, enter at the prompt the command line: [C, X, Y] = cheby('log(x+2)', 4) The values of the vector C are the the coefficients c_0, c_1, etc. One way in which you can plot the function P_N(x) = c_0T_0(x) + c_1T_1(x) + ... + c_NT_N(x) is as shown below the program. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function [C,X,Y]=cheby(fun,n,a,b) %Input - fun is the string 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 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; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%To plot the Chebyshev polynomial and the function%%%%%%%%%%% N=4; C=cheby('log(x+2)',N); x=-1:0.001:1; [s m]=size(x); T=zeros(N+1,m); T(1,:)=1; T(2,:)=x; for i=3:N+1 T(i,:)=2*x.*T(i-1,:)-T(i-2,:); end P=C*T; plot(x,P) hold on z=-1:.1:1; plot(z,log(z+2),'o') %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ************************************************************************** 4) Exercise 2 (a, b) of section 4.6, page 248. (a) Find the Pade' approximation R_(1,1)(x) for f(x)=ln(1+x)/x. ln(1+x)/x = 1- x/2 + x^2/3 - ... = R_(1,1)(x) = (p_0 + p_1x)/(1 + q_1x) Multiplying both sides by 1 + q_1x gives: (1- x/2 + x^2/3 - ...)(1 + q_1x) = p_0 + p_1x + terms of oder 3 or greater. This gives: (1 - p_0) + (q_1 - 1/2 - p_1)x + (1/3 - q_1/2)x^2 = 0, so q_1=2/3, p_0=1, p_1=2/3-1/2=1/6. Therefore R_(1,1)(x)=(1 + x/6)(1 + 2x/3)=(6 + x)/(6 + 4x). (b) The result of part (a) gives ln(1 + x) = (6x + x^2)/(6 + 4x) + terms of order 4 or greater. Therefore R_(2,1)(x) = (6x + x^2)/(6 + 4x) is the Pade' approximation of ln(1+x). ************************************************************************** 5) Algorithms and programs 1 (a, b) of section 4.6, page 250. See the graphs of e^x - T_4(x) and e^x - R_(2,2)(x) on the separate file. **************************************************************************