## Runge-Kutta method vs Euler method

In this post, I will compare and contrast two of the most well known techniques for the solving of systems of differential equations. The Runge-Kutta method is named for its’ creators Carl Runge(1856-1927) and Wilhelm Kutta (1867-1944). The Runge-Kutta method is very similar to Euler’s method except that the Runge-Kutta method employs the use of parabolas (2nd order) and quartic curves (4th order) to achieve the approximations. In essence, the Runge-Kutta method can be seen as multiple applications of Euler’s method at intermediate values, namely between and . I will be focusing on the 4th order method, as it is the most common method for obtaining graphical representations of systems of equations. Any referrals to the “RK method” are in reference to the Runge-Kutta 4th order method for solving systems of differential equations.

The backbone of the RK method lies in the idea of using a weighted average of the slopes of field segments at four(4) points very close to the current point, , of whom’s location is determined by applying Euler’s method. If we assume that we know the location , which is the Euler approximation of the function . To obtain the next approximate solution, , we must apply the fundamental theorem of calculus (developed by Sir Isaac Newton and/or Gottfried Wilhelm Leibniz, this argument is a complete topic of it’s own). The theorem says: = . In order to obtain an approximation of this integral, Simpson’s rule must be applied. Simpson’s rule states: .

Now, the RK method’s backbone lies in the use of a “weighted average” of the slopes at four points near our current point. To obtain the fourth point, two evaluations must be made the the middle point, . The approximation then becomes . To begin calculating the approximation, we must start the first of our four evaluations. Doing this requires us to calculate the slope of the line that passes through our initial point . In order to find this slope, the value of the function must be computed. As is common with most demonstrations of the RK method, label this slope **k1**.

Here is where the first real difference between the RK method and the Euler method arises. The next step in the Euler method tells us that the next value will be while the RK method takes half of this increase in the y coordinate, , and goes halfway between the original and the next step .

The next step is to perform the second evaluation. The x value of our point is and the y value is . In order to calculate the slope at this point, we must evaluate the function at the point . The value of this slope is to be labeled **k2**.

The Euler method would have us move one step size to the point . Just as in the last step, with the RK method, we take half of this increase leaving us at the point . As is required with the RK method, we must calculate the slope at this by evaluating the function . The value of this slope is to be labeled as **k3**. If we move along this slope for one step size, we would be at the x value and the y value . The y value differs only from the last value by . We now move to the x value and the y value which accounts for the last increase.

The final evaluation is to be made at this point by calculating the slope of the solution which passes through the point . This slope is to be labeled **k4.** This value is not the original value predicted by Euler’s method. After performing these evaluations, we now have four slopes very close to the point ; one at , one at and two at . In order to determine the next point, the RK method takes a weighted average of these slopes.

.

As is similar with the Euler method, it is possible to put a bound on the error between the exact solution value, and the approximate value calculated with the RK method. This difference is the *local truncation error*; , where M is a constant depending on the function and the specified interval.

So why go through all this extra work when the Euler method seems much quicker and to the point? The fact is, the Euler method provides a very shallow approach to the solutions that we desire from differential equations. In order to achieve a more accurate approximation with the Euler method, we must decrease the step size. By decreasing the step size, the amount of steps required to reach the desired point greatly increases, thus **greatly** increases the amount of meticulous calculations that must be done. While, on the other hand, the RK method may be a bit more complicated, the error is almost non existant after the first application of the method.

An interesting example of why the RK method is much, much more effective than the Euler method can be shown by examining some of the world’s most interesting curves, namely the Lorenz attractor and the Rossler attractor. The first curve I will examine is the Lorenz attractor. (Most of the following information is gathered from Jonas Bergman’s Doctoral thesis, titled *Knots in the Lorentz system* ca 2004).

The Lorenz attractor was introduced by Edward Lorenz in 1963, and is a 3D structure that corresponds to the long term behavior of a chaotic flow. The attractor shows how the state of a dynamic system( the three variables of a three dimensional system) and how they evolve over time in a complex, non repeating pattern. The attractor itself, comes from simplified equations of convection rolls arising in the atmosphere.

The Lorenz equations are a set of three coupled non-linear ordinary differential equations. They make up a simplified system describing the two-dimensional flow of a fluid. As can be seen, the derivative of all three variables is given with respect to *t*, and as a function involving one or both of the other variables. The three equations are as follows:

The most common associated values associated with the graphical representation of the lorenz attractor are: sigma = 10, r= 28, and b = 8/3.

To obtain a graph of the Lorenz attractor I created an m file containing the following:

[T,Y]=threeplot(‘lorenz’,0.1,0.1,0.1,0,30);

function F=lorenz(t,vec)

sigma=10.0;

rho=28.0;

beta=2.66666666;

x=vec(1);

y=vec(2);

z=vec(3);

F(1)= sigma* (y -x);

F(2)= rho* x – y – x*z;

F(3)= -beta* z + x*y;

F=transpose(F);

Then I plotted it with matlab using the plot3 command and obtained the following:

As you can see, this is a truly remarkable system of equations. To see just how chaotic the values of x,y, and z change I will borrow a figure from the esteemed British Mathematician Lewis Dartnell, in which x=red, y=green, z=blue.

It is clearly evident that there exists no pattern in the behavior of this attractor. Numerical analysis of such behavior is very difficult. One of the properties of a chaotic system is that it is sensitive to initial conditions. This means that no matter how close two different initial states are, their trajectories will soon diverge. This property indicates that accuracy is pivotal in obtaining any sort of a reasonable solution. Methods such as Euler’s method will not provide even a close approximation. Why you may ask? Euler’s method gives us an approximation of a solution. This approximation is close to what the solution curve may look like in most cases, but in this case the error produced by the Euler will ultimately skew the results. Even decreasing the step size to an almost infintesimally small size will not provide a solution, as millions small steps along the slope would have to occur. This is popularly referred to as the “Butterfly Effect”, whereby small changes in the initial state can lead to rapid and dramatic differences in the outcome, especially in this case. Whereas the RK method provides us with a very reasonable solution to such systems. In the RK method, the lower order “error” terms will inevitably cancel out, providing a proper representation of the behavior of the Lorenz system.

Another chaotic system that displays the superior approximation of the RK method as opposed to the Euler method is the Rossler attractor. (Most of the information on the Rossler attractor is obtained from Rossler’s 1976 publication titled *An Equation for Continuous Chaos).* Otto Rossler published his paper on the Rossler attractor in 1976, intending for it to behave similarly to the Lorenz attractor. The behavior of the attractor is best summarized by it’s creator in his original publication ” An orbit within the attractor follows an outward spiral close to the *x*,*y* plane around an unstable fixed point. Once the graph spirals out enough, a second fixed point influences the graph, causing a rise and twist in the *z*-dimension. In the time domain, it becomes apparent that although each variable is oscillating within a fixed range of values, the oscillations are chaotic”(Rossler 103).

The equations that define this chaotic system are:

.

Two sets of values are most commonly used to illustrate the behavior of this system, namely a=0.2, b=0.2, c=5.7, and a=0.1, b=0.1, and c=14. The latter of the two sets has been used to display the systems behavior in recent years.

To obtain a graph of the Rossler attractor, I created an m file in matlab. The code is as follows:

function F=Rossler(t,vec) a=0.2; b=0.2; c=5.7; x=vec(1); y=vec(2); z=vec(3); F(1)= -y-z; F(2)= x+a*y; F(3)= b+z*(x-c); F=transpose(F); Plotting the results using the plot3 command yields

Again, the systems chaotic behavior is very evident.

The chaotic behavior of the Rossler system is readily evident from the behavior of the graph. Borrowing another time series from Lewis Dartnell, with x=red, y=green, and z=blue, the results are changing at such a chaotic rate that they are almost impossible to distinguish from one another.

With the behavior changing so rapidly, the room for error is next to nothing. Just as in the Lorenz system, the “approximation” obtained from the Euler method will not give us an acceptable answer. In order to obtain even a remotely accurate model with the Euler method, the step size would have to be infintesimally small, and would take an obscure amount of time to accomplish. While, with the RK method, all of the lower order “error” terms cancel out, yielding a reasonable approximation to the behavior of the system.

While both the RK method and the Euler method have strengths and weaknesses, in the analysis of dynamic time varying chaotic systems, the RK method towers over the almost obsolete Euler method. With the room for error being so small in such an erratic system, one is forced to use the most accurate of numerical approximation techniques, and in these cases, this is generally associated with the RK 4th order method.

February 6, 2009 at 8:45 am

Where did you get the code for the graphs?

February 6, 2009 at 9:57 am

i wrote it? lol

April 3, 2009 at 6:15 am

Excellent job, Justin.

A+

Gary Davis

May 28, 2009 at 11:35 pm

wah berarti bangt sob penge\tahuannya makasih langsung aku copas neh wat tugas kuuiah

berkunjung tempatku ya walaupun masih sangat minim ilmunya yang ku tuangan dalam blog maklum baru 3 hari

September 23, 2009 at 7:20 am

Brilliantly written, I really appreciate your effort.

September 25, 2009 at 12:30 pm

Hi, that was a wonderful insight on RK method.

I have something to ask- you have used the RK method to solve a system of 3 linear ODEs. Can the RK method be used to solve say system of 5 linear ODEs and if yes, does the ‘n’th integration step remain same?

Do post a reply if anyone is aware..

September 25, 2009 at 12:56 pm

Hi Ram,

Yes the Runge Kutta method can be used for systems larger than 3 linear ODE’s, as long as initia values are provided for each ODEl. The solving of such systems is relatively the same as it would be for any of system of Linear De’s The initial values for the system give the RK method a starting point to begin the weighted average calculations, and therefore cause the RK method to not be limited to a certain size of linear DE’s. MATLAB’s ode45 is a great way to illustrate this.

September 25, 2009 at 1:06 pm

Hi jmckennon (i/m terribly sorry but I dont know your name :| )

Thanks very much for your reply.

Based on an 2nd order RK integration step for 2 dimensional system of ODEs (which i found by googling), i’ve written down a similar step for 5 dimensional system (as in my case). The system is a IVP i.e it has 5 initial conditions, one for each dependent variable. Can I please get your email ID so that I can get it checked from you. It would be of great help to me..

Thanks again.

RAM

September 25, 2009 at 1:48 pm

Certainly, my email is jmckennon@umassd.edu

September 25, 2009 at 10:47 pm

thanks and mail sent….

December 11, 2009 at 4:15 pm

I am always searching for recent posts in the WWW about this subject. Thankz!!

December 20, 2009 at 10:22 pm

it helped me alot

February 21, 2010 at 7:53 pm

hi, can some1 explain me…. when i plot the graph.. the x vs t graph… the y vs x graph..and the z vs x graph… ya, i got the graph.. and also the butterfly effect.. and, how can i read the graph???? n make some discussion and conclusion??? i’d make many graph for different intial value and also diffrent value of rayleigh… pls help me…!

March 5, 2010 at 4:09 am

I like the layout of your blog and I’m going to do the same thing for mine. Do you have any tips? Please PM ME on yahoo @ AmandaLovesYou702

March 28, 2010 at 7:45 am

thanks man, its the collection

June 25, 2010 at 3:33 am

This really great dude.

June 25, 2010 at 8:54 am

\m/

June 25, 2010 at 8:54 am

hi

June 6, 2011 at 1:12 pm

Chaos simulation is an exotic problem. You forgot to mention the computation time.

March 30, 2012 at 11:45 am

Pls I need more explanation on the comparison

August 18, 2012 at 4:28 pm

Thanks a lot for posting this. So if we use Euler method and Runge Kutta Method which solution will be more accurate ?

September 29, 2012 at 1:14 am

How will applicate of RK method in real life? Pls i need reply from any body that know it

May 4, 2013 at 12:45 pm

Bakwaas…not at all understanding..

December 3, 2013 at 8:50 am

It is not clear to me why Runge-Kutta a better method, In the Runge-Kutta method you will be evaluating the DE mutipul times which will take longer than evaluating it once as with the Euler method. Therefore with the euler we can take a smaller step size for the same amount of computational time. The smaller step size will result in the eluer method being more accurate for the same amount of work.