Math 449 - Homework 2 - Solutions 1) 3 (b) and 3 (d), section 2.1, page 50: see graphs 1 and 2. ************************************************************************** 2) Algorithm 1 (b), section 2.1, page 51. After saving the function files fixpt.m and g.m, where g(x)=cos(sin(x)), we can enter the following command (I've chosen the initial point p0=1 after inspecting the graph.) >>[k, p, err, P]=fixpt('g',1,5*10^(-12),100) The above gives the value p=0.76816915673757, with a relative error of 3.2098e-12. Therefore, the approximation for the fixed point holds to 12 significant digits. See graph 3. ************************************************************************** 3) 9 of section 2.2, p. 61. (a) The function f(x)=1/(x-2) is positive over the interval [3, 7]. The bisection method does not apply. (b) The limits of a_n and b_n as n goes to infinity are both equal to 2, even though the function is not defined at 2. ************************************************************************** 4) 11 of section 2.2, p. 61. The bisection theorem (Theorem 2.4) gives |r-c_n| less than or equal to (b-a)/2^(n+1). For this number to be less than 5*10^(-9) we need (7-2)/2^(n+1)< 5*10^(-9). Solving for n gives: n+1 > 9/log 2 (where this log has base 10.) That is, n > 28.89 Therefore, n=29. ************************************************************************** 5) Problem 2 in "Algorithms and Programs" of section 2.3, p. 69. We first define a function file with the function to be investigated. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function y=g(x) y=1000000*x.^3 - 111000*x.^2 + 1110*x - 1; %%%%The above is saved in the Matlab folder to a file named g.m%%%%%%%%%%% The program for approximate location of roots (page 68) given below should also be saved to a function file. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function R = approot(X,epsilon) % Input - g is the object function saved as an M-file named g.m % - X is the vector of abscissas % - epsilon is the tolerance % Output - R is the vector of approximate roots Y=g(X); yrange = max(Y) - min(Y); epsilon2 = yrange*epsilon; n=length(X); m=0; X(n+1)=X(n); Y(n+1)=Y(n); for k=2:n if Y(k-1)*Y(k)<=0 m=m+1; R(m)=(X(k-1)+X(k))/2; end s=(Y(k)-Y(k-1))*(Y(k+1)-Y(k)); if (abs(Y(k))) & (s<=0) m=m+1; R(m)=X(k); end end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% To obtain candidates for the roots to four decimal places over the interval [-2, 2] we use the program approot as in example 2.10: >> X=-2:.001:2; >> approot(X,0.00001) This gives the numbers 0.0015 0.0050 0.0095 0.0690 0.1005 2.0000 A closer examination of the graph near these values shows that only 0.0015, 0.0095, and 0.1005 lie near a root. (There are at most three roots of a third degree polynomial, so these are all the roots.) Further examination gives the intervals where the function changes sign: [0.000, 0.002], [0.009, 0.011], [0.095, 0.105]. We can now apply, say, the bisection method to find the roots to any desired degree of accuracy. ************************************************************************** 6) Exercise 2 of section 2.4, p. 85. (a) p_(k+1) = p_k - (p_k^2 - p_k -3)/(2*p_k - 1). (b) Starting with p_0=1.6 gives: p_1=2.5273, p_2=2.3152, p_3=2.3028, p_4=2.3028 (c) Starting with p_0=0.0 gives: p_1=-3.0, p_2=-1.7143, p_3=-1.3410, p_4=-1.3032 p_5=-1.3028, p_6=-1.3028. Conjecture that it converges to -1.3028. ************************************************************************** 7) Exercise 11 of section 2.4, p. 86. This follows from a direct application of the Newton-Raphson iteration formula and a little algebra. **************************************************************************