 in today's class we will start a new chapter and this is on numerical ordinary differential equations. In this chapter we will learn to develop numerical methods for some ordinary differential equations with initial and boundary conditions. In this lecture we will learn a very basic method called Euler method. Let us first see what is the model that we are interested in approximating. First let us see what is mean by an initial value problem. We are given a first order ordinary differential equation in the normal form that is y dash is equal to f of x comma y where f is a function of two variables x and y. x is the independent variable and it is taken in an interval i and y is the dependent variable it depends on the independent variable x that is y is a function of x and y dash denotes the differentiation of y with respect to x and this equation is posed on an interval i. For instance you can take this interval as a closed and bounded interval a comma b and we are also given an extra information that y at some point x naught in the interval i is given by y naught. So, it means the value of the unknown function y at one point is specified. Such a condition is called an initial condition if you are specified the unknown variable at two different points then it is called the boundary condition. Here we are given initial condition and therefore this problem that is the ordinary differential equation y dash equal to f of x comma y and the initial condition y of x naught equal to y naught posed on the interval i with x naught in i is what we generally call as the initial value problem and we often denote it by i v p. Here the function f is given to us and we are supposed to find the unknown variable y for all x in the interval i such that y satisfies this equation and also it satisfies this initial condition. We generally assume that f is a continuous function in a domain in r 2 that contains the point x naught comma y naught. If you would have gone through a basic course on ordinary differential equations you will know that under this condition we can say that this initial value problem has a solution in a small neighborhood of the point x naught y naught. This is what is the statement of a well known theorem called piano existence theorem. We assume this condition because we are going to develop some numerical methods to approximate a solution of the initial value problem in order to ensure that our initial value problem has a solution at least in a small neighborhood of x naught y naught. We have to assume this condition otherwise we will be devising and trying to capture something which does not exist that makes no sense right. Therefore, this assumption is very important. Well there is a nice characterization for a solution of this initial value problem in terms of a solution of a equivalent integral equation and this is especially very important and useful for us to generate many numerical methods for our problem. So, let us recall this result from our basic course on ODE here. The theorem says that y is a solution of the given initial value problem that is this problem posed on an interval i if and only if y is a continuous function on the interval i and it satisfies this integral equation. What is this integral equation? It is y of x equal to y naught plus integral x naught to x f of s this is the dummy variable in the integral and the integration is done with respect to that variable y of s this is unknown to us. Therefore, in general we cannot explicitly evaluate this integral unless the function f is independent of y right and this equation should hold for all x in i that is the integral equation. You can see that it is also an equation for which y of x is an unknown. You can see that a direct integration of this will give rise to this equation under suitable conditions on f and y right. So, that is what the lemma says it is not very difficult for us to prove you can use the fundamental theorem of calculus to prove this, but this is a very useful result for us to devise many numerical methods. Let us see how to devise numerical methods to approximate the values of the unknown function y. This is the aim of this chapter before getting into the construction of some numerical schemes. Let us try to recall some simple examples let f of x comma y equal to y then our initial value problem is given by y dash equal to y y of x naught equal to y naught. This is the initial condition and this is the equation given to us and this problem is posed on some interval. Since it is a very simple problem I have not specified or restricted our problem to any particular interval. You can immediately see that the exact solution of this initial value problem is y naught into e power x minus x naught. How will you check this? Well you can differentiate the function y of x and see that it satisfies this equation and also put x equal to x naught and see that the initial condition is also satisfied. Therefore, this is clearly a solution of our initial value problem. Well in this simple example we got the exact solution very nicely, but in general it may not be possible for us to get exact solution for any given initial value problem that is for any given right hand side function f of x comma y and for any given initial condition. Sometimes we may know that there exist a solution like for instance if f is continuous in a domain in R 2 that contains x naught y naught that is our data then Piano theorem says that we always can find a solution at least in a small neighborhood of x naught comma y naught right. Like that we also have Lipschitz theorem which says that if f is Lipschitz with respect to y in a domain containing x naught y naught then again you can say that there exist a unique solution for our initial value problem in a smaller neighborhood of x naught y naught. So, these results are qualitative you cannot construct the solution and show these results. Therefore, in general there are equations for which you know that there exists solution. In fact, we may know also that there exist a unique solution in a small neighborhood of your initial data, but you may not know how to obtain this solutions explicitly. Something like what we got in the previous example we had the solution explicitly right, but this may not be the case always for instance you consider this equation y dash is equal to x square plus y square. You give any initial condition to this equation and define a initial value problem. In fact, you can show that it has a unique solution by properly defining a initial condition and restricting yourself to a suitable domain in R 2. But you can see that none of the methods that you learnt in your basic ordinary differential equation course will help you to actually construct the solution explicitly for this particular equation. Now, if you ask the question then how will I compute or construct the solution for such equations? Well, one way to do it is to go for certain numerical methods in which case you can at least get an approximate solution for this initial value problem. This is the purpose of our chapter. Let us learn how to device numerical methods for a given initial value problem of the form y dash is equal to f of x comma y and the initial condition is y of x naught is equal to x naught. That is we know the initial condition and we want to device a numerical method for this ordinary differential equation. There are two ways that we can construct a numerical method for this differential equation. One is using the numerical differentiation formulas. In the last chapter we have learnt to develop numerical differentiation formulas. We call them as finite difference formulas for any order derivative of a function. Here y is a function of x and y dash is the derivative of y with respect to x. Therefore, we can use the ideas that were introduced in our last chapter to approximate the derivative y dash using some finite difference formulas. So that is one way to develop numerical methods for this equation. The next approach is go to the lemma that we stated in the first slide of this class. We had an equivalent equation for our initial value problem. That is given as this integral equation. The lemma says that any continuous solution of this integral equation is also a solution of this equation. Now look at this integral equation. We can also approximate this integral by some quadrature formula. Again recall we have learnt already to develop quadrature formula for a given integral. We can use one or the other quadrature rule to develop a numerical method for our initial value problem by first considering the given ODE in the form of this integral equation and then approximate this integral by a suitable quadrature formula. Of course, different finite difference methods in this form or different quadrature formulas in this form can lead to different methods for our initial value problem. So, let us see how to devise different numerical methods for our initial value problem. First let us understand a general framework for these methods. To devise a numerical method for the given initial value problem, first you have to discretize your interval. Remember this initial value problem is posed on an interval x belonging to i. That is our interest is to obtain the unknown function y on the interval i, such that both this equation is satisfied as well as this initial condition is satisfied. So, the first step of our method is to introduce a partition to the interval i. Let us consider this interval as a closed and bounded interval a b and first introduce a partition to this interval which we call as discretization of our space. Here the space is the interval for our problem and all this node points are called grids. In the context of interpolation, we call them as nodes and in the context of numerical methods for differential equations, generally people call these points as grids and our numerical methods will give approximate values of our function y only at these grid points. Remember your numerical method will not give exact solution, it only gives approximate values of your solution y and not for all x in the interval only at these grid points which you introduce at the beginning. How you are generating these grid points? Well, you can have non uniform grids, but for the sake of simplicity more precisely notational simplicity, we will consider this partition as equally spaced partition. It means what the length of each sub interval of this partition has an equal length denoted by h and it is given by b minus a by n if we have n plus 1 grid points in our partition. And this grid points are obviously given by this, now our aim is to find an approximate value of the solution of our initial value problem. Generally, we denote this approximate solution by y h of x j, the suffix h is to denote that we have generated these grid points values with h as the length of the partition. We also often use the notation y j to denote this approximate value, these are some notations that you have to keep in mind. Now, let us learn to devise Euler methods, we are interested in solving the ordinary differential equation y dash equal to f of x comma y, but our function f is too complicated just like we have shown in the example that we do not know how to obtain an exact solution. However, we know that there exist a solution at least locally around the initial condition that is specified. These are something that we have to make sure before coming to develop a numerical method or to work with some numerical method. Once these are given, then let us see how to devise the so called Euler method, note that we are also given the value of y at the point x naught through the initial condition in our initial value problem. Now, our aim is to find the value of y at the point x 1, which is given by x naught plus h, that is we know the solution at the point x naught that is given by y of x naught and we want to find the solution at the point x 1, that is our aim. For this, we will put a finite difference formula for the derivative of y in our equation. Let us take the forward difference formula. If you recall, we have introduced this formula in the last chapter when we were discussing the finite difference formulas for derivatives of a given function. In that, we have introduced forward difference formula and we have also learnt the mathematical error expression for this formula. Let us use that formula, it is given by y of x plus h minus y of x divided by h. So, we will try to replace this formula in the place of y dash in our equation and see what happens. So, instead of y dash is equal to f of x comma y, what we are doing is we are putting this approximate formula and we are evaluating an approximate value of y at the point x naught by taking x is equal to x naught here, that is what we are putting here and since we are taking x equal to x naught, in the equation also you have to put x naught comma y of x naught. Remember, this is a function that depends on x, although we write like this, it means f of x comma y of x, you have to keep that in mind that is what we meant by writing like this and also this means y dash of x, that is nothing but d y by d x, all this should be kept in mind always and you see from here we can write y of x 1 as y of x naught plus h into f of x naught comma y of x naught. In all this one thing should be carefully observed the equation is given like this, we have put an approximation to y dash therefore the left hand side is now not equal to the right hand side, it is only approximately equal to the right hand side, this is a notational discipline that you have to keep in mind, do not ever put this is equal to this that is wrong, you have to put approximately equal to here also we are approximating this quantity by this formula therefore, you have to put approximately equal to, if you put exactly equal to then that is wrong and that approximates approximately equal to is also put here because the left hand side is the notation for exact value of y at the point x 1 whereas, the right hand side is obtained by putting the finite difference formula right therefore, they are approximately equal not exactly equal. So, this is what we got and with this formula you can compute the value of the value of y approximately at the point x 1 provided you are given the value of the function y at the point x naught right. Similarly, once you get the value of y at the point x 1 well approximately then you can go to get the value of y at the point x 2 again approximately and so on. So, you can simply repeat this idea by replacing x naught by x 1 and x 1 by x 2 in order to approximate y of x 2 and similarly you can approximate y of x 3 and so on that is what I am trying to say. Let us put this idea in general we are known or given the value y of x j for some j equal to 0 1 2 up to capital N and our aim is to find an approximate value for y of x j plus 1 for that what we do is we replace the derivative of y in our equation by the corresponding forward difference formula evaluated at the point x j and that gives us this approximate relation and from there you can get y of x j plus 1 is approximately equal to y of x j right plus h times f of x j comma y of x j remember you have to put approximately equal to here. If you do not want to always remember to put approximately equal to what you can do is you can fix a notation for this approximate value that is coming out of this relation by y suffix j plus 1 and also you replace this by y j and then you use this notation to indicate the approximate value computed through this formula then you can put equal to sign here because this value is precisely obtained by evaluating this expression with their appropriate values right. Therefore, you can put equal to sign here with this notation but here you should not put equal to sign it is only approximately equal to this is just a notational discipline that you have to keep in mind always ok. This formula is called the forward Euler method what this formula gives us is you first know the value of the solution at the point x naught through the initial condition. Now you want to find the value of your solution at x 1 x 2 and so on up to x n in general we take x naught as a and x n as b this is again an unnecessary restriction you can have x naught x 1 up to x n anywhere even in the interior of your interval but generally we will take either x naught as a or x naught as b for forward Euler method we will take x naught as a and then we go forward in the space to get the value of our function at other points in the inter which are lying on the right side of x naught then we have to use the forward Euler method. Similarly, you can also device backward Euler method by replacing y dash in the given ordinary differential equation by its backward difference formula and that leads to this expression for computing an approximate value to our function at a point x j minus 1 given y j what is the geometrical interpretation for Euler method let us see suppose this is the solution that we want to obtain that is y of x assume that we know the exact value of the unknown function y at the point x n and it is given like this then what the Euler method does is it goes along the tangent line at the point x n comma y of x n and takes the value of this tangent line at the point x n and it gives that value as the approximate value of your exact solution y of x n plus 1 and this is the geometrical interpretation of the forward Euler method similarly you can give the geometrical interpretation for the backward Euler method also if you are given the value of the function at x n and if you want to find the value of your unknown at x n minus 1 right then you have to go for the backward Euler method let us summarize what we have done so far we want to find an approximation to the given initial value problem for that first we have discretized our space interval a comma b by introducing a partition to our interval right so these are called grid points if you are given the value at some point x n and you want to find the value of your function at points that are lying on the right side of x n then you have to go for the forward Euler method and the formula is given like this on the other hand if you are given the initial condition and x n and you are interested in finding an approximate value of the points that are lying on the left side of x n then you have to go for the backward Euler method so this is what you have to keep in mind where the initial condition is given and where the approximation is needed depending on this we have to decide whether we have to go for forward Euler method or backward Euler method let us take the example that we have seen at the beginning of this lecture our initial value problem is y dash equal to y and the initial condition is specified at x naught which is equal to 0 and y naught is taken as 1 with that we know what is the exact solution for this initial value problem just to see how our Euler method works let us also compute the solution of this initial value problem using Euler method here we are interested in finding an approximate solution for this initial value problem for some point x greater than 0 it means what our domain lies on the right side of the point where we are given the initial condition right therefore we have to use the forward Euler method and forward Euler method in this particular example is given like this you can easily check that and the exact solution is given by y of x equal to e power x let us take h is equal to 0.01 and compute the approximate values of the solution at different node points y 1 is an approximation to y of 0.01 and it is given by 1.01 similarly you can find an approximate value of y of 0.001. 0.02 denoted by y 2 and it is given by this number similarly you can find y of 0.03 approximately and so on let us now see how the error looks like in this table we are giving exact value approximate value then we are also showing the error that is exact value minus approximate value and also the relative error for the approximate solution obtained using forward Euler method with h is equal to 0.01 you can see from here the initial condition does not have any error because we have taken this value from the initial condition itself right generally in such cases we do not commit any mistake unless there is some rounding error involved in the data in this particular case the initial condition is an integer therefore there is no rounding error involved in it and that is why we see that the error is 0 at the first level. And as you go on computing the solution at later points of x you can see that the relative error keep on increasing right that is as you go away from the initial condition at every grid point when you calculate the solution you see that the error is increasing that is an interesting observation when we are doing the error analysis we will clearly see why we are accumulating the error when we go from one grid point to the next grid point. So, we will keep this behavior of error in mind and we will try to answer this question let us see how the errors look like when we take h is equal to 0.005 you can see for instance in the previous case we have obtained the solution up to x equal to 0.05 and at this point the relative error was given like this now we have decreased h and thereby you can see at the point x equal to 0.05 the relative error is given like this which is much lesser than what we got as the relative error with h equal to 0.01. This shows that as you go on decreasing h you will get better and better approximation for your solution, but if you should keep in mind that we have seen a very dangerous behavior of the finite difference formula which are also true for quadrature formula right. If you go on decreasing h do not think that your error will also decrease and tends to 0. There is a optimal h beyond which if you tend to decrease h your error may tend to increase because of the arithmetic error. The same behavior will also be seen in this kind of method because we are basically using the finite difference approximations right. However, at least from h equal to 0.01 to h equal to 0.005 you see that the error is pretty good. However, you can see that as you go on with your x i your error gets accumulated here you can see from one step to the next step to the next step the error is accumulating. We will study this behavior when we are doing the error analysis. Let us see another example here we will take y dash equal to cos x and we are interested in solving this initial value problem y dash equal to cos x and y of 0 equal to minus 1 in the interval 0 comma 1. The Euler forward formula gives us the expression like this and we know that the exact solution is like this. Let us try to visualize the solution of this initial value problem along with the computed solution from the forward Euler method. The exact solution of this initial value problem is shown in solid blue line and the Euler solution is shown in red dotted lines which are shown here for the initial condition. This is the initial condition and then this is the solution obtained as an approximation to y of x 1. Similarly, this is y of x 2 which we call as y 2 this is y 3 and so on. You can see that the solution is nicely coinciding with the exact solution. This is because from the geometrical interpretation of Euler method we have seen that the Euler method takes the tangent line and tries to approximate the solution value along the tangent line. Therefore, on those regions where the solution is almost linear something which is happening here you will see that the Euler method gives better approximation. However, if your solution has too much of curvature you will see that the Euler method gives poor approximation. Let us go on you can see that as you go on computing the solution for different x i lying on the right side of x naught you see when you come to this region the Euler method is giving rather a poor approximation means the exact solution at least at this point is this but your Euler method is giving this as the computed solution. So, I am just going on with my computation with x 1 x 2 x 3 and so on and you can see that the values obtained from the forward Euler method are shown in the red dots and you can see again when you come to this region your approximation is rather better because again in this region you have a almost linear behavior for the exact solution. So, let us see how this Euler method approximates the solution for different values of h. Let us start with h equal to 0.2 the solid red line shows the Euler solution and blue line is the exact solution. Now, I am going to decrease the value of h and see how the Euler solution looks like for h equal to 0.1 the Euler solution is little closer to the exact solution than what we got when we took h equal to 0.2 right then I will go on decreasing h. Now, I take h equal to 0.05 you can see that the approximation is significantly improved from h equal to 0.1 to h equal to 0.05 further let us reduce h you can see that Euler method is giving better and better result as you go on decreasing h. I went up to h equal to 0.0063 here at least visually you can see that the Euler solution is nicely coinciding with the exact solution. So, this is what we say that Euler method is point wise converging to the exact result that is you take any particular point your Euler solution is this whereas, the exact solution is this and as you go on decreasing your h they both coincides very well. Although I show you in this plot a continuous solid line for Euler solution it is actually computed only at some discrete grid points rest all are linearly joined to show a continuous solid line. I hope you understood how to develop Euler method and how the Euler method works both geometrically and numerically. In the next class we will learn how to analyze the error involved in the Euler method both mathematical error as well as the truncation error. Thank you for your attention.