SonshineCS MathSolutions http://www.sonshinecs.com/mathsolutions/ Roots of Functions Background and Commentary Newton-Raphson and Secant Methods for Finding Roots of Functions General Background and Review It is frequently required to find the value of a component of a mathematical equation that satisfies the equation. For example, for the equation we may want to find the values of x that ‘satisfy’ the equation. In other words, we want to find those values of the variable x such that the left side of the equation is equal to 2. In this topic, we focus on three methods for solving the general equation f(x) = 0. Note that by focusing on methods for solving the equation f(x) = 0, we do not lose any generality in solving equations because any equation can be put in the form of f(x) = 0 simply by moving terms from one side of the equality to the other. For example, while the equation above may not appear to be one which is of the form f(x) = 0, we can make it such simply by subtracting 2 from both sides of the equation. Thus, the equation above becomes We conclude, therefore, that if we can solve an equation of the form f(x) = 0, we can solve any equation. Note further that values of the unknown x which satisfy the equation f(x) = 0 are referred to as the roots or zeroes of the function f(x). So that in solving the equation f(x) = 0 for the values of x which satisfy the equation, we are finding the roots of the function. Note also that, from a graphical point of view, the roots of the equation f(x) = 0 represent the locations on a graph of the function where the graph crosses the x axis. So then, in this topic we will be examining methods for finding the roots of functions of the form f(x) = 0 which translates graphically into methods for finding where the function f(x) = 0 crosses the x axis. Note that some functions may cross the x-axis more than once, meaning that there are multiple real roots, as shown on the following graph. -------------------------------------------------------------------------------------------------------------------------------------------------------------------------CS 450: Numerical Analysis 3/6/2016 In addition, some functions may not cross the x-axis at all, as shown on the following graph, meaning that the function has no real roots. Such functions may have complex or imaginary roots, which we will not consider at this time. The three methods (there are other methods in addition to these three) that we will consider are the Bisection Method (sometimes called the Half-Interval Method), Newton’s Method (also known as the Newton-Raphson Method), and the Secant Method. Bisection/Half-Interval Method The Bisection/Half-Interval method is one of several methods referred to as ‘bracketing methods’ for finding the roots of a given function. The basic idea in all bracketing methods is to find an interval along the x-axis (independent variable axis) which contains the root of the function with the interval small enough that the value of the root can be established to within some desired level of accuracy. Description Consider the function represented by the graph below with corresponding values shown in the table. -------------------------------------------------------------------------------------------------------------------------------------------------------------------------CS 450: Numerical Analysis 3/6/2016 x 0 5 10 f(x) -4.00 2.25 21.00 The bisection method begins by finding an interval [a, b] along the x-axis such that f(a) and f(b) are of opposite signs; that is, where the product f(a) f(b) < 0. If f(a) and f(b) are of opposite signs, there must be at least one place along the x-axis where the function crosses the axis; that is, where f(x) = 0. In the example above, if a = 0 and b = 10, then f(a) = -4.00 and f(b) = 21.00. Since f(a) f(b) = (-4.0)(21.0) = -84.0 < 0, there must be a root somewhere in the in [a, b] interval. The next step is to cut the interval in half; that is, let c = ( 0 + 10 ) / 2 = 5.0 for which f(c) = f(5) = 2.25. Now examine the two new intervals. For the interval [5, 10], f(5) and f(10) are both of the same sign; that is, f(5) f(10) = (2.25)(21.0) = 47.25 > 0. Therefore, the function does not cross the x-axis between x = 5 and x = 10, so the root must lie in the interval between x = 0 and x = 5. We can confirm this by calculating the product f(0) f(5) = (-4.0)(2.25) = -9.0 < 0. So that the function does in fact cross the x-axis somewhere in the interval [0, 5]. If we now re-define the [a, b] interval for a = 0 and b = 5, we can repeat the process until the interval [a, b] is smaller than some value we choose, such as 10-6. We could then take either the value of a or the value of b as the value of the root of the function. Alternatively, we could take the average of the final [a, b] interval as the value for the root; that is, let the root value for x equal (a + b) / 2. As yet another approach to terminating the iterative procedure, we could choose to terminate when the value of the function itself at either x = a or x = b is less than some selected value. Since we are finding the root of the function (that is, the value of x which makes the value of the function equal to zero), we could choose to terminate when the value of the function is sufficiently close to zero. -------------------------------------------------------------------------------------------------------------------------------------------------------------------------CS 450: Numerical Analysis 3/6/2016 Error Analysis Let and define the starting interval for the bisection method iterations, and let define the interval size after the i-th interation. Then and Thus we can say that the error in the value of the root of the function after n iterations is given by From this relationship we can also determine the number of iterations needed to satisfy some given error criterion: Advantages and Disadvantages Two advantages of the bisection method (or of any of the bracketing methods in general) are: -------------------------------------------------------------------------------------------------------------------------------------------------------------------------CS 450: Numerical Analysis 3/6/2016 1. the procedure always converges; that is, a root will always be found, provided that at least one root exists. 2. there is good information available about the error associated with the result. Two disadvantage of the bisection method are: 1. the method converges relatively slowly. 2. many iterations may be required. Newton’s (Newton-Raphson) Method The Newton-Raphson method is one of several methods for finding roots of functions classified as slope methods. Slope methods use the slope of a straight line to project to the location of a root on the x-axis. Description Recall from Calculus that the first derivative of a function represents the slope of the function at any given point on the curve, as illustrated in the following diagram. If m represents the slope of the function f(x), then we can write the following relationship: -------------------------------------------------------------------------------------------------------------------------------------------------------------------------CS 450: Numerical Analysis 3/6/2016 Noting that , Solving for x1, Then, similarly, In general, -------------------------------------------------------------------------------------------------------------------------------------------------------------------------CS 450: Numerical Analysis 3/6/2016 Thus, we have an iterative algorithm such that, given some starting value for x = x0, we can solve the algorithm repetitively until two successive values of x are within some arbitrary limit; that is, until Advantages and Disadvantages The Newton-Raphson method generally provides rapid convergence to the root, provided the initial value x0 is sufficiently close to the root. How close is ‘sufficiently close’? That depends on the characteristics of the function itself. As illustrated by the following graphs, certain initial values of x may cause the solution to diverge or not produce a valid result. In example (a) above, a runaway situation is encountered where the solution algorithm does not yield a finite value for the result. In example (b) above, a flat spot on the curve is encountered which does not produce an new value of x which lies on the x-axis. Since the slope of a horizontal line is zero, this situation could also result in a divide-by-zero computational error, causing a computer program to crash. In example (c) above, a cyclical or oscillatory situation is encountered where the solution algorithm produces values of x which cycle back and forth between the same values and never do converge. Overall, the Newton-Raphson method is a widely used technique which produces good results provided its limitations are recognized. -------------------------------------------------------------------------------------------------------------------------------------------------------------------------CS 450: Numerical Analysis 3/6/2016 Secant Method The Secant method is another of the methods for finding roots of functions classified as slope methods. This method is similar to the Newton-Raphson method but avoids the calculation of derivatives. Description While the Newton-Raphson method can be started with only one x-f(x) combination, the secant method begins with two separate values. Consider the following diagram. Let m represent the slope of the straight line between two points on the curve of f(x), that is, a secant line over an arc of the function. Then we can write the following relationship: Noting that , Solving for xn + 1, -------------------------------------------------------------------------------------------------------------------------------------------------------------------------CS 450: Numerical Analysis 3/6/2016 Thus, we have an iterative algorithm such that, given two starting values for x = x0 and x = x1 we can solve the algorithm repetitively until two successive values of x are within some arbitrary limit; that is, until Advantages and Disadvantages The Secant method generally provides fairly rapid convergence to the root but not as rapidly as the Newton-Raphson method. However, one might note that, except for the starting iteration, the secant method requires the evaluation of only one function per iteration while the Newton-Raphson method requires that two functions (the function and its derivative) for each iteration, since the (n + 1) values from one iteration can be used as the (n) values for the next iteration. Similar to the Newton-Raphson method, the secant method may also encounter runaway, flat spot, and cyclical non-convergence characteristics as described above. -------------------------------------------------------------------------------------------------------------------------------------------------------------------------CS 450: Numerical Analysis 3/6/2016