Question 7.6: CLASSICAL RK4 METHOD Consider the initial-value problem in E...
CLASSICAL RK4 METHOD
Consider the initial-value problem in Examples 7.4 and 7.5:
y′ – x²y = 2x², y(0) = 1, 0 ≤ x ≤ 1, h = 0.1
1. Using hand calculations, compute the estimated value of y_1 = y(0.1) by the classical RK4 method.
2. Solve the initial-value problem by executing the user-defined function RK4.
Learn more on how do we answer questions.
1. Noting that f(x, y) = x²(2 + y), the calculations are carried out as follows:
k_1=f(x_0,y_0)=f(0,1)=0
k_2=f(x_0+\frac{1}{2} h,y_0+\frac{1}{2}k_1h) =f(0.05,1)=0.0075
k_3=f(x_0+\frac{1}{2}h,y_0+\frac{1}{2}k_2h )=f(0.05,1.0004)=0.0075
k_4=f(x_0+ h,y_0+k_3h) =f(0.1,1.0008)=0.0300
y_1=y_0+\frac{1}{6}h(k_1+2k_2+2k_3+k_4)=\boxed{1.0010}2.
>> f = @(x,y)((x^2)*(2+y));
>> x = 0:0.1:1;
>> y0 = 1;
>> y = RK4(f,x,y0); y = y'
y =
1.0000
1.0010
1.0080
1.0271
1.0647
1.1276
1.2240
1.3634
1.5583
1.8252
2.1868
A summary of all calculations is provided in Table 7.3 where it is easily seen that the global % relative error for the classical RK4 method is significantly lower than all previous methods used up to this point. As expected, starting with Euler’s method, which is indeed a first-order Runge–Kutta method, the accuracy improves with the order of the RK method.
TABLE 7.3 | |||||
Summary of Calculations in Example 7.6 | |||||
x | y_{\text{RK4}} | RK4
e_{\text{RK4}} |
RK3
e_{\text{RK3}} |
RK2
e_{\text{Heun}} |
RK1
e_{\text{Euler}} |
0.0 | 1.000000 | 0.000000 | 0.0000 | 0.00 | 0.00 |
0.1 | 1.001000 | 0.000001 | -0.0000 | -0.05 | 0.10 |
0.2 | 1.008011 | 0.000002 | -0.0001 | -0.10 | 0.50 |
0.3 | 1.027122 | 0.000003 | -0.0004 | -0.15 | 1.18 |
0.4 | 1.064688 | 0.000004 | -0.0010 | -0.19 | 2.12 |
0.5 | 1.127641 | 0.000005 | -0.0018 | -0.23 | 3.27 |
0.6 | 1.223966 | 0.000006 | -0.0030 | -0.25 | 4.56 |
0.7 | 1.363377 | 0.000007 | -0.0044 | -0.27 | 5.96 |
0.8 | 1.558286 | 0.000010 | -0.0059 | -0.28 | 7.40 |
0.9 | 1.825206 | 0.000016 | -0.0074 | -0.27 | 8.87 |
1.0 | 2.186837 | 0.000028 | -0.0087 | -0.25 | 10.37 |