For more information, please see full course syllabus of Differential Equations

For more information, please see full course syllabus of Differential Equations

### Runge-Kutta & The Improved Euler Method

Lecture Slides are screen-captured images of important points in the lecture. Students can download and print out these lecture slide images to do practice problems as well as take notes while watching the lecture.

- Intro
- Lesson Overview
- Runge-Kutta is Know as the Improved Euler Method
- More Sophisticated Than Euler's Method
- It is the Fundamental Algorithm Used in Most Professional Software to Solve Differential Equations
- Order 2 Runge-Kutta Algorithm
- Runge-Kutta Order 2 Algorithm
- Example 1
- Example 2
- Example 3
- Example 4
- Example 5

- Intro 0:00
- Lesson Overview 0:43
- Runge-Kutta is Know as the Improved Euler Method
- More Sophisticated Than Euler's Method
- It is the Fundamental Algorithm Used in Most Professional Software to Solve Differential Equations
- Order 2 Runge-Kutta Algorithm
- Runge-Kutta Order 2 Algorithm 2:09
- Example 1 4:57
- Example 2 10:57
- Example 3 19:45
- Example 4 24:35
- Example 5 31:39

### Differential Equations Online Course

### Transcription: Runge-Kutta & The Improved Euler Method

*Hi and welcome back to the differential equations lectures here on educator.com .*0000

*My name is well Murray, and we are studying numerical techniques right now, we are about to learn about the Runge-Kutta method.*0004

*Now, this is also known as the improved Euler method so, you might also, see it called the improved Euler method this is to be distinguished from the sort of basic Euler method and we had another whole lecture on the basic Euler method.*0012

*That is the previous lecture here on educator.com so, if you are looking for the basic Euler method and that is the previous lecture if you are looking for the improved Euler method, that is this lecture right here keep watching so, find out what that is all about.*0027

*The Runge-Kutta method, also known as the improved Euler method is a way to find numerical approximations for initial value problems that we cannot solve analytically.*0043

*So, the idea here is that we have some differential equation and some initial condition and we cannot solve it analytically so, we use these techniques of numerical approximation instead.*0056

*The Runge-Kutta method is more sophisticated than Euler’s method that is what it sometimes called the improved Euler method, it is actually the method that is built into the programming packages.*0069

*If you use commercial software to solve differential equations so, it is things like Mathematics or Matlab, then the when you solve differential equations numerically on those software packages still be running some version of the Runge-Kutta method in the background.*0080

*So, we are going to learn the order to run Dakota method , that wins it is already pretty complicated what the F professional software packages uses something called the order for even more sophisticated methods and that is a little too collocated for us to go into by hand.*0100

*But we will learn the order to run Dakota method annual see him get a flavor of how it works.*0120

*So, let us check that out and get down systems actual algorithms so, you start with it an initial value problem you will have Y′ of T = some function of T and Y .*0126

*They also, have an initial value Y T = Y not and shall choose a step size and usually when you are studying differential equations the step size will be given to you it would not be your own choice to choose the step size.*0140

*So, that will usually be given of course in real life you get to choose your own step size depending on how accurate of an answer you want and how much work you want to do.*0155

*So, you start at T0Y0 and you make iterative steps to me fill in this the T N+ 1 it is just the same as it was for the Euler method it is just TN +8 so, just stepping over in horizontal steps of size H*0164

*Y MT TN +1 so, this is Y and + 1 Y N + 1 is the same as Y TN +1 now, this is much more complicated than it was for Euler’s method so, let me show the steps for this carefully.*0184

*It is Y N+ now, H instead of just H x F of TN YN that was the Euler’s method formula its H x K-1 + K2 over 2 see what they did this is an average because it is and what is it an average out.*0205

*Let me explain what these that this K-1 and K2 are so, K-1 is just F of T and Y so, that is what we had that is the same as it was for Euler’s method the K2 is different K2 is F of now, for TU plug-in TN + H and for Y you plug-in Y and + H x K1.*0223

*So, that is quite a bit more complicated so, what will do each time is will calculate this will calculate this K1 and will calculate this K2 and plug them back into this formula here and will find Y N+1.*0247

*So, and will step along will find T1 and Y 1 in T2 and Y 2 and keep going along by these little steps until you arrive at the value of T that you want to as that you want to use for your approximation of Y of T.*0265

*So, we will see how that works out it is a little complicated but it is it is it is not sort of theoretically difficult is just a matter sort of following these formulas through.*0283

*So, let us try that out in a first example really is run Dakota was step size H = .01 to estimate Y .01 in the initial value problem Y′ = 1+ T - Y and Y0 = 1 so, let me remind you of the Runge-Kutta formulas.*0295

*They run Dakota formula said TN + 1 = TN + H and Y N+1 = Y N+ H x K-1 + K2 /2 and K-1 was F T and YN and K2 that is the complicated 1 that is F of TN + H and Y N+ H K1 .*0318

*So, let us go ahead and try to figure those out here we have this the F is this function right here it is always Y′ = F of TY so, F of TY must be 1 + T - T - Y and we get our T01Y0 from the initial condition .*0369

*T0 is 0 and Y0 = 1 and so, now, let us start calculating T1 is T0 + H T0+0.1 which is 0.1 and out to find Y 1 we are to need to find these this K1 and K2 so, what is worked that out K1 is F of T0Y0 so, that is F of 0, 1 which is 1+0-1 which is 0 very convenient.*0393

*K2 is F TN + H so, that is F0.1 and YN + H x K1 so, YN was Y061 + H is 0.1 and K1 is all that is just 0 .*0433

*So, this is F of 0.1 and 1+0 so, just 1 and so, that is 1 + T - Y so, 1 +0.1 T -1 which is .1 so, that is our K-1 and K2 and now, we can find our Y1 is Y0 + H x K-1 + K2 /2 which is worth Y0Y0 was 1 + H0.1 .*0458

*Now, my K-1 was 0 my K2 was 0.1 /2 so, that is 0.1 / 2 is .05×.1 is .005 and so, I got 1 + that and so, he got 1.005.*0510

*So, my T1Y1 are 0.1 that comes from there and 1.005 and since I have already arrived at the value of T that I was looking for the stop and say that is my estimate for Y1 .005.*0537

*So, let me go back and recap here first I just copied the formulas from the beginning of the lecture that is what we found out at the beginning of the lecture for our new formulas, for TN + 1YN + 1 in terms of K-1 and K2 .*0562

*Now, the F comes from the differential equation that is F of T Y there my T0Y0, from the initial condition and my T1 is always just T0 + H so, that is 0.1 and then to find Y 1 I need my values of case so, unplugging everything into the appropriate F.*0579

*So, that is my K-1 that is my K2 playing everything into this formula for K2 that F is 0.11 and number this was my F so, it is 1 + T - Y1 +0.1-1 simplifies down to .1 so, now, I use my formula for Y 1 so, I get Y0 + H x the average of K-1 and K2 drop in what I figured out for my K2 and my K-1 was just 0 .*0603

*So, that is without 0 and out .1 come from work out there is a check I get Y 1 is 1.005 and since I already arrived at the value of T that I was asked for I got a Y value as an approximation.*0636

*So, example 2 works in any keep going with the previous example so, you definitely want to have watched example 1 before you try out this example is working to use our answer from example 1.*0655

*Reuse run Dakota was step size H = .01 0.1 to estimate Y .2 in the initial value problem is the same initial value problem we had for example 1 so, let me record first of all the formulas for Runge-Kutta our TN + 1 = TN + H our YN +1 = Y N+ H x this average K1 + K2 over 2 where the K-1is are given by K1 is just F of TN YN and K2 is more complicated F of TN + H T x T sub N + H and YN + H x case of 1 .*0668

*So, we are going to use our example from our answer from example 1 so, let me remind you what the answer from example 1 was if you have just watched it probably worth going back and looking at example 1.*0725

*Example 1 we figured out that T1 was 0.1 and our Y1 we figure this out before was 1.005 so, much as calculating those are coming from example 1 and so, let us go ahead and take it from there.*0743

*So, T 2 is T1 + H T1 0.1 H is 0.1 so, T2 0.2 and Y 2 our Y2 is before figure out Y to me go ahead and figure out what the case should be so, I will find K1 is F of TN Y Nthat is F of T1Y1 which is F of 0.1 and 1.005 .*0758

*Getting those numbers from example 1 and so, now, my F is this function right here 1 + T - Y so, 1 +0.1-1.005 and if I simplify that down it turns into 0.095 .095 so, now, I need to find my K2 its F of TN + H so, .1+ H is is .2 0.2 .*0793

*And now, Y N where was my Y N, that is 1.005 that is Y 1 + H0.1 x K-1 is 0.95 so, let us simplify that down in 2.095.*0829

*Sorry I put my decimal point the wrong place it is 0.95 .095 and so, if I multiply by .1 I get 2 0s .0095 and if we add that to 1.005 forget F of 0.2 and then 1.005 and .0095 so, 1.0145.*0849

*Now, my F function that is F right there so, it is 1 + the T value .2 - the Y value 1.0145 and so, that simplifies down .2-.0145 is .0 .1855 .*0881

*Sounds K2 and now, going to use my formula here to find Y2 Y2 is Y N Y 1 + H x K-1 + K2 /2 now, where is my Y1 there is 1.005 1.005+ my H is 0.1 K-1 was .095 and K2 is 0.1855 /2 .*0910

*And now, those are a bunch of decimals that I can just go ahead and throw into my calculator .095+ .1855÷2 x .1+1.005 and I see that when this all settles down I get 1.019025 .*0950

*And I can stop there the reason I can stop is because I have gotten to achieve value of 0.2 which is the goal T value that we are asked for the problem so, stop there and summarize T2Y2Y is T value is 0.2 and the Y value was 1.019025 .*0985

*So, that Y value right there is my estimate for Y of 0.2 and that is what we are asked for in this problem so, we remind you how all the steps worked out there.*1011

*I start out with the generic Runge-Kutta order to formulas also, known as approved Euler’s portals such as copies formulas overfill beginning of the lecture and those K1 and K2is are also, part of those formulas from the beginning of today's lecture .*1029

*This is the same initial value problem that we had for example 1 we did the first step of it in example 1 we found T1 and Y 1 so, example 2 here this can keep going with those values and so, I get my T2 is T1 + H which is 0.2 .*1046

*I am going to find K1 and K2 using my F function which I get from the differential equation so, there that is 1 + T - Y so, I plug-in T1 and Y 1 get .095 for K-1 for K2 I have apply my F function here .*1068

*I am reading off this formula right here and then plug in all the values TN + H there is my Y1 there is my H there is my K1 those simplify down 2.2 and 1.0145 and now, again using the F function appear so, I get 1 + T - Y simplifies down 2.1855 .*1092

*And then I played back into my main Runge-Kutta formula here sets run getting this line , and I just drop in all the numbers my Y1 my H and K1 and K2 worked out all those decimals on my calculator got 1.019025 and so, my T2 was 0.2 and that is my Y to write there and that is what I am stopping in the reason I am stopping there is because I have a Y .2 in the requirement for the problem.*1118

*So, since I party got into T = .2 then I take that Y value and I offer it as my approximation and as my final answer to that problem so, keep this problem in mind and also, keep this answer in mind because in the next example over to do is resolve this differential equation analytically and never go to compare our answer from the analytic solution with the estimate that we just made using the Runge-Kutta method.*1153

*So, let us see how those 2 answers compare so, example 3 we are to solve the initial value problem Y′ = 1 +2 - Y and Y0 = 1.*1181

*Resolve this initial value problem analytically in order to calculate how Y of .2 and really see how close the answer is to the estimate that we use in the previous example.*1193

*So, I cannot can have to do very much work in this problem because I have done this 1 before this is the same initial value problem that we did for example 2in the previous lecture on Euler’s methods.*1208

*So, if you do not remember that what you might want to do is go back and check out 2 to from the previous lecture on Euler’s methods so, from the Euler’s method lecture and we found the answer analytically there.*1222

*Remind you what was we found the answer was Y = C+E -T so, that is coming from the previous lecture not working that out on the spot here but if you have no idea where that is coming from just check out the previous lecture is example 2 on the Euler’s method lecture.*1248

*And so, now, we are going to compute Y of 0.25 0.2 = that if T0 .2+ E -0.2 and try that to signify that of course that is been recently used by calculator for 2130 So, 0.2+ E -.2 and I see I get 1.01873 that is approximation there so, that is my guess for Y0 .2 and that is really the answer given by an analytic solutions. 2203 They should think of that is essentially being an exact solution now, we also, solve this equation using the Runge-Kutta method and that was in example 2 of this lecture.*1267

*So, example 2 of this lecture so, that should be just above this 1 of this lecture we used the Runge-Kutta method to estimate Y of 0.2 and I am just a copy of the answer that we had back there got so, 1.019025 .*1336

*Sure that I am copying the right number there now, got 1.019025 using the Runge-Kutta estimation technique and we now, know, that the true solution is 1.0187.*1370

*So, let me just subtract those to show you how close we got there .0187 not cannot bother keeping track of decimal places after that because I see that is not 190 - hundred and 87 is 3 so, .0003 is our error there.*1388

*0.0003 is our error so, what you should really see here the new lesson you should take away from this is that the Runge-Kutta estimation technique is extremely accurate the true solution is 1.0187 our Runge-Kutta solution we figured out the previous example is 1.0190.*1416

*Very close the difference between those two answers is 0.0003 that is 1000 thousand 10,003 10,000 off from each other so, those answers are really very close so, even though it is a lot of work to calculate that Runge-Kutta solution the payoff is we get an answer that is very close to being the true solution is extremely accurate.*1443

*So, let us do a little more practice with calculating some Runge-Kutta answers in example 4 we are going to use Runge-Kutta was step size H = .0 .1 to estimate Y of 0.1 in the initial value problem Y′ = T-² + Y ² and Y001.*1467

*So, let me remind you of the Runge-Kutta formulas we have TN + 1 = TN + H and Y N+ 1 = Y N+ H + H x K1 + K2 over to this copying these back from the first slide of this as was the second slide of this lecture .*1490

*So, if you have not looked at the first couple size of this lecture that is where I am getting these formulas from where the K1 was F TN Y N and the K2 is as of TN + H and Y N+ H x K-1 .*1525

*So, let us apply those in this case Our F of TY that is just what you get from the differential equation so, that is T-² + Y ² and we start off at the initial condition that we are given so, that is Y 0s equal 1 so, Y01 start with T0, T0 = 0 and Y0 = 1 .*1551

*So, let me go ahead and plug all those numbers into the Runge-Kutta formulas so, TN +1 T1 is just T0 + H and that 0+0.1 so, that is 0.1 and now, I want to find Y 1 but in order to do that I need to know, my K1 and my K2 .*1582

*So, I got a fine K1 is F of TN Y N so, that is aft of T0Y001 and so, that is 0 ² +1 ² that is my F function 0 ² +1 ² is 1 my K2 is F of TN + H so, that is 0.10+.1 and Y N is 1 + H is .01 x K-1 is 1 so, that is 0.1 ² + now, 1 +.1 is 1.1 ² .*1606

*So, that is myself little more space here 0.01+1.21 so, that is 1.2 to select my K2 and out my Y1 is Y0 + H x K1 + K2 /2 now, my Y0 there it is this 1 by H is still 0.1 my K1 is 1 my K2 is 1.22 over 2 .*1664

*And if I just worked that out this 1 point this is 2.22 over 270.1×1.11 and so, that is .111 & get 1.111 .*1710

*And I can stop here because I got a T 1 of 0.1 I got a Y1 1.111 which is the T value is the T value those asked for the prompt for the problem so, stop there and summarize T1Y1 = 0.1 and 1.111 and so, that 1.111 that is my estimate for Y of 0.1.*1729

*So, that is what I would offer is my answer to the problem so, may I remind you where everything came from there for so, I just copy down these equations for the Runge-Kutta method to copy those down from the initial slide of the lecture 2nd slide lecture .*1762

*Then I identify what my F of T Y was that is just dysfunction that that we had for Y′ and then I identified T0 Y0 that came from the initial condition here and I started running through the equations.*1778

*T1 is T0 + H we are that is my H here so, that 0.1 my K1is F01 so, that is 0 ² +1 ² my K2 is F of this more complicated expression of getting that from up here by the way and I filled in all the numbers there so, that is T1 that is Y 0 that is H and that is K1 .*1796

*Filled in all those numbers get and plug it into my F function T² + Y ² simplify that down to 1.22 and finally use this YN +1 formula so, Y 0+ H x K1 + K2 over 2 there is Y 0 there is H there is K1 there is K2 and then I justify the decimals down to get 1.111.*1825

*So, my T1 and Y1 there is T1 came from their there is my Y1 and in a stop there and the reason I am been a stop is because I was asked to estimate Y of 0.1 and so, I am going to give my Y 1 as my estimate for Y of 0.1*1853

*The end of this example we are going to use these this same initial value problem and the same computations as the first step of the next example 5 so, hang onto these numbers and can be the same initial value problem will take it 1 more step in example 5 .*1876

*So, in example 5 reuse Runge-Kutta was step size H = 0.1 to estimate Y in 0.2 in the initial value problem Y′ = T² + Y ² and Y 0s equal 1.*1895

*Now, once you remember this is the same initial value problem that we studied in example 4 so, we are going to use our answer from example 4 to solve this if you have not just watched example 4 just go back and check that out and you will see where we are getting our starting point for this for this example 5 .*1914

*So, let me remind you of our Runge-Kutta equations TN + 1 = TN + H YN +1 = Y N+ H x K1 + K2 /2and my K-1 = F of TN YN.*1934

*My K2 = TN + H and Y N+ H x K1 so, we are going to run this algorithm for this initial value problem but we party did the first step back in example 4.*1966

*So, go ahead and copy down the answers we had from example 4 might calculate those from scratch if you want to see where they came from just go back and watch example for you will see everything there.*1988

*So, what we had there is T1 we already figured it out back in example 4 T1 was 0.1 and our Y1 figure out last time was 1.111 .*2000

*So, really use those to take this out 1 more step so, our T2 is T1 + H so, that is 0.2 find my K1 K2 so, K1 is F of TN Y is that 0.1 and 1.111 now, my F function is given by the differential equation right here T² + Y ² that is F rate there .*2015

*And so, this is point .1 ² +1.111 ² and I do not think I want to do that plug that into my calculator so, .1 ² +1.111 ² is 1.244321 .*2046

*All say that as a number in my calculator K2 is F of TN + H so, 0.2 and now, my YN that is Y once a 1.111+ H is 0.1 x K-1 which is 1.244321 .*2068

*So, this is F of 0.2 and do some calculations right there so, looks like 1.235 here so, about 1.235 here and if I plug that into F I got .2 ² +1.235 ² .*2097

*And again I am going to calculate that out on my calculator and I see I get 1.566 for my K2 number ready to drop all those numbers and my formula for YN +1 find myself a Y2 is Y 1 + H x K1 + K2 over 2 and so, my Y 1 that is 1.111111.*2129

*H is still 0.1 and my K1 is 1.244 my K2 is 1.566 got all those numbers saved in my calculator now, and now, I am just going to simplify the decimals of them definitely do that on my calculator .*2171

*So, + 1.244321÷2 x .1+1.111 so, what I am getting on my calculator is 1.25153, in there some more decimal places after that but let me summarize here.*2197

*T2Y2 according to what we just figured out where is T2 right there, Y2 is right there so, T2 is 0.2 and Y2 is 1.25153.*2231

*And that is my answer as my estimate for Y of 0.2 and that is what we are being asked for the problem check this back out so, that is that means I am time of the problem below me go ahead and go back and make sure that all the steps are totally clear there.*2249

*We started out with the generic Runge-Kutta formulas copy those down from the second slide a lecture TN + 1YN +1 and K1 K2 complicated but not too bad and remember that this is the same differential equation we had for example 4.*2272

*We already did the first step of Runge-Kutta in example 4 so, that is what I am doing right here is just taking my answers from example 4 back watch example 4 and see where they came from and they we are to run with those answers and run 1 more step to get to get 2.2 .*2289

*So, T2 is just T1 +8 that is 0.2 and then I found K1 K2 using these formulas here K1 K2 and I plug in all the values that is T1 that is Y 1 that is T1 + H and that is Y 1 that was my H and this was K1.*2311

*And then to calculate F of those values running T² + Y ² so, that is Y doing .1 ² +1.111 ² and here I am doing.2 ² +1.235 ² .*2340

*So, calculate out those decimals and I get K1 K2 the drop those in the formula for Y 2 drop those in right there multiplied by Hs 0.1 and I still have my Y1 so, there is Y 1 there is H run using this formula right here to figure out Y 2 .*2354

*Drop in all those decimals and I justify those decimals of my calculator I did not think there is any reason to do that on the screen.*2378

*So, we get 1.25153 that is my T2 is 0.2 my Y2 is 1.25153 and so, since I have gotten to the value of T that I was asked to find in the in a prompt that are rather that I was asked to find my estimate at I am just to take the Y value at that point and offer that as my estimate of Y is 0.2.*2387

*So, my final estimate there is 1.25153 since the end of this lecture on Runge-Kutta order 2 techniques also, known as the improved Euler’s method if you seen it called that maybe in a class or in a different textbook.*2418

*That also, wraps up our chapter on numerical techniques when you cannot solve the differential equation analytically you try to use 1 of these numerical techniques Euler’s method or Runge-Kutta methods.*2435

*So, that wraps up this chapter and that puts another chapter of differential equations into the books so, I really appreciate your watching.*2447

*You have been watching the differential equations lecture here on educator.com. My name is Will Murray, thanks for joining us, bye bye.*2457

4 answers

Last reply by: Dr. William Murray

Fri Dec 5, 2014 10:25 AM

Post by Josh Winfield on December 2, 2014

It looks to me that the Euler's method is approximating the slope at fn(tn,yn) by (yn+1-yn)/h and rearranging for yn+1 and the R-K method is approximating the slope at fn and fn+1 by (yn+1-yn)/h solving for yn+1 then taking the average (2yn+h(k1+k2))/2. I havnt spent long on thinking about this but I cant quite see how it is better. I can kind of see how Euler is looking back so it can look forward and R-K is looking back and looking forward so it can see the middle but not quite crystal clear atm.

1 answer

Last reply by: Dr. William Murray

Fri Sep 6, 2013 10:46 AM

Post by Nitin Patwardhan on August 31, 2013

Why is y' equal to f(t,y)?