 Hi everybody, we are discussing numerical methods for non-linear equations. In this, we are discussing bracketing methods. Under this category, we are interested in introducing two methods. One is bisection method and another one is the regular falsely method. In the last class, we have introduced bisection method. We also did convergence analysis for bisection method and also we quickly gone through how to code bisection method, right. Today, we will start our second method on bracketing methods type that is the regular falsely method and then we will also pause on to the non-bracketing methods. In that, we will discuss the first method called secant method. Secant method is a slight modification of the regular falsely method. Let us start our discussion on regular falsely method. Regular falsely method is a bracketing method. Therefore, if you recall a bracketing method needs initially an interval to be specified where there is at least one root line, right. So, this is what we have also seen in the bisection method. Therefore, we need the following two hypothesis for regular falsely method in order to start the method. These two hypothesis if you recall are the same as we had in the bisection method. In fact, regular falsely and bisection method, the underlying algorithm is the same. Only difference between these two methods is in the way how we split an interval in each iteration. Therefore, the hypothesis for regular falsely method goes like this. We have to find an interval a naught b naught such that the function f is defined on the interval a naught b naught and it should be continuous. What is that function? The function f is actually defining our equation f of x equal to 0. And the second condition is that f of a naught into f of b naught is less than 0. Since f is continuous, this condition will ensure that there exists at least one root in the interval a naught b naught. We have seen that this is a simple application of the intermediate value theorem, right. Once you set your hypothesis, then our interest is to see how to split the interval a naught b naught to get a interval a 1 b 1 whose length is smaller than the interval a naught b naught's length, right. So, that is the only way that the regular falsely method will differ from the bisection method. If you recall in the bisection method, we define x n plus 1 is equal to a n plus b n divided by 2. That is, you obtained an interval at the nth iteration given by a n and b n and then in order to get the interval for the n plus 1th iteration, you have to bisect the interval a n and b n. That is, take the midpoint of this interval and define that as x n plus 1 and that is the point where you are breaking this interval a n and b n, right. Now, the question is in the regular falsely method, how are we breaking the interval a n and b n. That is, you have to assume that you have obtained an interval a n and b n at the nth iteration and now in order to go to the n plus 1th iteration, the basic idea is to split this interval a n b n into 2 parts. Well, to understand the method geometrically, let us consider a function f of x whose graph is given like this and we are interested in capturing the root r here and for that assume that we have located this root in the interval a n b n given like this. Now, previously what we do is we just bisect this interval, but now what we are going to do is you take two points a naught comma f of a naught and b naught comma f of b naught and then draw the secant line joining these two points. That is the idea. Now, take the point x 1 as the point of intersection of this secant line with the x axis. So, this is the secant line. Once you locate your x 1, then getting the interval a 1 b 1 is something similar to what we did in the bisection method. That is, you have to see where the root lies, whether the root lies in the first part of the interval or at the second part of the interval. In this particular example, you can see that the root lies in the second part of the interval. That is, it lies between x 1 and b naught. Therefore, we will discard the interval a naught to x 1 and we will take a 1 as x 1 and b 1 as b naught. Now, what we will do? Again, you take this point which is a 1 comma f of a 1 and similarly, the same point b 1 comma f of b 1 and then again draw the secant line joining these two points. Take the point of intersection of this secant line with the x axis as x 2 and again, you apply the same idea of locating the root. You will see that the root in this example lies in this interval and it goes on like that. You will discard this part of the interval and take the second part of the interval in this particular example and the iteration sequence goes on like this. Now, the question is how to derive x 1, x 2 and so on? That is, how to derive the expression or formula for x 1 and x 2 and so on? In general, how to derive the formula for x n plus 1 given a n and b n? That is the question. In bisection method, it is just a direct idea. You just take the midpoint. Therefore, we know how that expression looks like. But here, we have to get the expression for x n plus 1. Well, that is not very difficult because we know how to write the equation of the line joining two points a naught f of a naught and b naught f of b naught is given like this. So, this is called the secant line and the slope of this line is given like this. So, we know this formula from our basic geometry course and therefore, it is not very difficult. In fact, you can directly see by putting x equal to a naught, you will get y equal to f of a naught and putting x is equal to b naught, you will get y equal to f of b naught. Now, what we want? We want to get this x 1 in such a way that y is equal to 0. So, y should be 0 at the point x equal to x 1. So, what you do? You put y equal to 0 and x equal to x 1 in this expression and that gives you y equal to 0 and x is equal to 0 and x is equal to x 1 here. From here you can get what is x 1 and x 1 is given like this. So, therefore, we obtained the expression for x 1 and now how to get the interval a 1 comma b 1? That is the question. Well, we have already explained it also. We know it from our bisection method itself. Once you get a 1 and b 1, again you calculate x 2 which is given by a 1 minus f of a 1 b 1 minus a 1 divided by f of b 1 minus f of a 1. Once you get x 2 from there, you will get the interval a 2 comma b 2 and like that you will go on with your iteration. That is the idea of the regular falsi method. The only new thing that comes is how you will define the point at which you have to split your interval at every iteration. That is the only new thing that you have to understand and that has a very nice geometric interpretation like this. I hope you have understood the regular falsi method. Note that this expression can also be written like this. This is just a mathematical simplification. You can also write x 1 in this form, but never use this form of the expression. You always use this form of the expression in your code. Why it is? I will leave it to you to see why we do not prefer this form of the expression, although both these are mathematically same. The reason is that this will may lead to loss of significance. I will leave it to you to think why it is. Let us formulate the algorithm now. For n is equal to 0, 1, 2 and so on, you should look at this expression by putting n is equal to 0 first and then n equal to 1 and so on. When you put n equal to 0, you get x 1 and that is given in terms of a naught and b naught are given to us as inputs. Therefore, in that way you can compute x 1. Once you get x 1, then you have to go ahead with the algorithm. How the algorithm goes? From now onwards, it is exactly the same as what we did with the bisection method. First you see whether the computed value x n plus 1 coincides exactly with the root. That is check whether f of x n plus 1 equal to 0. As I told you, this may not happen at all computationally because you always have a rounding error. Therefore, you may not always get exactly the root, right, but still we may just check this condition just for formality and then if this is not satisfied, then you will go to check this condition. If this is also not satisfied, then this will surely be satisfied, ok. So, one of these two will surely be satisfied if this is not satisfied and again I will tell you this is more likely will not be satisfied. So, you will come across one of these two conditions only. If the first condition is satisfied, then you will take a n plus 1 comma b n plus 1 as a n comma x n plus 1 if this condition is satisfied. On the other hand, if this condition is satisfied, then you will take our interval as x n plus 1 to b n and now you are ready to go for the next iteration that is the n plus second iteration. Again you will go to compute x n plus second equation. Again you will come to check this condition and the iteration will keep on going. Now you have to worry about where to stop this iteration because on a computer we cannot go on doing this, right, somewhere we have to stop. What are all the situation where you can stop? Obviously, if x n plus 1 coincides with the exact root, then we are stopping our iteration, right, but this may not happen always. Therefore, one has to think about the stopping criteria. If you recall in the bisection method we had a very natural stopping criteria that b n minus a n should be less than epsilon for some given epsilon which is the tolerance parameter, right. This is the stopping criteria we have imposed for bisection method. Why we did this? Because at every iteration you are necessarily breaking the interval into half. In that way the length of the interval is actually shrinking to 0 as n tends to infinity, right. That was the nice part of the bisection method because of that this condition will always hold at some n. That is what you can see because it is actually this number is going to 0, right. Therefore, at some n it will surely cross whatever epsilon you give, however small it is. But in regular falsely method this may not happen. Why? Let us go back to our geometry and see. It is very clear from the way we have drawn the geometrical interpretation of the regular falsely method at our first slide. You can see here that x 2 is given like this, right. Now x 3 will come the point of intersection of this secant line with the x axis. So, this is your x 3 and how x 4 is given? x 4 comes like this. Now you can see that x 3 is given as smaller interval like this. x 4 gives you a smaller interval like this. So, from here you can clearly see that the interval length is shrinking, but as n tends to infinity it will only tend to r that is x n will only tend to r at least geometrically you can see. And therefore, the length of the interval will tend to the length of the interval r comma b naught in this particular example. So, this is a very good example where you can see that the interval length may not shrink to 0 in the regular falsely method unlike in the bisection method. Therefore, the natural criteria for stopping your iteration that we followed in the bisection method will not hold in the regular falsely method. So, this will not hold in the regular falsely method. Therefore, it is really a difficult question for us to now think how to stop the iteration? Well, one way to stop the iteration is to check this condition, right. This is the typical error that we would like to make it to 0, right. Of course, you have one more condition that f of x k is also almost equal to 0 that we will come little later, but mostly we are interested in this, but unfortunately you cannot check this condition why because we do not know r, right. The root of the equation that we are interested to capture is not known to us. In fact, that is why we are going for an approximation method, right. Therefore, this condition although may be preferred, but practically not possible. The next criteria is to just decide some natural number k and run the loop for i equal to say 0 to n, right. So, in that way you perform n iterations and then finally, declare whatever x n comes as the approximation to r. But this is rather blind why because even if you have a large value of k there is no guarantee that after performing that many iterations you are pretty close to the root. Sometimes the convergence may happen very slowly and therefore, even after a large number of iterations you may not be tending very close to the exact root. Therefore, this may be easy to implement, but rather it is a blind approach. Another stopping criteria which we actually prefer is the Cauchy condition. So, what it says that for some real number epsilon that is your tolerance parameter what you do is you first compute the n iterations where n is also decided by you beforehand and once you compute n iterations from n plus 1 iteration onwards you check this condition that is x k where k runs from n plus 1 to and so on. So, x k minus x k minus n is less than epsilon. After running each iteration you check this condition if that condition is satisfied for some k then you stop the iteration. You can see that all these quantities are known to us therefore, you can explicitly calculate this number and therefore, you can check this condition. So, this is a nice condition that can be implemented and we know that Cauchy sequence converges on a real line. Therefore, if you check this then you can in fact, be confident that you are going very close to the root of your equation. You can also impose the relative form of the Cauchy criteria that is you just take the relative error in x k minus n when compared to x k minus n. So, you take the relative error to x k and that will also give you a very reliable stopping criteria. So, we mostly prefer this criteria with possibly n is equal to 1 or 2 you do not need to go for a bigger n. Another one is the well known residual error. We have already seen this while solving linear systems this may also be a criteria for us to stop the iteration. As I told the residual error alone or Cauchy criteria alone may not lead to a good idea of the approximation. In fact, you have to check both the conditions simultaneously, but often we tend to use one of them. More often we prefer to use the Cauchy criteria as this stopping criteria for our iterations. Let us take an example use regular falsely method to find an approximate solution to the non-linear equation sin cube x plus 1 by 2 x to the power of 10 minus 0.85 equal to 0. Therefore, we are taking this as our function f of x. You can see that the interval 0 1 can be taken as the initial guess you can take anything else, but I am just taking here the interval 0 1 as my initial guess. You can check that f of 0 is equal to minus 0.85 which is negative and f of 1 is also positive you can check that. Therefore, 0 1 is a nice interval that satisfies our hypothesis and also the function given here is a continuous function defined on the interval 0 comma 1. Let us go to compute x 1 remember x 1 is given by a naught minus f of a naught minus naught into b naught minus a naught divided by f of b naught minus f of a naught where a naught is given by 0 and b naught is given by 1. From here you can get x 1 and now once you get x 1 you have to find the interval a 1 comma b 1 and that is given by x 1 comma b naught. I will leave it to you to check this it is not very difficult. In fact, we will see the geometric interpretation in the next slide and once you get a 1 b 1 then you plug in that into your formula for regular falsely method to get x 2 and that gives you the interval for the next iteration that is the third iteration and that is taken to be x 2 comma b 1 and you keep on going like this. Just for the information the root that we are trying to converge by taking this as the interval is given by r is equal to 0.9528 and so on. Therefore, we are trying to converge to this root which is also seen from these 2 iterations. In fact, if you go on doing the iteration you will in fact see that the sequence is actually converging to this root. This is the geometric interpretation for the example that we have taken. The function graph is given like this. This is your f of x and the red lines or the secant lines and the first iteration is obtained by looking at the point of intersection of this line with the x axis and that is given by x 1 here and once you have x 1 then you take x 1 comma f of x 1 as the next step you have to see in which interval the root lies. In this case the root lies in this interval. Therefore, we are taking a 1 comma b 1 as this and then you go to draw the next secant line and that gives you x 2 and it goes on like this. Then the third iteration is done by joining this point and this point. Just assume that this is a straight line then you have x 3 somewhere here and every iteration you have to see where the root lies that is the idea of regular false method it is a bracketing method. So, in the second iteration you will discard this interval and take this interval and it goes on like this. You can also see that in this example also that the interval length is not shrinking to 0 because you will always go from this side and at most you will go to the point r. Your iterations x n will never jump on the right hand side of r that is the problem. So, therefore, this is also an example where regular false method iteration intervals may not shrink to 0 in their length. With this our discussion on regular false method is over. Let us continue our discussion to the non bracketing methods that is open domain methods. In open domain methods we will discuss the secant method as our first method. Secant method is almost the same as regular false method there is no new idea involved in secant method. The only new idea is the way we implement the method that is all. It is otherwise a straight forward modification of the regular false method. What is the idea in secant method? If you recall in regular false method what we did is we have to locate the interval a naught b naught in such a way that there is at least one root lying in the interval a naught b naught. Now, this may not be always required because just take instead of a naught b naught on the either side of the root let us take a naught b naught on only one side of the root and see what is happening. Then you can see that you have a naught here and b naught here and therefore the point x 1 is obtained by joining these two points and see where that secant line cuts the x axis that is your x 1. Now what you do? You remove a naught and take x 1 and b naught and try to draw the secant line again. You see the same convergence in fact happening in a very nice way here. So, this is your x 2 and now what you do? You remove b naught take x 1 and x 2 and again draw the secant line between them and that will go like this and in that way also we are forming a sequence that is converging to the root at least in this example. Therefore, the fact is that locating the root in a interval as far as the regular falsing method is concerned is something which is not that important. So, you can relax that because that is the main burden for us because we do not have a automated algorithm to locate a root either you have to do it by trial and error on a computer which may take lot of time or you better do it manually even manually doing is some kind of trial and error only or you just have to draw the graph of the function and see where it cuts the x axis and in that way only you can find a initial interval for your bracketing methods, but that is not required as far as the regular falsing idea is concerned. You just throw any arbitrary two points say you throw x naught and x 1 instead of a naught and b naught let me use the notation x naught x 1 and then you compute from here you can compute x 2 because it is given by x naught minus f of x 1. So, that is the idea of x naught into that formula you can write and get x 2 once you get x 2 you keep x 1 and x 2 to get x 3 using the same formula as we gave in the regular falsing method and you can keep on going. So, that is the idea of secant method, but one problem is suppose your function is something like this. Now, what happens if at some iteration x n minus 1 and x n are such that f of x n minus 1 and f of x n are equal then what happens if you recall x n plus 1 is given by x n minus 1 minus f of x n minus 1. So, f of x n minus 1 into x n minus x n minus 1 divided by f of x n minus f of x n minus 1 right. If these two are equal then x n plus 1 is not defined that is what you can see from the expression. Geometrically what happens if these two points are equal then the secant line will become parallel to the x axis therefore, it will never intersect the x axis right therefore, the point of intersection will never exist. Therefore, at least to start with you have to be careful in choosing your x naught and x 1 you should choose these two points such that f of x naught is not equal to f of x 1. However, such a situation may happen at the further iterations in which case the secant method will fail. You can also check that in the regular falsely method such a situation will never occur that is why once you locate the root in a interval regular falsely method surely will take you to a root that is it will surely converge to a root whereas, in secant method that is not guaranteed to you because there is a danger that at some iteration that is at some n you may face a problem where f of x n is equal to f of x n minus 1 in which case the secant method fails. So, let us give the algorithm quickly the algorithm is given like this what you have to do you have to give x naught and x 1 and then compute x 2 that is take n equal to 1 that gives you x 2 you have to plug in x naught and x 1 in this expression get x 2. Once you get x 2 then give x 1 and x 2 to get x 3 again you have to plug in this into this formula and get x 3 and so on right. So, that is the algorithm again stopping criteria one has to carefully choose as I told you Cauchy criteria is something which we can prefer. As I told you the secant method is obtained by looking at the point of intersection of the secant line with the x coordinate that is why the name of the method is secant method and one situation where the secant method fails is that at some n if f of x n is equal to f of x n minus 1 then the secant method fails. Let us take an example let us take f of x equal to sin x plus x square minus 1 then we can use the secant method for that you have to give now two initial conditions remember you do not need to take x naught and x 1 in such a way that there is a root in between them right. You can just throw these numbers arbitrarily just to have a comparison I have taken the same numbers 0 and 1 as we did with the regular falsely method, but remember this is not required you can take any numbers as the initial guess then I have just computed up to 5 iterations and you can see that you obtained x 5 pretty close to the exact solution which is approximately given like this. So, in this example secant method is nicely converging to the exact root 0.6367 and so on. With this we will finish our discussion on secant methods. Thank you for your attention.