CHAPTER 03.05: SECANT METHOD: Example of Secant Method

 

In this segment, we're going to take an example of the secant method. Secant method is a way to find out roots of a nonlinear equation.  So let's suppose somebody says, hey, x cubed is equal to 20, find the root of this equation, x cubed equal to 20, and you are given the initial guesses to be, let's suppose x0 is given as 4.0, x1 is given as 5.5, so these are the initial guesses, and somebody's saying find the estimate after two iterations. So that's the formulation of the problem statement, that you are given the root of . . . you are asked to find out the root of the equation x cubed is equal to 20, the initial guesses, two initial guesses which you're asked to use, or which you may choose, is 4.0 and 5.5 for this particular equation, and you're asked to conduct . . . find the estimate of the root after two iterations.  So let's go ahead and see how we can go about doing that.  The first thing which you have to understand is that x cubed is equal to 20 is given to us, so this is the solution here, we are given x cubed is equal to 20, so we have to rewrite it in the form x cubed minus 20 is equal to 0.  So that's the first thing which we have to do, because secant method, Newton-Raphson method, bisection method, most of the methods to solve nonlinear equations do require you to write down the equation in the f of x equal to 0 form.  There are a few methods which allow you . . . which require you to write it in a different form, but most of them are in the form of f of x equal to 0, so you do need to know what the method works for, in what form.  So it works in the form of f of x equal to 0, so x cubed minus 20 is equal to 0, so we need to find the root of this particular equation, with my initial guesses being 4 and 5.5.  So let's go ahead and apply the formula, so we have x-sub-i-plus-1 is equal to xi minus the value of the function of xi, times xi minus x-sub-i-minus-1, divided by the value of the function at xi minus the value of the function at x-sub-i-minus-1.  So this is a general formula for the secant method, and what we want to be able to do is use this particular general formula to be able to conduct our two iterations, so I'm going to say, let's suppose i is equal to 1.  What do I get from here?  I get x2 is equal to x1 minus the value of the function at x1, times x1 minus x0, divided by the value of the function at x1 minus the value of the function at x0, that's what I get here. So, what is x1?  x1 is nothing but 5.5.  What is the value of the function at x1?  It is 5.5 cubed minus 20, all I'm doing is plugging in the value of x1 equal to 5.5 into my function, and my function is x cubed minus 20, so I get 5.5 cubed minus 20, times x1, which is 5.5, x0 is 4.0, divided by the value of the function at x1, which is 5.5 cubed minus 20, minus the value of the function at x0, which is 4, so 4 cubed minus 20, and this value here turns out to be 3.353. So that's my estimate of the root of the equation x cubed equal to 20, or x cubed minus 20 equal to 0, based on the initial estimate of 4 and 5.5.  Now, what is my absolute relative approximate error for this case will be the present approximation, x2, minus the previous approximation, divided by x2, times 100, and the present approximation is 3.353, the previous approximation, x1, is 5.5, divided by the present approximation, which is 3.353, times 100, and this number here turns out to be 63.92 percent. Okay, now keep in mind that the previous approximation which you are using is 5.5, somebody say, hey, why can't I use 4.0?  It's all about the assignment, what you have given the assignment to x0 and x1 when you are conducting this.  So, since you assigned x0 equal to 4 and x1 equal to 5.5, so you've got to use 5.5 there, you cannot just pick and choose the way you want to, because when you're going to write the program for it, it'll be in a loop, and you'll be using current approximation, which will be i plus 1, and then i minus 1, and that's how it's going to choose 5.5 there for the . . . for the previous approximation. Let's conduct one more . . . one more iteration, because the question asks us to conduct two iterations, so what is i equal to 2?  i equal to 2 is x3 equal to x2 minus the value of the function at x2, times x2 minus x1, divided by the value of the function at x2 minus the value of the function at x1, so basically what you are doing is you are plugging in the value of . . . you are plugging in the value of i equal to 2 into your secant method formula, and this is what you are getting.  Now we already know what x2 is, x1 is given as 5.5, and x2 is nothing but 3.353, this is the estimate which we just found, and this is one of the previous estimates, so all we have to do is to plug those numbers into the formula.  So what I get for x3 will be equal to x2, which is 3.353, minus the value of the function at x2, which will be 3.353 cubed minus 20, because my function is x cubed minus 20, times x2 minus x1, which is 3.353 minus 5.5, because that's x2 minus x1, divided by the value of the function at x2, which is at 3.353, which is nothing but x cubed minus 20, the function is, so it is 3.353 minus 20, minus the value of the function at x1, which is 5.5, so it's 5.5 cubed minus 20.  So, that's what we get by substituting the values of x1 and x2 in there, and this value here now turns out to be 3.059. Now, if I want to find the absolute relative approximate error here, for this particular iteration, it will be the current approximation, which is x3, minus the previous approximation, which is x2, divided by x3, times 100. And, in this case, x3 turns out . . . x3, which we just found out, is 3.059, x2 is from the previous estimate, which is 3.353, 3.353, and divided by 3.059, and I'm going to multiply by 100 to be able to get the value of the absolute relative approximate error as a percentage, and this turns out to be 9.691 percent.  So, at the end of the second iteration, as required by the problem statement, is that the estimate of the root of the equation x cubed minus 20 is given as 3.059, and the absolute relative approximate error is given as 9.691 at the end of the second iteration.  And that's the end of this example, of this segment.