Math 449 - Homework 1 - Solutions 1) 14 (a) of section 1.1, page 12. We look for the coefficients of the polynomial Q(x)=b_4x^3 +b_3 x^2 +b_2 x + b_1, and b_0=P(c), such that P(x)=(x-3)Q(x) + b_0. The coefficients of P(x) are a_4=1, a_3=1, a_2=-13, a_1=-1, a_0=-12. The algorithm for Horner's method is: b_4=a_4 =1 b_3=a_3+c*b_4 =1+3*1 =4 b_2=a_2+c*b_3 =-13+3*4 =-1 b_1=a_1+3*b_2 =-1+3*(-1) =-4 b_0=a_0+3*b_1 =-12+3*(-4) =-24 So P(3)=-24. ************************************************************************** 2) 2 (d) of section 1.2, page 23. 1000000111_(two)=2^9+2^2+2^1+2^0=512+4+2+1=519. ************************************************************************** 3) 3 (d) of section 1.2, page 23. 0.110110110_(two)=2^(-1)+2^(-2)+2^(-4)+2^(-5)+2^(-7)+2^(-8) =219/256 =0.85546875. ************************************************************************** 4) 1 (c) of section 1.3, pages 37-38. Absolute error: E_z=|z-z^|=0.00008 Relative error: R_z=|z-z^|/|z|=0.000008/0.000068=0.117 Since 0.5*10^(-1) < R_z < 0.5*10^(-0), z^ approximates z to 1 significant digit. ************************************************************************** 5) 5 (c) of section 1.3, pages 37-38. To avoid dealing with differences, we can use the identity cos^2(x)-sin^2(x)=cos(2x). ************************************************************************** 6) 10 of section 1.3, pages 37-38. exp(h) = 1 + h + h^2/2! + h^3/3! + h^4/4! + O(h^5) sin(h) = h - h^3/3! + O(h^5) Then exp(h) + sin(h) = 1 + 2*h + h^2/2! + h^4/4! + O(h^5) exp(h)*sin(h) = h + h^2 + h^3/3 + O(h^5). ************************************************************************** 7) Algorithms and Programs: 2 (b) of section 1.3, page 39. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % We want to generate the sequence {1/2^n : n = 1, 2, ... , m} using the % recursive scheme % % p(n) = (3/2)*p(n-1) - (1/2)*p(n-2) % % with two initial conditions: First, p0 = 1 and p1 = 1/2. This gives the % correct sequence 1/2^n. Second, with p0 = 1 and p1 = 0.497, which % introduces a small error. One possible MATLAB script for this is % as follows. m = 10; % This is the number of terms in the sequence. p0 = 1; % These are the conditions for the first case. For the second, p1 = 0.5; % we take p1 = 0.497. p=[p0 ; p1]; % This creates a column vector of dimension two containing p0 and p1. % Notice that p(1)=p_0 and p(2)=p_1. A=[3/2 -1/2 ; 1 0]; % The matrix A multiplied by the vector [p(n-1) ; p(n-2)] gives % the vector [p(n) ; p(n-1)]. for n=1:m-2 q = [p(n+1) ; p(n)]; q = A*q; p = [p ; q(1)]; % Adds to the vector p a new entry equal to the top entry of q. end % We compare this sequence with what is obtained by direct calculation of x(n+1)=1/2^n i = 0:1:m-1; x = 2.^(-i); % The sequence of errors is now e = x' - p; % The apostrophe indicates transpose. % In the first case (p1 = 0.5) the resulting table is: % iteration x p e 1.0000 1.0000 1.0000 0 2.0000 0.5000 0.5000 0 3.0000 0.2500 0.2500 0 4.0000 0.1250 0.1250 0 5.0000 0.0625 0.0625 0 6.0000 0.0312 0.0312 0 7.0000 0.0156 0.0156 0 8.0000 0.0078 0.0078 0 9.0000 0.0039 0.0039 0 10.0000 0.0020 0.0020 0 % In the second case (p1 = 0.497) the resulting table is: % iteration x p e 0.0000 1.0000 1.0000 0 1.0000 0.5000 0.4970 0.0030 2.0000 0.2500 0.2455 0.0045 3.0000 0.1250 0.1198 0.0052 4.0000 0.0625 0.0569 0.0056 5.0000 0.0312 0.0254 0.0058 6.0000 0.0156 0.0097 0.0059 7.0000 0.0078 0.0019 0.0060 8.0000 0.0039 -0.0021 0.0060 9.0000 0.0020 -0.0040 0.0060 % The graph for the error e as a function of the iteration number is % obtained by plot(i, e' , '--rs') grid xlabel('iteration number') ylabel('error = x - p') title('Error for iteration scheme of HW 01, problem 7 - Your name here') **************************************************************************