Spring 2009 STATISTICS 580 Assignment No. 1 (40 points) 1. Write an R function secant(fun, x0, x1, epsx, epsf) using the secant algorithm to compute roots of a function. For this algorithm, you need to specify two starting values x0 and x1, and stopping constants epsf and epsx. Include print statements in your function to monitor progress. Invoke secant to find the smallest positive root of the following functions. √ a) x3 + x − 1 b) log(1 + x2 ) − c) 1 x+1 sin(x2 + 1) − x3 d) x3 − sinh x + 4x2 + 6x + 9 First define R functions f1, f2, f3 and f4 corresponding to these functions. Perform a search to locate appropriate starting values using R plots of these functions. (Show plots you used in your solution). 2. The secant method has superlinear convergence with |n+1 | = O(|n |1.618 ), but like Newton’s method an iterate can be thrown far away from the root in a region where the function is very flat. An algorithm that combines the safety feature of the bisection algorithm (i.e., keeping the iterates bracketed between two specified values) and still retain superlinear convergence is the Illinois method discussed in class. Write an R function illinois(fun, x0, x1, epsx, epsf) to implement Illinois method to find the root of a function defined by the user as an R function fun and passed as an argument to illinois along with two starting values x0 and x1, and stopping constants epsx, epsf. Use illinois() to find the smallest positive root of each of the functions in Problem 1. Compare the performance of secant and illinois methods for finding the root of Problem 1(c). (For this comparison for secant use x(0) = .1 and x(1) = .2, .3, .4, .5 and for illinois use x(0) = .1 and x(1) = 1.0) 3. To find the root of f (x) = x2 − 4x + 2.3 = 0 using a simple iteration, f (x) = 0 is reformulated as x = g(x) in the following forms: a) x = (x2 + 2.3)/4 1 b) x = (4x − 2.3) 2 c) x=4− d) x = x + 2.3 x x2 −4x+2.3 10 Determine which of these result in convergent fixed point iterations for the zero of f (x) in the interval [0, 1]. That is, show that g(x) has a fixed point in [0, 1]. Then verify whether one of Condition 1 or 2 holds to check if a unique root of x − g(x) exists in this interval. 1 4. Write an R function fixedpoint(g, x0, nlim, epsx, epsf) to implement the fixed point method where g ≡ g(x) of simple iterations, x0, epsx, epsf, are as defined in earlier problems, and nlim is used to set an upper limit on the number of iterations. Apply fixedpoint() to one of the convergent iterations (i.e. a g() function) from the previous problem, starting with x(0) = 0.1, to find the the root of f (x) = x2 − 4x + 2.3 = 0 = 0 in [0, 1]. Evaluate and print all iterates until an accuracy of at least 7 digits is reached, identifying each with the iteration number. 5. To speed up simple iterations whose order of convergence is known to be linear Aitken acceleration described in your notes can be used. One way to implement it is Steffensen’s method which has quadratic convergence. Write an R function for implementing this method (call it steffenson()) by modifying fixedpoint(). Re-compute the root of f (x) = x 2 − 4x+2.3 = 0 = 0 in [0, 1] using steffensen() starting with x(0) = 0.1. Print iteration number and the iterate until 7 digit accuracy is reached as before. 6. Derive simple iterations of the form xi+1 = g(xi ) for finding all the roots in the range [−3, 3] of the function f (x) = x + sin x − x3 /3 First bracket each zero in an interval by sketching the function, so that the selected g(x) has a fixed point in that interval. Then use one of the two conditions needed to be satisfied to verify the existence of a unique root of x − g(x) in that interval. Repeat this for each zero in [−3, 3]. Use the functions fixedpoint() and steffensen()) above to find the zeros of f (x) = x + sin x − x3 /3 (to at least 7 digit accuracy). Note: You may discuss these problems with others in class but you need to write your own R functions and turn-in your own written answers. Remember to turn-in all supporting output e.g. plots you used to get starting values etc. DUE, Tuesday 10, February, 2009 2