This article will present an adaptive Runge-Kutta method which combines Euler method (having order 1) with Modified Euler method (having order 2) to estimate the error produced b[r]
Trang 1AN ALGORITHM AND ITS IMPLEMENTATION FOR AN ADAPTIVE
RUNGE-KUTTA METHOD OF THE PAIR OF ORDERS 1 AND 2
Pham Thi Minh Hanh *
University of Technology - TNU
ABSTRACT
Adaptive Runge-Kutta methods are practical in approximating the solution of an initial value problem (IVP) because of their efficiency This article will present an adaptive Runge-Kutta method which combines Euler method (having order 1) with Modified Euler method (having order 2) to estimate the error produced by the first method, and basing on that estimate to decide which step-size would be taken for the next step The article also presents its algorithm, how the algorithm works, and its implementation in Matlab as well
Keywords: initial value problem, Runge-Kutta, Euler method, adaptive Runge-Kutta method,
error control
INTRODUCTION*
Consider the IVP
𝑦′= 𝑓(𝑥, 𝑦), 𝑦(𝑥0) = 𝑦0,
where 𝑦 = 𝑦(𝑥), 𝑥 ∈ ℝ Adaptive
Runge-Kutta methods are useful in reducing the
number of computations and the local
truncation error For such an adaptive method
which combines a Runge-Kutta method of
order 1 and another of order two, every
calculation becomes simpler This method is
the simplest in the family of adaptive
Runge-Kutta methods
The main idea of the method is that: First, we
use a Runge-Kutta method of order 1 (with 1
step) to approximate the solution at 𝑥0+ ℎ,
𝑤1= 𝑤0+ 𝑏1ℎ𝐹1 (1.1) where ℎ > 0 is a step-size, and 𝑤0= 𝑦0,
𝐹1= 𝑓(𝑥0, 𝑤0), the constant 𝑏1 is a
parameter
Then, we use another Runge-Kutta method of
order 2 approximating the solution, with
𝑤1∗= 𝑤0+ ℎ (𝑏1∗𝐹1+ 𝑏2∗𝐹2), (1.2)
to estimate the error produced by (1.1), where
𝐹2= 𝑓(𝑥0+ 𝑐2ℎ, 𝑤0+ 𝑎2ℎ) and 𝑏1∗, 𝑏2∗, 𝑐2, 𝑎2
are parameters For all parameters, we are
going to search for their suitable values such
*
Tel: 0977 791201, Email: phamminhhanh86@gmail.com
that the approximations generated by (1.1) and (1.2) are identical to the Taylor expansions of corresponding orders Then, basing on these approximations, we can determine whether the local truncation error produced by (1.1) is confidently accepted and adjust the step-size in the next step if it is needed (to approximate the solution at
𝑥0+ 2ℎ)
Now, we are going to derive those suitable parameters First of all, the Taylor expansion
up to order 3 for the exact solution 𝑦(𝑥) of the IVP at 𝑥0 is
𝑦(𝑥0+ ℎ) = 𝑦(𝑥0) + ℎ𝑦′(𝑥0) +ℎ2
2 𝑦′′(𝑥0) +
ℎ3
6 𝑦′′′(𝜉), for some 𝜉 ∈ (𝑥0, 𝑥0+ ℎ) This can be rewritten as
𝑦(𝑥0+ ℎ) = 𝑤0+ ℎ𝑓(𝑥0, 𝑦0) +
ℎ 2
2 𝑓′(𝑥0, 𝑦0) +ℎ63𝑓′′(𝜉, 𝑦(𝜉)), (1.3) where
𝑓′(𝑥0, 𝑦0) = 𝑓𝑥(𝑥0, 𝑦0) + 𝑓𝑦(𝑥0, 𝑦0) 𝑦′(𝑥0)
= 𝑓𝑥(𝑥0, 𝑦0) + 𝑓𝑦(𝑥0, 𝑦0)𝑓(𝑥0, 𝑦0) Now, using Taylor expansion up to order 2 of two variables, we have
𝐹2= 𝑓(𝑥0+ 𝑐2ℎ, 𝑤0+ 𝑎2ℎ) = 𝑓(𝑥0, 𝑦0) +
ℎ (𝑐2𝑓𝑥(𝑥0, 𝑦0) + 𝑎2𝑓𝑦(𝑥0, 𝑦0)) + 𝑂(ℎ2)
Trang 2Hence, omitting the term relate to 𝑂(ℎ2) =
𝑂(ℎ3), the right-hand side of (1.2) can be
rewritten as
𝑤0+ ℎ(𝑏1∗+ 𝑏2∗)𝑓(𝑥0, 𝑦0) +
ℎ2𝑏2∗[𝑐2𝑓𝑥(𝑥0, 𝑦0) + 𝑎2𝑓𝑦(𝑥0, 𝑦0)] (1.4)
Since then, identifying the right-hand side of
(1.3) and (1.4), we get
{
𝑏1∗+ 𝑏2∗= 1
𝑏2∗𝑐2=1
2
𝑏2∗𝑎2=1
2𝑓(𝑥0, 𝑦0)
(1.5)
System (1.5) has many solutions However,
we fix a favorite solution 𝑏1∗= 𝑏2∗= 1/2,
𝑐2= 1, and 𝑎2 = 𝑓(𝑥0, 𝑦0) With this choice
of parameters, the method of order 2 is
exactly Modified Euler method And if we
take 𝑏1= 1, the method of order 1 is just
Euler method The next section presents how
to use both approximations to estimate the
local truncation error produced by Euler
method, and how the adaptive algorithm
works This adaptive Runge-Kutta method is
called one of orders 1 and 2
ERROR CONTROL
We require that the error can not exceed a
given 𝜀 > 0 Local truncation error of (1.1) at
𝑥0+ ℎ is
𝜏1(ℎ) =𝑦(𝑥0+ ℎ) − 𝑤1
ℎ = 𝑂(ℎ)
That of (1.2) is
𝜏1∗(ℎ) =𝑦(𝑥0+ ℎ) − 𝑤1∗
ℎ = 𝑂(ℎ2)
So, 𝜏1(ℎ) = (𝑦(𝑥0+ ℎ) − 𝑤1)/ℎ
=1
ℎ[(𝑦(𝑥0+ ℎ) − 𝑤1∗) + (−𝑤1+ 𝑤1∗)]
= 𝜏1∗(ℎ) +1
ℎ(𝑤1∗− 𝑤1)
So, since 𝜏1∗(ℎ) has a high order than 𝜏1(ℎ),
𝜏1(ℎ) ≈ (𝑤1∗− 𝑤1)/ℎ
Moreover, there exists a constant 𝐾 such that
𝜏1(ℎ) ≈ 𝐾 ℎ Adjusting the step-size to 𝑞ℎ
produces a local truncation error from (1.1),
𝜏1(𝑞ℎ) ≈ 𝐾(𝑞ℎ) ≈𝑞ℎ(𝑤1∗− 𝑤1)
To adjust the step-size, we require that
|𝜏1(ℎ)| ≤ 𝜀 or 𝑞|𝑤1∗− 𝑤1|/ℎ ≤ 𝜀 Hence,
𝑞 ≤ 𝜀ℎ
|𝑤1∗− 𝑤1| From this bound, 𝑞 is chosen conservatively
to reduce the cost of computation for evaluating function when the steps are repeated Normally, 𝑞 is taken to be 0.5𝜀ℎ/
|𝑤1∗− 𝑤1| Then, if 𝑞 < 1, we reject ℎ and adjust the step-size to 𝑞ℎ, then recalculate the all approximations at this step Otherwise, if
𝑞 ≥ 1, we keep computed values for this step, but change the step-size to 𝑞ℎ in the next step,
to approximate the solution at 𝑥0+ 2ℎ For the latter, when 𝑞 ≥ 1, we accept 𝑤1 as the approximation of 𝑦(𝑥0+ ℎ)
The estimate for the local truncation error
𝜏1(ℎ) is denoted by
𝑅 =|𝑤1∗− 𝑤1|
1 2ℎ|−𝐹1+ 𝐹2|
We will use this quantity later in the pseudo-code of the algorithm
Table 1 Butcher Tabular for parameters of the
adaptive Runge-Kutta of orders 1 and 2 method
Here, 𝑎 21 𝑓(𝑥 0 , 𝑦 0 ) = 𝑎2= 1
𝑐1= 0
𝑐2 = 1 𝑎21= 1
1/2 1/2
IMPLEMENTATION FOR THE ADAPTIVE RUNGE-KUTTA METHOD OF ORDERS 1 AND 2
The following pseudocode describes the algorithm for the adaptive Runge-Kutta method
to approximate the solution of the IVP:
𝑦′= 𝑓(𝑥, 𝑦), 𝑎 ≤ 𝑥 ≤ 𝑏, 𝑦(𝑎) = 𝛼, such that the local truncation error is bounded by a given tolerance 𝜀 > 0
Trang 3INPUT function 𝑓, endpoints 𝑎 and 𝑏, initial
value 𝛼, tolerance 𝜀, maximum step-size
ℎ𝑚𝑎𝑥, minimum step-size ℎ𝑚𝑖𝑛
OUTPUT mesh point 𝑥, current step-size ℎ,
approximation 𝑤 of 𝑦(𝑥), or message that
ℎ𝑚𝑖𝑛 is exceeded (the procedure fails)
Step 1 (Initiate the procedure)
𝑥 ≔ 𝑎; 𝑤 ≔ 𝛼, ℎ = ℎ𝑚𝑎𝑥, 𝐹𝐿𝐴𝐺 ≔ 1;
OUTPUT (𝑥, 𝑤)
Step 2 While (𝐹𝐿𝐴𝐺 = 1) do steps 3-9
Step 3 𝐹1≔ ℎ𝑓(𝑥, 𝑤);
𝐹2≔ ℎ𝑓(𝑥 + ℎ, 𝑤 + 𝐹1);
Step 4 𝑅: =1ℎ|𝐹1− 𝐹2|
Step 5 If 𝑅 < 𝜀 then do
𝑥 ≔ 𝑥 + ℎ; (Adopt the approximation.)
𝑤 ≔ 𝑤 + 𝐹1;
OUTPUT (𝑥, 𝑤, ℎ); end do; End If
Step 6 𝑞 ≔ 0.5𝜀/𝑅
Step 7 If 𝑞 ≤ 0.1 then ℎ ≔ 0.1ℎ
elseif 𝑞 ≥ 4 then ℎ ≔ 4ℎ
else ℎ ≔ 𝑞ℎ
End If
Step 8 If ℎ > ℎ𝑚𝑎𝑥 then ℎ ≔ ℎ𝑚𝑎𝑥;
End If
Step 9 If 𝑥 ≥ 𝑏 then 𝐹𝐿𝐴𝐺 ≔ 0
elseif 𝑥 + ℎ > 𝑏 then ℎ ≔ 𝑏 − 𝑥
elseif ℎ < ℎ𝑚𝑖𝑛 then 𝐹𝐿𝐴𝐺 ≔ 0;
OUTPUT(“minimum h exceeded”)
(Procedure fails!)
STOP
EXAMPLE
With the use of the algorithm, we are going to
approximate the solution of the IVP:
𝑦′= 𝑦 − 𝑥2+ 1, 0 ≤ 𝑥 ≤ 1.5, 𝑦(0) = 0.5
We take the tolerance 𝜀 = 0.06, and the
maximum, minimum step-sizes ℎ𝑚𝑎𝑥 =
0.25, ℎ𝑚𝑖𝑛 = 0.001, respectively
The approximations are represented in Table
2 The results are obtained with the
implementation of the algorithm programmed
in Matlab It is easy to see that the exact solution of the IVP is 𝑦(𝑥) = (𝑥 + 1)2−𝑒2𝑥
So, we can determine the absolute error of the approximation at each mesh point 𝑥𝑖 This table also reveals the value of 𝑦(𝑥) (in column 2) and the absolute error (in column 5) at each mesh point Column 4 and 6 indicate the approximations obtained by Euler method and Modified Euler method, respectively Column 7 presents the estimate for the local truncation error 𝜏𝑖+1(ℎ) produced by Euler method at the operating mesh point 𝑥𝑖+1
SUMMARY The family of the adaptive Runge-Kutta methods has the advantages in finding a highly exact approximation for the solution of
an IVP It is a favor in solving a non-stiff differential equation numerically The adaptive Runge-Kutta method of the pair of orders 1 and 2 is the simplest member in that family Therefore, it has a smallest number of calculations comparing with other method in the family It is worth to translate the algorithm of this method into one that is easy
to execute by a process of high performance computing This promises to increase much more the efficiency of the method
REFERENCES
1 John C Butcher (2008), Numerical Methods for Ordinary Differential Equations, 2nd Edition, John Wiley & Sons, Ltd
2 Richard L Burden, J Douglas Faires (2010),
Numerical Analysis, 9th Edition, Brooks/Cole
3 Michiel Hazewinkel, (2001), “Runge-Kutta method”, https://www.encyclopediaofmath.org/ind ex.php/Runge-Kutta_method
Trang 4Table 2 Approximations values for Example
𝑥 𝑖 𝑦(𝑥 𝑖 ) ℎ 𝑖 𝑤 𝑖 by Euler
method
Absolute Error
|𝑦(𝑥𝑖) − 𝑤𝑖|
𝑤𝑖∗ by Modified Euler method
Estimate 𝑅 𝑖 of
𝜏 𝑖+1 (ℎ) 0.0000 0.500000000 0.250000000 0.500000000 0.000000000 0.500000000 0.000000000 0.0538 0.582794479 0.053760000 0.580640000 0.002154479 0.663369916 0.038874931 0.1002 0.657785768 0.046465317 0.653950647 0.003835121 0.728798267 0.033077835 0.1474 0.737159458 0.047198815 0.731541041 0.005618417 0.810686675 0.032950817 0.1956 0.821355070 0.048128707 0.813831849 0.007523220 0.897705702 0.032891885 0.2447 0.910691785 0.049164849 0.901128510 0.009563276 0.990039026 0.032825413 0.2950 1.005543717 0.050325000 0.993789002 0.011754715 1.088097564 0.032748526 0.3467 1.106357364 0.051633470 1.092240543 0.014116821 1.192378366 0.032658685 0.3998 1.213672443 0.053121691 1.196999503 0.016672940 1.303487706 0.032552499 0.4546 1.328151023 0.054831085 1.308699260 0.019451763 1.422176932 0.032425305 0.5114 1.450619466 0.056817490 1.428130294 0.022489172 1.549394859 0.032270529 0.5706 1.582130720 0.059158240 1.556299747 0.025830973 1.686366914 0.032078608 0.6326 1.724060435 0.061963938 1.694523328 0.029537107 1.834719537 0.031835113 0.6980 1.878262202 0.065399118 1.844573775 0.033688427 1.996685423 0.031517273 0.7677 2.047332893 0.069720829 2.008934690 0.038398203 2.175463022 0.031087073 0.8430 2.235100017 0.075356719 2.191266978 0.043833039 2.375895862 0.030476336 0.9261 2.447605733 0.083080387 2.397351338 0.050254395 2.605890763 0.029550478 1.0206 2.695371328 0.094465512 2.637259976 0.058111352 2.879814170 0.028005519 1.1339 2.999727117 0.113336275 2.931441691 0.068285426 3.228456621 0.024998301 1.2863 3.417376961 0.152334306 3.334464986 0.082911975 3.740104276 0.017172727 1.5000 4.009155465 0.213738253 3.907282585 0.101872880 4.477672852 0.011356559
TÓM TẮT
MỘT THUẬT TOÁN VÀ CHƯƠNG TRÌNH THỰC THI
CHO MỘT PHƯƠNG PHÁP RUNG-KUTTA THÍCH NGHI VỚI CẶP BẬC 1 VÀ 2
Phạm Thị Minh Hạnh *
Trường Đại học Kỹ thuật Công nghiệp - ĐH Thái Nguyên
Các phương pháp Runge-Kutta thích nghi rất khả dụng trong việc xấp xỉ nghiệm của bài toán phương trình vi phân với giá trị ban đầu bởi tính hiệu quả nó mang lại Bài báo này giới thiệu một phương pháp Runge-Kutta với sự kết hợp của hai phương pháp Euler (có bậc 1) và Euler cải tiến (có bậc 2) để ước lượng sai số tạo ra bởi phương pháp Euler, và dựa vào ước lượng đó để xác định
độ lớn bước cho điểm lưới tiếp theo Bài báo cũng giới thiệu thuật toán, cách thức thuật toán hoạt động, cũng như lập trình chương trình bằng Matlab cho thuật toán
Từ khóa: bài toán giá trị ban đầu, phương pháp Runge-Kutta, phương pháp Euler, phương pháp
Runge-Kutta thích nghị, điều khiển sai số
Ngày nhận bài: 27/8/2018; Ngày phản biện: 16/9/2018; Ngày duyệt đăng: 12/10/2018
*Tel: 0977 791201, Email: phamminhhanh86@gmail.com