 We are learning numerical methods for first order initial value problem. In this, we have learnt Euler method and Runge-Kutta method. In this class, we will introduce two methods. One is midpoint method and another one is trapezoidal method. We will use a different idea to derive these two methods. We will first write the initial value problem in the form of an equivalent integral equation and then use quadrature formulas to approximate the integrals appearing in this equation to get these two methods. One is a two-step method and another one is an implicit method. Let us go to derive these two methods. Recall that the initial value problem that we are interested in is given by y dash is equal to f of x comma y and this equation is posed on a closed and bounded interval a comma b and we are also provided with an initial condition y of x naught equal to y naught where x naught is a point in the interval a comma b. Often we take x naught equal to a just for the sake of simplicity. Recall we have derived the forward Euler method in one of our previous lectures where we have approximated the derivative y dash in our equation using forward difference formula and thereby we got the formula for the forward Euler method as y j plus 1 equal to y j plus h into f of x j comma y j. Here you can see that in order to get y j plus 1 we just need to know the value of y at the previous node that is at x j. So, in that way this method is a one-step method and also you can see that y j plus 1 is obtained fully from x j and y j which are known to us. In that way this formula is an explicit formula for y j plus 1 and that is why we say that the forward Euler method is an explicit method. Well we have obtained this formula by approximating y dash by the forward difference formula. Now we can also get the same formula using another approach here what we will do is we will write the given equation in the equivalent integral form. How are we getting this? Well we have y dash is equal to f of x comma y right. Now you integrate it from x j to x j plus 1 the same has to be done on the right hand side also right x j to x j plus 1 d s. So, let us write it as s d x j plus 1 d s. And this is d s right. Now here you can see that the integral becomes y of x j plus 1 minus y of x j which I will take on the other side y of x j plus this integral is kept as it is x j to x j plus 1 f of s comma y of s d s. So, that is what we are writing here. So, this equation can be equivalently written in this form we are just using the fundamental theorem of calculus for that you have to of course assume that f is a continuous function with all this nice assumptions you can see that the given ODE is equivalent to this integral form of the equation. Remember this is not a formula, but it is a equation because you have y on the left hand side which is unknown and that is evaluated in terms of again y which is sitting in the integrand here. Therefore, it is an integral equation and it has to be solved in order to get y. Now we know that there are some integrands f for which we do not know how to perform this integral explicitly in which case you can approximate this integral by a quadrature formula. So, that is the idea. Now what we are claiming is that there is a quadrature formula for which we will get the forward Euler method. The question is what is that quadrature formula when I replace this integral by that quadrature formula leads to forward Euler method. Let us see if you recall we had studied a rule called rectangular rule. So, what it says integral a to b f of x dx is nothing but b minus a into f of a. So, that is what we are going to use here integral x j to x j plus 1 f of s comma y of s ds is equal to x j plus 1 minus x j into f of x j that is the value of the function f evaluated at the lower limit of the integral ok. And we know that this is nothing but h therefore, this can be written as h into f of x j comma y j. Now you replace this integral by the rectangular rule and thereby you get y j plus 1 remember since I put an approximate expression for this I will not use the notation y of x j because this is used to indicate the exact solution. So, I will use this notation to indicate the corresponding approximation to the exact solution and that is given by y j which is an approximation to y of x j plus this integral is now replaced by the rectangular rule and that is precisely the forward Euler method right. So, the forward Euler method which we derived by replacing y dash by the forward difference formula can also be obtained by replacing the rectangular rule in the equivalent integral equation. Now from here we get lot of ideas because why only rectangular rule we can also replace this integral by midpoint rule, trapezoidal rule, even Simpson's rule and Gaussian quadrature rule right. So, we have many formulas from which we have scope to get many methods this is what is the interest for us in this lecture as the first step let us consider the integral form of the ODE here, but there is a slight difference in the way I have taken this limits I have taken the limits as x j minus 1 to x j plus 1 remember how you will write this integral equation is up to you you just have to integrate y dash of s d s integral f of s comma y of s d s and then take any limit. So, it is not necessary that you have to take x j to x j plus 1 you can also take x j minus 1 to x j plus 1 like that you can take the integral over any interval, but only thing is you have to take the same integral on the right hand side also right. So, that is what I am doing here why am I doing here with a different limit because I want to now apply the midpoint rule if you recall midpoint rule is given by integral a to b f of x d x is integral a to b f of x d x is actually b minus a into f evaluated at the midpoint of the interval that is b plus a by 2 right. Now, when I want to apply this midpoint rule to this integrand I have to evaluate this integral at the midpoint of the interval on which you are taking this integral and that midpoint should coincide with one of your grid points that you have generated in your problem that is why I have taken the limit as x j minus 1 to x j plus 1. So, that x j is the midpoint of this interval remember we always work with equally spaced nodes again this is only for the convenience, but here we are crucially using it and that will make the evaluation of this quadrature rule exactly at the node point x j for that reason we have chosen this you have to choose similarly for Simpson's rule also because Simpson's rule also evaluates the value of the function at the midpoint of the interval right. So, in such cases you have to make sure that all the points where you are evaluating the function should be the grid points of your problem. Once you have this now it is very easy for you to apply the midpoint quadrature rule for the integral and that is given by this which is nothing, but 2 h into f of x j comma y j right. So, when you apply this quadrature rule into this equation you get the formula y j plus 1 equal to y j minus 1 plus 2 h into f of x j comma y j that is why you have 2 h here because you have applied the quadrature formula in the interval x j minus 1 to x j plus 1 ok. You have chosen a wider interval in order to fit this function evaluation exactly at a grid point ok. So, this is the idea of midpoint rule well we have the midpoint method for our initial value problem and we have the following important observations about this midpoint method what are they the first observation is that to compute the value of y j plus 1 we need to know the value of y j and not only that it also depends on the value at x j minus 1 right. Therefore, y j plus 1 depends on the value of y at 2 grid points one is at x j and another is x j minus 1 that is the first observation. Now, when you go to find y 1 how will I get it well put j equal to 0 to get y 1 that will make the first term here as y minus 1 what is that it is nothing, but y evaluated at x naught minus h. But if you recall we have posed the problem only in the interval x naught to b right we do not care about x naught minus h it is outside our domain. Therefore, we do not know whether the solution exists at this point or not even if it exists we have no interest to calculate the value of y at this point. So, we cannot go to use the value at this point that makes the method to be not applicable for j equal to 0 in that case therefore, you have to compute y 1 using some one step method something like forward Euler method. Once you have y 1 from some other method then we can use y naught and y 1 to obtain y 2 using the midpoint rule and similarly you can use y 1 and y 2 to get y 3 from the midpoint method and so on. So, you can apply the midpoint rule only for obtaining y j for j equal to 2 3 and so on whereas, y 1 has to be obtained from some one step method like forward Euler method. Such a method is called a two step method because to find y j plus 1 you need to know the value of the solution at two previous nodes right here it is y j and y j minus 1. Let us take an example where we have the initial value problem as y dash is equal to y and y of 0 is equal to 1. Our aim is to obtain an approximate value of y of 0.04 with the step size h is equal to 0.01. As we have already observed we have to use some one step method to obtain y 1. Here we use the Euler's forward formula and get the approximate value at the point y of 0 comma 0 1 as 1.01 and is denoted by y 1. So, we got the value of y 1 from forward Euler method. Now to get y 2 we can go for the midpoint method y 2 is from the midpoint method given by y naught plus 2 into y 1 h y 1 and we know all the values. Therefore, we can plug in all these values and get the approximate value of y of 0 comma 0 2 and it is given by 1.0202 here. Similarly, you can also get y 3 y 3 is the approximation to y of 0 comma 0 3 and it involves the values of y 1 which is we have already computed from the Euler method and it also involves the value of y 2 which we have computed from the midpoint tool from here. So, you can plug in those values and get the value of y 3 which is approximately 1.0304. Similarly, you can get y 4 which is the approximation of what we want. So, we want y of 0 comma 0 4 and that is now given by approximately 1.04081. Now let us see what is the exact value of the solution y of 0 comma 0 4. You can clearly see that the exact solution is given by y of x equal to e power x from there you can compute the exact value of the solution and that may be taken approximately as 1.040811. So, that is pretty close to what we have obtained also. You can see that we have obtained the approximate solution up to 6 digit rounding with respect to this exact value the error is given by this which is pretty small. If you recall we have also obtained an approximate solution for this initial value problem using forward Euler method and for the same value of h that is h equal to 0.01 we got the error from the forward Euler method as this value. From here you can see that at least in this example the midpoint method performs better than the forward Euler method. So far we have only derived explicit methods where the unknown y j plus 1 is obtained as a solution of y j and y j minus 1 which are already computed when we go to compute y j plus 1. In that way the methods that we have derived so far are explicit methods. There are also other cases where the unknown y j plus 1 is obtained as an implicit relation involving known and unknown quantities such methods are called implicit methods. Let us illustrate such a method by putting the trapezoidal rule to the integral equation. Just recall that the trapezoidal rule for this integral is given by b minus a which is x j plus 1 minus x j by 2 into f of b that is f of x j plus 1 comma y j plus 1 plus f of a which is f of x j comma y j. So, we just have to replace this integral by the trapezoidal rule and we get y j plus 1 equal to y j plus h j plus 1 minus h j is precisely h for us divided by 2 into f of a plus f of b. This relation is called the trapezoidal method here you can see that we obtained a relation for y j plus 1 and it is implicitly represented because to get y j plus 1 we again need to know y j plus 1 on the right hand side also. If you recall both in the midpoint rule as well as in the forward Euler method we obtained y j plus 1 purely in terms of the known quantities whereas, in the present case we only have an implicit relation and for this reason this method is called an implicit method. Note that the trapezoidal method can be explicit if the function f is linear in y. Let us see this by an example consider the initial value problem y dash equal to x y and the initial condition is given by y of 0 equal to 1. Here you can see f of x comma y is equal to x y and you can see that f is linear in y. Let us take h equal to 0.2 that is not very important for us now we will apply the trapezoidal method to this initial value problem and see that we get an explicit relation just because f is a linear function in y. Let us see how it goes recall the trapezoidal rule for this initial value problem is y j plus 1 is equal to y j plus h by 2 into x j y j plus x j plus 1 y j plus 1. Of course, we have y j plus 1 appearing on the right hand side, but what you can do is you can take it to the left hand side and then you can easily solve for y j plus 1. So, that is what we do here for instance y 1 is given like this and when you plug in all the known quantities here we have this expression where y 1 is again not known to us, but that does not matter you can take this y 1 to the other side and get an explicit relation for y 1 like this and that immediately gives you the value of y 1 as well. So, therefore, as long as the right hand side function f depends linearly on y you can still use the trapezoidal rule just like the explicit method. In fact, you can also get y 2 very easily again y 2 will be given in terms of y 2 again, but that is again appearing linearly therefore, you can solve it to get y 2 and that value is given by 1.0842. Now, the question is how to solve this in general trapezoidal rule gives a non-linear equation for each y j plus 1. Let us see this by another example. Now, let us take the initial value problem y dash equal to e power minus y with the initial guess as y of 0 equal to 1. In this case y 1 is given by this expression where the right hand side also involves y 1, but now it depends on y 1 in non-linear way. Now, it involves y 1 in terms of the exponential function. Now, it is not very easy for us to solve this equation to get y 1. Now, the question is how to solve this non-linear equation at every grid point? There are two ways that we can handle this problem. One is to use some non-linear iterative method. Let us first consider the non-linear equation. The non-linear equation is precisely y 1 which is coming from your left hand side minus 0.1 into e power minus y 1 minus you collect all the constants in one place and that is equal to 0. Therefore, you have this non-linear equation g of y 1 equal to 0. You have to solve this equation to get y 1. If you recall, we have learnt some non-linear iteration methods in one of our previous chapters. So, you may use one of those methods to obtain a solution to this non-linear equation which will be the approximation to the solution of your initial value problem at x equal to 0.2. This is one way to handle this non-linear equation. Let us put this idea in a general way. How to proceed when we are working with implicit methods? Because implicit methods in general gives us a non-linear relation involving the unknown y j plus 1. The idea that we have proposed in the last example is to go for one of the non-linear iterative methods. Recall that the trapezoidal method is given like this. This equation can be seen as a fixed point problem where the iteration function g of y is given as y j plus h by 2 into f of x j comma y j. These are known quantities plus f of x j plus 1. This is also known comma y. So, this is unknown to f. Therefore, you can define the iteration function like this whose fixed point is precisely the point y equal to y j plus 1. So, that is what we are seeing from the trapezoidal method. So, that is what I have written here. We can view the trapezoidal method as a fixed point iteration method Now, you can choose any initial guess which we will denote by y j plus 1, 0 and then define the fixed point iteration method like this where you will plug in y 0 and get y j plus 1, 1 and again plug in y j plus 1, 1 on the right hand side get y j plus 1, 2 and so on. So, in that way you generate a sequence of numbers which is expected to converge to the fixed point of the function g and that is precisely the approximation of our solution at x j plus 1. There is another approach which is called the predictor character approach where you take the initial guess from the Euler method. Remember in the first approach you get the initial guess arbitrarily whereas, in this we are taking the initial guess from the Euler forward formula which is called the predictor step and then use this value here to compute y j plus 1 using the trapezoidal method and that step is called the character step. In that way you have one predictor step get the initial guess from the Euler forward formula plug in on the right hand side and thereby the expression now becomes explicit you can find y j plus 1 from there and that is called the character step and such a method is called the predictor character method and since we are using Euler forward formula here and then computing the solution from the trapezoidal method this method is also sometime called as Euler trapezoidal method. Let us take our previous example y dash equal to e power minus y on the interval 0 to 0.4 with h is equal to 0.2 we are given the initial condition as y of 0 equal to 1. We will now compute the solution using the Euler trapezoidal method that is the predictor character approach which includes one predictor step which is coming from the Euler forward formula and that is given by this value. Now you plug in that value into the trapezoidal method and perform the character step and get the value as 1.070966. Similarly we can do the step 2 for step 2 again you will take this value y 1 remember do not take this value for the predictor step of y 2 ok. So, you have to take the character value from y 1 and plug in that to the predictor step of y 2 and you get the corresponding value once you get that value you just plug into the character step and get y 2 from here and that gives us the value for y 2. So, this is not the value for y 2 it is just a prediction and that is further corrected by the trapezoidal method. So, this is a nice illustration for the predictor and character method in this lecture we have learnt two important methods one is midpoint method which is a example for a two step method and another method we learnt is the trapezoidal method which is an example of an implicit method we will continue our discussion on multi step methods with explicit and implicit forms in the next lecture. Thank you for your attention.