Numerical solution of Example on Euler’s method.
Abstract
Most real life phenomena change with time, hence dynamic. Differential equations are used in mathematical modeling of such scenarios. Linear differential equations can be solved analytically but most real life applications are nonlinear. Numerical solutions of nonlinear differential equations are approximate solutions. Euler and Runge-Kutta method of order four are derived, explained and illustrated as useful numerical methods for solving single and systems of linear and nonlinear differential equations. Accuracy of a numerical method depends on the step size used and degree of nonlinearity of the equations. Stiffness is another challenge with numerical solutions of nonlinear differential equations. Although better accuracy can be obtained with smaller step size, this takes more computational effort and time. Algorithms and codes can be written using available computer programming software to overcome this challenge and to avoid computational error. The Runge-Kutta method is more applicable and accurate for diverse classes of differential equations.
Keywords
- numerical solution
- Euler method
- Runge-Kutta method of order four (RK4)
- accuracy
1. Introduction
In numerical analysis, mathematical methods are employed to produce numerical answers to mathematical expressions. It entails developing, examining, and putting into practice computer algorithms to solve continuous mathematics problems numerically [1]. These problems may originate from real-life applications in the natural sciences, social sciences, engineering, medical sciences and business where variables which vary continuously are involved.
Differential equations are the foundation of the majority of mathematical models used in the natural sciences and engineering. The numerical technique finds the solution function at a discrete set of points, approximating the derivatives or integrals in the relevant equation.
In an effort to obtain solutions that are more precise, more affordable, or more resilient to instabilities in the issue data, a number of techniques have been developed. Many of the differential equations that arise in practical problems are usually nonlinear. Nonlinear differential equations are nearly impossible to be solved precisely [2]. Most differential equations that arise in practical problems are typically nonlinear. The computational labour of solving a system of first order equations may be formidable even when the exact solution is possible [3]. It is for these reasons that techniques have been developed for computing to any degree of accuracy the numerical solution of almost any of such problems.
These techniques typically fall into “families” of increasing order of accuracy, with Euler’s method (or a close relative) frequently making up the lowest order. Adams-Bashforth techniques are “multistep” methods, whereas Runge-Kutta methods are “single-step” methods. These methods have been very successful and reliable.
In this chapter, the derivation of Euler and Runge Kutta methods are explained and illustrative examples given to explain how they are used. Algorithms/codes of the examples written with Maple mathematical programming software were also included for better comprehension and further practice.
2. The Euler method
The popular Euler method published in 1768 is attributed to Leonhard Euler (1707–1783). The method is one of the most straightforward and fundamental method of solving single and systems of ordinary differential eqs. [1]. The basic idea is as follows;
Consider initial value system:
By the definition of a derivative,
for small
Substituting Eq. (5) and Eq. (6) into Eq. (1) and Eq. (2) respectively yield the difference equations
which approximates the differential Eqs. (1) and (2).
According to [1], the Euler’s method approximates a solution (x, y) with step size
Expressing Eq. (1) and Eq. (2) in vector notation:
Where
The Euler’s method approximates a solution (x, y) by:
Given the initial value problem in [5]:
Determine.
The Euler formula is.
For the first iteration which is
When
When
When
Table 1 gives the numerical solution of Illustration 1 using different step sizes. Obviously this takes more computational effort since more iteration is needed but gives more accurate result.
X | y(x) at h = 0.02, n = 5 | y(x) at h = 0.01, n = 10 | y(x) at h = 0.005, n = 20 |
---|---|---|---|
0 | 1.0 | 1.0 | 1.0 |
0.02 | 1.019803922 | 1.019706799 | |
0.04 | 1.038852886 | 1.038665609 | |
0.06 | 1.057200704 | 1.056929219 | |
0.08 | 1.074894334 | 1.074543762 | |
0.10 | 1.091975065 | 1.091549847 |
The algorithm/ code given below can be adapted to various single differential equations for the Euler method (Figure 1).
## Illustration on Euler method#
For more on Maple programming codes and algorithms see [6].
Consider the Lorenz dynamical system given as.
Where
The Lorenz system is a classical nonlinear dynamical system. Due to the high degree of nonlinearity of the system and the number of iterations required, its numerical solution is only easily tractable using computer programming. The algorithm/Code in Maple mathematical software is given below after the table of numerical solution (Figures 2–4) and (Table 2).
X(t) | Y(t) | Z(t) | |
---|---|---|---|
1.0 | 26.77337837 | ||
2.0 | 3.307860445 | 5.707928748 | 12.82481891 |
3.0 | 33.60229026 | ||
4.0 | 2.906631532 | 4.606304372 | 17.27981641 |
5.0 | 29.67196074 | ||
6.0 | 0.1457099124 | 21.71150940 | |
7.0 | 8.807447039 | 11.68841199 | 23.40171689 |
8.0 | 4.038757258 | 0.5104950902 | 27.19520327 |
9.0 | 18.53277577 | ||
10.0 | 37.42332818 |
## This is the numerical solution of Lorenz system using Euler method##
sys:=diff(x(t),t)=sigma*(y(t)-x(t)),diff(y(t),t)=-x(t)*z(t)+r*x(t)-y(t),
diff(z(t),t)=x(t)*y(t)-b*z(t);
##restart:X:=array(0..2000000):Y:=array(0..2000000):Z:=array
(0..2000000):T:=array(0..2000000):A:=0.0:h:=0.01:N:=1000:sigma:=
10.0:b:=(8/3):r:=28.0: for m from 0 to N do T[m]:=A+m*h:X[0]:=0.1:
Y[0]:=0.1:Z[0]:=0.1:od: for m from 0 to N do X[m+1]:=X[m]+
h*(sigma*(Y[m]-X[m])):Y[m+1]:=Y[m]+h*(-X[m]*Z[m]+r*X[m]-Y[m]):
Z[m+1]:=Z[m]+h*(X[m]*Y[m]-b*Z[m]):od:
for m from 0 by 100 to N do print (m, T[m], X[m],Y[m],Z[m]);od: with(plots):
func1:=listplot([seq(X[m],m=0..N)],style=line,color=black,thickness=1):
display(func1,labels=["t","X(t)"],axes=boxed,caption="Figure1:Euler solution for X(t)");
func2:=listplot([seq(Y[m],m=0..N)],style=line,color=blue,thickness=1):
display(func2,labels=["t","Y(t)"],axes=boxed,caption="Figure2:Euler solution for
Y(t)"); func3:=listplot([seq(Z[m],m=0..N)],style=line,color=red, thickness=1):
display(func3,labels=["t","Z(t)"],axes=boxed,caption="Figure
3:Euler solution for Z(t)");
For more on Lorenz system see [7].
3. The Runge-Kutta method of order four
One of the well-known numerical techniques for solving differential equations is the Runge-Kutta method. The Runge-Kutta method is a family of methods which depend on the order of derivatives involved. The Runge-Kutta method of order four is the classical form of the method in which four values of the derivatives are used for each iteration [1].
3.1 Derivation of Runge-Kutta method of order four
The Taylor series of functions of one variable is:
when
Then Eq. (13) becomes.
Taylor series of functions of two variables is:
when
where the partial derivatives are all evaluated at the point
Consider the differential equation
From Eq. (15).
Hence
The main idea is to select several points so that the Taylor series of expansion Eq. (19), coincide with the terms on the right hand side of Eq. (32).
Using Eq. (32), these values become;
where all functions are evaluated at the point (x0, y0).
Considering an expression of the form
Equating the expression to the right hand side of Eq. (37) through Eq. (40) to obtain four equations in seven unknowns.
Choosing three unknown quantities arbitrarily since there are four equations in seven unknowns.
Let
Solving Eq. (46) through Eq. (47) simultaneously produced.
Connecting Eq. (33) and the expression (41).
In general
Where
This is the Runge-Kutta formula of order four for a single first order differential equation.
The formula can be generalized for system of differential equations.
Consider the system of two initial-value differential equation:
The Runge-Kutta formula of order four for system of two initial-value differential equation of the form of Eq. (54) and Eq. (55) is
Where
Generalizations of the formular to system of more than two equations follow a similar pattern.
Further insights and resources on the Runge- Kutta method can be found in [8, 9, 10].
Given the initial value problem.
Determine.
The RK4 formula is:
Where
Hence two iterations shall be needed.
When
For the second iteration, when n = 1:
Where
Consider the Lorenz dynamical system given as.
Where
The number of iteration needed is determine thus:
The numerical solution is generated using Maple mathematical programming software. The codes and solution are presented below (Table 3).
## This is the numerical solution of Lorenz system using RK 4method## sys1:=diff(x(t),t)=sigma*(y(t)-x(t)),diff(y(t),t)=-x(t)*z(t)+r*x(t)-y(t),diff(z(t),t)=x(t)*y(t)-b*z(t); ## restart:X:=array(0..20000):Y:=array(0..20000):Z:=array(0..20000):T:=array(0..20000):A:=0.0:h:=0.1:N:=100:sigma:=10.0:b:=(8/3):r:=28.0: for m from 0 to N do T[m]:=A+m*h:X[0]:=0.1:Y[0]:=0.1:Z[0]:=0.1:od: for m from 0 to N-1 do K1:=h*(sigma*(Y[m]-X[m])): M1:=h*(-X[m]*Z [m]+r*X[m]-Y[m]):N1:=h*(X[m]*Y[m]-b*Z[m]):K2:=h*(sigma*((Y[m]+ M1/2)-(X[m]+K1/2))): M2:=h*(-(X[m]+K1/2)*(Z[m]+N1/2)+r*(X[m]+ K1/2)-(Y[m]+M1/2)):N2:=h*((X[m]+K1/2)*(Y[m]+M1/2)-b*(Z[m]+N1/2)) :K3:=h*(sigma*((Y[m]+M2/2)-(X[m]+K2/2))): M3:=h*(-(X[m]+K2/2)*(Z [m]+N2/2)+r*(X[m]+K2/2)-(Y[m]+M2/2)):N3:=h*((X[m]+K2/2)*(Y[m]+ M2/2)-b*(Z[m]+N2/2)):K4:=h*(sigma*((Y[m]+M3)-(X[m]+K3))):M4:=h* (-(X[m]+K3)*(Z[m]+N3)+r*(X[m]+K3)-(Y[m]+M3)):N4:=h*((X[m]+K3)*(Y [m]+M3)-b*(Z[m]+N3)):X[m+1]:=X[m]+(K1+2*K2+2*K3+K4)/6:Y[m+1]:=Y [m]+(M1+2*M2+2*M3+M4)/6: Z[m+1]:=Z[m]+(N1+2*N2+2*N3+N4)/6:od: for m from 0 by 10 to N do print (m, T[m], X[m],Y[m],Z[m]);od:
X(t) | Y(t) | Z(t) | |
---|---|---|---|
1.0 | 25.75673332 | ||
2.0 | 26.86095558 | ||
3.0 | 28.21573058 | ||
4.0 | 24.99141661 | ||
5.0 | 28.79099030 | ||
6.0 | 25.79606864 | ||
7.0 | 26.47905713 | ||
8.0 | 28.65893980 | ||
9.0 | 24.64927991 | ||
10.0 | 28.83748475 |
For further insight on programming with Maple see [6].
4. Conclusions
This chapter discusses the numerical solution of differential equation using Euler and Runge-Kutta methods. The formulas were derived and illustrations given to understand their applications. Algorithms written in Maple computational environment were provided for better understanding and further practice.
References
- 1.
Akinsola VO, Oluyo TO. Mathematical analysis with numerical solutions of the mathematical model for the complications and control of diabetes mellitus. Journal of Statistics and Management Systems. 2019; 22 (5):845-869. DOI: 10.1080/09720510.2018.1556409 - 2.
Bronshtein IN, Semendyayev KA, Musiol G, Mühlig H. Handbook of Mathematics. 6th ed. London: Springer; 2015 - 3.
Baumann G. Mathematics for Engineers IV: Numerics. München: Oldenbourg Wissenschaftsverlag; 2010 - 4.
Lynch S. Dynamical Systems with Applications using Maple. 2nd ed. Basel: Birkhäuser Verlag AG, Springer; 2010 - 5.
Shah NH. Numerical Methods with C + + Programming. New Delhi: PHI Learning; 2009. p. 243 - 6.
Richard H. Computer Algebra Recipes for Mathematical Physics. Boston: Birkhauser; 2005 - 7.
Montoya CA, Sánchez RD, Castaño LF. Approach to the numerical solution of Lorenz system on SoC FPGA. In: 2016 XXI Symposium on Signal Processing, Images and Artificial Vision (STSIVA). Colombia: Universidad Pontificia Bolivariana (UPB) Seccional Bucaramanga; 2016. pp. 1-4. DOI: 10.1109/STSIVA.2016.7743305 - 8.
Enns RH, McGuire GC. Nonlinear Physics with Maple for Scientists and Engineers. 2nd ed. Massachusetts, USA: Birkhäuser Boston, Springer Science+Business Media; 2000 - 9.
Steele WA, Vallauri R. Computer simulations of pair dynamics in molecular fluids. Molecular Physics. 1987; 61 (4):1019-1030. DOI: 10.1080/00268978700101621 - 10.
Zou Y. Multi-Variable Calculus, A First Step. Berlin/Boston: Walter de Gruyter GmbH; 2020