 # Solving ODEs using Three Forms of Forth Order Runge Kutta

by admin in on April 27, 2019

This code solves a single ordinary differential equation (ODE) using three forms of fourth order Runge Kutta (RK4). A comparison between the solutions on one chart will be produce, with a second chart presenting the errors of these forms.

### Code Outputs:

• Chart comparison of the exact solution (if exist) with the numerical Solutions.
• Error chart of the three RK4 forms.
• Maximum Error Value of each RK4 form.

Max. Error-First-Form = 2.8058e-05
Max. Error-Second-Form = 2.8075e-06
Max. Error-Third-Form = 2.8058e-05  ### Input Requirements:

• ODE you want to solve.
• Initial Condition.
• Exact solution (optional)

### About the Method:

Runge–Kutta methods are a family of implicit and explicit iterative methods, which include the well-known routine called the Euler Method, used in temporal discretization for the approximate solutions of ordinary differential equations. These methods were developed around 1900 by the German mathematicians Carl Runge and Wilhelm Kutta.

### List of Runge–Kutta methods:

Runge–Kutta methods are methods for the numerical solution of the ordinary differential equation which take the form     Each method listed on this page is defined by its Butcher tableau, which puts the coefficients of the method in a table as follows: The most widely known member of the Runge–Kutta family is generally referred to as ‘RK4‘, ‘classical Runge–Kutta method‘ or simply as ‘the Runge–Kutta method‘.

Let an initial value problem be specified as follows: Here y is an unknown function (scalar or vector) of time t, which we would like to approximate; we are told that y’, the rate at which y changes, is a function of t and of y itself. At the initial time t0 the corresponding y value is y0. The function f and the data t0, y0 are given.

Now pick a step-size h > 0 and define for n = 0, 1, 2, 3, …, using (Note: the above equations have different but equivalent definitions in different texts).

Here yn+1 is the RK4 approximation of y(tn+1), and the next value (yn+1) is determined by the present value (yn) plus the weighted average of four increments, where each increment is the product of the size of the interval, h, and an estimated slope specified by function f on the right-hand side of the differential equation.

• k1 is the increment based on the slope at the beginning of the interval, using y (Euler’s method);
• k2 is the increment based on the slope at the midpoint of the interval, using and k1;
• k3 is again the increment based on the slope at the midpoint, but now using y and k2;
• k4 is the increment based on the slope at the end of the interval, using and k3.

In averaging the four increments, greater weight is given to the increments at the midpoint. Ifis independent of y, so that the differential equation is equivalent to a simple integral, then RK4 is Simpson’s rule.

The RK4 method is a fourth-order method, meaning that the local truncation error is on the order of O(h^5), while the total accumulated error is on the order of O(h^4).

In many practical applications the function is independent of t (so called autonomous system, or time-invariant system, especially in physics), and their increments are not computed at all and not passed to function , with only the final formula for tn+1 used.

### Values of Butcher Tableau:

The first standard form of Runge Kutta has the following Butcher tableau values:

 0 1/2 1/2 1/2 0 1/2 1 0 0 1 1/6 1/3 1/3 1/6

A slight variation of ‘the’ Runge–Kutta method is also due to Kutta in 1901 and is called the 3/8-rule. The primary advantage this method has is that almost all of the error coefficients are smaller than in the popular method, but it requires slightly more FLOPs (floating-point operations) per time step. Its Butcher tableau is:

 0 1/3 1/3 2/3 −1/3 1 1 1 −1 1 1/8 3/8 3/8 1/8

The third form of Runge Kutta has the following Butcher tableau values:

 0 1/2 1/2 1/2 -1/2 + 1/sqrt(2) 1-1/sqrt(2) 1 0 – 1/sqrt(2) 1 + 1/sqrt(2) 1/6 1/3 – 1/(3 sqrt(2)) 1/3 + 1/(3 sqrt(2)) 1/6

### References:

 Runge, Carl David Tolmé (1895), ‘Über die numerische Auflösung von Differential gleichungen’, Mathematische Annalen, Springer, 46 (2): 167–178, doi:10.1007/BF01446807.

 Kutta, Martin (1901), Beitrag zur näherungweisen Integration totaler Differentialgleichungen.

 Ascher, Uri M.; Petzold, Linda R. (1998), Computer Methods for Ordinary Differential Equations and Differential-Algebraic Equations, Philadelphia: Society for Industrial and Applied Mathematics, ISBN978-0-89871-412-8.

 Atkinson, Kendall A. (1989), An Introduction to Numerical Analysis (2nd ed.), New York: John Wiley & Sons, ISBN978-0-471-50023-0.

 Butcher, John C. (May 1963), Coefficients for the study of Runge-Kutta integration processes3 (2), pp. 185–201, doi:10.1017/S1446788700027932.

 Butcher, John C. (1975), ‘A stability property of implicit Runge-Kutta methods’, BIT15: 358–361, doi:10.1007/bf01931672.

Share Now!

#### Release Information

• Price
:

\$7.99

• Released
:

April 27, 2019

• Last Updated
:

May 29, 2019