Watch these four (4) videos in order. The total video time is 25 min. Be sure to test your knowledge with the knowledge checks after each video.
Description: This video discusses the generalized Butcher Tableau and how to use them to generate different ODE solvers, such as the classic RK4 method.
Hello, this is a video ODE|VL|06 and it is the theory of Butcher tableaus and the RK4 method for solving ordinary differential equations.
First, let's talk about some general theory. The method shown previously, for example, Euler's method and the second-order methods are all part of a family of numerical techniques called the Runge-Kutta methods. All these techniques attempt to achieve a higher-order accuracy of the Taylor series approximations without actually calculating any higher-order derivatives. This is achieved by calculating the slope at numerous points. These methods can be organized into a Butcher Tableau, a generalized Butcher Tableau is shown here. The first column has the a parameters. The top left of the tableau has b parameters, and the last row has the c parameters. Let's see what these means. Well, the first step for any Runge-Kutta method is to calculate the case for k = 1 to n and n being the number of k values you want for a certain order. For example, a second order would be 1 to 2. We have kk = f(xi + aih, yi +h time the summation from j = 1 to k-1 bkjkj. And this may sound very confusing, but we can look at this in more detail when we do some examples. What we will have here is the a values represent how you're going to actually adjust your x value. So you can see here, xi + aih is what you have. The b values are going to be representing how you're going to change your y-value. So how the weighting factor of your k will be for the y-values. And so that's where you have your yi + h times summation series. Once you get your k values, what you're going to do is you're going to weight them to a certain amount. You can do that with this ϕ function here, ϕ is a function of xi, yi and h, and that will equal to the summation from j = 1 to n of cjkj. So these are the weighting factors that we have. Once we have that weighting factor, we can update our value of yi+1, which will equal to yi + ϕh. This is generalized form that we have.
Let's look at it under more specific examples we've done already. Here's an example of the Butcher Tableau for Euler’s method. It's quite small because Euler’s method only has one estimate of the slope, which is k1. Let's see how we take Butcher’s Tableau and convert it into our equations. We have k1 is equal to f(xi +0 ,so you can see that where the zeros coming from times h, yi). Then with that, we can now move over to yi+1, which is equal to yi + 1hk1. Next one we can look at is Heun’s method. So Heun’s method as you remember, we'll take two estimates of the slope at k1 and k2. In this case here k1 is equal to f(xi + 0h,yi). And you'll notice that for k2, we're going to have xi+ 1h. And you can see where we're getting that from our equation. Next that we have a value of k1 in this, we could actually use part of our b table. You'll notice that the next one in the k2 value comes from the inside of a bunch of Tableau. And then we can finally use those two estimates pf the k1, k2s to give us the yi+1, which is equal to yi h times our two halves here. So k1 is weighted by half and k2 is weighed by half. Let's try the Butcher Tableau for the Midpoint method. So we have k1 is going to equal to f(xi + 0h again, yi). And then in our k2 our xi gets adjusted by a half, which is from the Butcher Tableau. As well as our yi gets adjusted by half of h*k1. Once they've done that, we can find our next estimate of yi+1, which is equal to yi + h(0k1 + 1k2). So again, you can see that it's weighted all to the second estimate of the slope k2. Let's do the final one for Ralston’s method. So here's the Butcher Tableau for Ralston’s method. You'll see that again, we can use the values in the first column to adjust our x values. For k1, we have xi + 0h as usual, and k2 it is equal to xi +3h/4 as well inside of it. Normally, by the way, for k1, we don't say xi + 0h, will just say xi, but for the purpose of the illustration, I'm showing it here. For k2 again, we're going to re-adjust our yi. Have yi + 3hk1/4. Now that we have our k1 and k2 we can find our yi+1, which should be equal to yi + h and then now we have a weighted factors for k1 and k2. We have 1/3 of k1 and 2/3 of k2.
Let's look at a third order method. For example, this Kutta method here that will have three k's. We can generate the case based off with this Butcher Tableau. We have a k1 and with k1, our xi will be adjusted by 0h for k1. For k2 our xiwill be adjusted by 1/2 of h, and k3 will be adjusted by xi + 1h. Now that we've done that, we can go through and we can look at how our y's are going be adjusted since there's no k-value yet when we calculate k1, that can never be adjusted, but k2 can be adjusted. In this case, it will be adjusted by half. So we have yi + (1/2)hk1.k3 in this case here, we can use both weights to determine what we want. In this case, for k3 will be adjusted by -hk1 + 2hk2. Once we have our 3 k-values, we can calculate our next estimate of yi+1, which is equal to yi + h((1/6)k1 + (2/3)k2 + (1/6)k3). Let's look at one other Butcher Tableau. In this case here we'll look at the Runge-Kutta 4 method or RK4 method, which is a fourth order method, and is quite popular. And so in this case here we'll have to calculate 4 k’s. If we look at the Butcher Tableau, we can generate these equations first by looking at the x-values and how they'll change for k1, xiwill be changed by 0h. For k2, it'll be half of h. For k3, it will also be half of h. So we're calculating two different slopes in the midpoint area. For k4, it will be 1h. Next we'll look at k2 and how yi changes. In this case here, we'll change it by half of hk1. For k3, you're going to notice that we don't account for k1, so at 0hk1 plus half of hk2. Then for k4, we don't account for k1 or k2, which is yi + 0hk1 plus 0hk2 and then we have a full plus 1hk3 to find k4. Once we have that, we can find our yi+1, which is equal to yi +h((1/6)k1 + ((1/3)k2 + ((1/3)k3 + ((1/6)k4).
Let's look at the graphical representation of RK4. First we calculate our k1 value, which is the slope at xi. We go halfway to a point to find another slope at k2. Then we use that slope to go halfway again. So you notice that the slope of the black line with k2 and the bottom turquoise slope is equivalent. That will give us a slope of k3. Then we'll use that slope again. In this case, it's practically the same to find a value of k4. And then once we ever evaluate k4, we will be able to take a weighted average of that and find our next estimate of yi+1. Let's look at the function we've done before, that is f(x,y) = (10ex – 3y)/(1 + 3x). The orange figure here that we have is the true answer. And if we did Euler's method for a certain step size, we would get something that's not too accurate. If we did the same method using the RK4, you can see it's actually quite accurate to all the points that we have, which is fantastic. You can say, well, on RK4 it calculates 4 different slopes. So there's a lot more calculations. That's true, however, if we did it the same number of calculations for Euler's method. You'll notice that it's still not as accurate as the RK4 method, meaning that it is superior.
This concludes the video. This project could not have been completed without the support of eCampusOntario and the University of Ottawa.
Description: This video implements the theory of the RK4 method in a practice problem in a step-by-step approach.
Hello, this is video ODE|VL|07 and it is a step-by-step example of using RK4 to solve ordinary differential equations.
First, let us look at the problem. Solve the following problem using the RK4 method with the following conditions. We have the initial conditions of x0 = 0, y0 = 1, h, the step size, = 0.5, and our final value we're looking for xf = 1.5. The function is dy/dx = xcox(x)/(1-ey). We have our function f(x,y) = xcox(x)/(1-ey) and we'll have our iteration table at the bottom left-hand corner here. In this case we will have seven columns. The columns are i for iteration, i, y, k1, k2, k3, and k4 as we have 4 estimates of the slope. In this case, these equations are k1 = f(xi,yi), k2 = f(xi + h/2, yi + hk1/2), k3= f(xi + h/2, yi + hk2/2), and k4 = f(xi + h, yi + hk3). With these four k values, we can find our next value of y as yi+1, which is equal to yi + h((1/6)k1 + (1/3)k2 + (1/3)k3 + (1/6)k4) We can find an x value of xi+1 = xi + h. Let's take our initial values of x = 0 and y = 1. To calculate our k1 value, which in this case here will be equal to 0 again. Then we can use that to find our k2 value, k3, and then k4. Then we can take our weighted average of all these values to find our next value at x = 0.5, which will give us a y = 0.9276. We can repeat the process again, finding our k1, k2, k3, k4 to give us another value of x = 1, and our y-value is equal to 0.7218. We can calculate our k1, k2, k3, and k4 one last time. And finally, we could find our value that we're looking for at x = 1.5. And that will give us a value of y = 0.5041. And if we were to plot this, you'll notice that the RK4 method does an outstanding job for this function. To estimate the answers at all points of 0.5, 1 and 1.5.
This concludes the video. This project could not have been completed without the support of eCampusOntario and the University of Ottawa.
Description: This video discusses systems of ODEs and how they can be solved simultaneously using any of the methods discussed in this module.
Hello, this is video ODE|VL|08 and it is the theory of solving systems of ordinary differential equations.
Let's talk about the general theory of solving systems of ODEs. Many engineering systems can be defined by multiple coupled, ordinary differential equations. Coupled means that they are connected to each other and must be solved simultaneously. An example would be in the reactor the flow rates in the reactor are related to the pressure and temperature in the reactor at the same point. Its need to be solved together. Here's a simplified example where we have two coupled ordinary differential equations. We have dy/dx = -2y + 4e-x dx and dz/dx = -yz3/3. In this case here our independent variable is the same, which is x. And we have two dependent variables, y and z. And since y appears in the second ODE, we cannot solve them separately. We need to solve them together. Here's the general notation for our systems of ODEs. We have dependent variables y1, y2, yn, that is dependent on the independent variable x. And what we'll do is we'll take our ODEs dy1/dx and equate it to the function f1(z,y1,y2,…,yn). And we could do that for all the ODEs we have. So, we have dy2/dx is equal to f1(z,y1,y2,…,yn). And so what I want to show you here is the equations, depending on what we have, if it's based off of y1, that will be our f1 function. These are all slightly different, just based off the subscripts. What does not change are the inputs into each one of those functions. Now some of the functions might have a y1 and y2, and no yn, but it's just a general rotation that we can use.
We can actually use any of the Runge-Kutta methods that we've seen already to solve systems of ODEs. Take for example Euler’s method here. We have yj,i+1, j here represents the equation number, is equal to yj,I +h fj(z,y1,y2,…,yn). And so what you'll see here is that we're going need initial values for each of the unknowns that we're looking for. So we'll have an x0 will need an initial condition for y1,0, y2,0, yn,0. The thing that does not change is the h. So every step that we take for each equation needs to be the same. Let’s, look at the system of ODEs that only have two ODEs. We have this orange line represents an OD as well as this green line. If we were to use Euler’s method here to solve this, we can go back and forth and find some values for it. What you're going to notice is in this case here one equation lines up quite well because it's quite linear, whereas the other one does not. So the step size for the orange one, is not accurate enough. And so we'd actually have to reduce the step size, but we have to reduce it for both of them at the same time. So you're limited to your most non-linear equation that you are dealing with here. So we're not limited just to Euler's methods of solving systems of ODEs. We can use all the methods. Here's the RK4 method that you can use to solve the system of ODEs. There's one thing that's important to note. When we solve these, we're going to solve it in a certain order. That is, we solve for all the k1 values first, and then continue to all the k2 values, k3 values, and k4 values, we cannot solve just one equation, k1, k2, k3, k4, and then the other one, because it's in the same spot. In terms of notation, what we have here is k1,1. The first 1 represents the k value we're looking for. So the first k. And the second 1 represents the function. So k1,1 is for f1, k1,2, is for f2. Once we find those initial values we can go and move on to k2. k2,1 is for function f1. What you're going notice is we're just going to use the same weighting schemes that we had before for RK4. So we're doing half of h here, and we're going to do half of h for each of the parameters. So we have a y1,0, so the initial value of equation 1 plus 1/2 of hk1,1. If we had a yn,0 then it would be 1/2 of hkn,0. And so you have to be careful that we're going to always multiply these values out. Once we get k2, we can do k3 the same way. What you'll notice is again, our function should line up and we're going to do now 1/2 of hk2,1 for equation 1 and 1/2 of h k2,n for equation n,so something you need to keep in mind. Finally, we can do k4 in this case here we'll do k4,1 and k4,2 and get all our values. And here we're just multiplying it by h. There's no half here, as per the RK4 Butcher Tableau. Once we have all those values, we can update our y's. So we have y1,i+1 = y1,i +(h/6)*(k1,1 +2k2,1 +2k3,1 +k4,1). So you'll notice here is we're adding all the k-values that are related to equation 1. We can do the same thing for y2, and we could add them all up together as well. Finally, for all the ones that we have up to yn, so make sure when we add the k’s adding them correctly.
Let's look at a simple example. We can take the two equations shown before. That is dy/dx = -2y + 4e-x dx and dz/dx = -yz3/3. So these can represent their functions f1 and f2. Here we'll say that y1 = y and y2 = z. Just to keep our notation, we will apply Heun’s method to this. So the first thing that we have is k1,1 =f1(x0,y1,0,y2,0) and then we can calculate our k1,2 value. So this is our f2 function. And you'll notice that it has the same parameter list here so x0,y1,0,y2,0. Once we have our both k1’s, we can use them to calculate our k2’s. So we will calculate our k2,1. In this case here that you'll notice that we're adding to y1,0 is 1hk1,1 and we're adding to y2,0 is 1hk1,2. We can do the same thing again for k2,2, but with the f2 function and the same parameter list. Then with that we can calculate our y1,i+1 with a weighted value of (1/2)k1,1 and (1/2)K2,1. Then we can do the same thing for our y2,i+1 and has the same weighting scheme as before. This would be able to solve everything.
This concludes the video. This project could not have been completed without the support of eCampusOntario and the University of Ottawa.
Description: This video implements the theory of the solving system of ODEs in a practice problem in a step-by-step approach.
Hello. This is video ODE|VL|09 and it is a step-by-step example for solving systems of ordinary differential equations.
Let's first look at the problem. Solve the following problem with Ralston’s method under the following conditions, we have the initial conditions of x0 = 0, y0 = 1, z0 = 1.5. We'll take a step size of h = 0.5 and it will end when x gets to 2. That is xf = 2. The coupled differential equations are dy/dx = -2y + 4e-x and dz/dx = -yz3/3. We'll solve the problem using Ralston’s method. Our functions f1 = -2y + 4e-x and f2 = -yz3/3. Let’s look at our k-values. We will assume that y1 = y and y2 z. Here our functions will solve for a k1’s first. k1,1, k1,2, and then we solve for a k2 values, k2,1, k2,2. And you'll notice here since we're doing Ralston’s method, we have the (3/4)h terms that need to be used. Then finally, we can find our next values of y1 and y2. And this will have weighting factors of 1/3 and 2/3 respectively. We can update our xi+1 as well, which is equal to xi + h.
Let's start with our initial conditions of x = 0, y = 1, and z = 1.5. What we can do is we can calculate our k1,1 value first, which is equal to 2, our k1,2 value which equals -1.1250. Then we can start calculating our k2 values. So do k2,1, then k2,2. Now that we have our k2’s, we can calculate our new values. So we'll have x = 0.5, y = 1.0831 and z = 1.0688. We calculate our k1,1, we calculated k1,2, k2,1, and k2,2. And we do the same procedure again to get our next values. We can continue on calculating all the k-values. We can take another step to be at x = 1.5. We can calculate our k-values is one last time. And then now we can calculate our final step that we want to be at x =2 , which gives an answer of y = 0.4611 and z = 0.7701. If we look at our answers that we'll have here, you'll notice that for the RK2 method of Ralston’s, one function behaved not too badly. This is the green line and the turquoise line are matching up pretty well. However, the orange line and the red line are still quite off, which means that we would actually have to take smaller steps using the Ralston’s method or perhaps to something more powerful like the RK4 method.
This concludes the video. This project could not have been completed without the support of eCampusOntario and the University of Ottawa.