Kevin H. answered 05/09/24
BS Mathematics, MS Mathematics, 5+ years of tutoring experience
For reference, here is the website that I used to refresh myself on this method. It goes through how this algorithm is derived, and gives several more examples in case this one is still confusing.
https://math.libretexts.org/Courses/Monroe_Community_College/MTH_225_Differential_Equations/03%3A_Numerical_Methods/3.02%3A_The_Improved_Euler_Method_and_Related_Methods
The basic idea is to compute a sequence of three numbers, the last of which will be the approximate value of y at that step and which we will use to compute subsequent approximations for y. We will need to repeat this process 5 times for h = 0.1 since 1 + 0.1 * 5 = 1.5, and 10 times for h = 0.05 since 1 + 0.05 * 10 = 1.5.
If we denote y' = f(x,y), y(x0) = y0, h = step size, and i = current location in the algorithm, then we need to compute the following numbers:
k1i = f(xi, yi)
k2i = f(xi + h, yi + h*k1i)
yi+1 = yi + (h/2)*(k1i + k2i)
We're essentially using the average value of the derivative to approximate where the function value will be when x changes by a small amount.
Since we are given y' = f(x,y) = 4x - 2y + 2, y(1) = 6, and we are being asked to approximate y(1.5), then we continue as follows:
For h = 0.1, i = 0, x0 = 1, y0 = 6 we get:
k10 = f(x0, y0) = f(1, 6) = 4(1) - 2(6) + 2 = -6
k20 = f(x0 + h, y0 + h*k10) = f(1 + 0.1, 6 + 0.1*-6) = f(1.1, 5.4) = 4(1.1) - 2(5.4) + 2 = -4.4
x1 = x0 + h = 1 + 0.1 = 1.1
y1 = y0 + (h/2)*(k10 + k20) = 6 + (0.1/2)*(-6 + -4) = 5.48
The calculations for i = 1, 2, 3, and 4 are identical to that of i = 0 except that xi+1 = xi + h and we use yi+1 instead of yi.
For h = 0.1, i = 1, x1 = 1.1, y1 = 5.48, we get:
k11 = f(x1, y1) = -4.56
k21 = f(x1 + h, y1 + h*k11) = -3.248
x2 = x1 + h = 1.2
y2 = y1 + (h/2)*(k11 + k21) = 5.0896
For h = 0.1, i = 2, x2 = 1.2, y2 = 5.0896, we get:
k12 = f(x2, y2) = -3.3792
k22 = f(x2 + h, y2 + h*k12) = -2.30336
x3 = x2 + h = 1.3
y3 = y2 + (h/2)*(k12 + k22) = 4.80547
For h = 0.1, i = 3, x3 = 1.3, y3 = 4.80547, we get:
k13 = f(x3, y3) = -2.41094
k23 = f(x3 + h, y3 + h*k13) = -1.52876
x4 = x3 + h = 1.4
y4 = y3 + (h/2)*(k13 + k23) = 4.60849
For h = 0.1, i = 4, x4 = 1.4, y4 = 4.60849, we get:
k14 = f(x4, y4) = -1.61697
k24 = f(x4 + h, y4 + h*k14) = -0.893579
x5 = x4 + h = 1.5
y5 = y4 + (h/2)*(k14 + k24) = 4.48296
So finally after this last step, we have our desired approximation of y(1.5) ~ 4.48296, or if you are rounding to 4 decimal places it becomes y(1.5) ~ 4.4830.
The calculations for h = 0.05 are the same except you have to do it 10 times to get from x = 1 to x = 1.5. I'll leave the details for you to get some practice with, but here are the resulting numbers:
h = 0.05, i = 0, x0 = 1, y0 = 6, k10 = -6, k20 = -5.2, x1 = 1.05, y1 = 5.72
h = 0.05, i = 1, x1 = 1.05, y1 = 5.72, k11 = -5.24, k21 = -4.516, x2 = 1.1, y2 = 5.4761
h = 0.05, i = 2, x2 = 1.1, y2 = 5.4761, k12 = -4.5522, k22 = -3.89698, x3 = 1.15, y3 = 5.26487
h = 0.05, i = 3, x3 = 1.15, y3 = 5.26487, k13 = -3.92974, k23 = -3.33677, x4 = 1.2, y4 = 5.08321
h = 0.05, i = 4, x4 = 1.2, y4 = 5.08321, k14 = -3.36642, k24 = -2.82977, x5 = 1.25, y5 = 4.9283
h = 0.05, i = 5, x5 = 1.25, y5 = 4.9283, k15 = -2.85661, k25 = -2.37095, x6 = 1.3, y6 = 4.79761
h = 0.05, i = 6, x6 = 1.3, y6 = 4.79761, k16 = -2.39523, k26 = -1.95571, x7 = 1.35, y7 = 4.68884
h = 0.05, i = 7, x7 = 1.35, y7 = 4.68884, k17 = -1.97768, k27 = -1.57991, x8 = 1.4, y8 = 4.5999
h = 0.05, i = 8, x8 = 1.4, y8 = 4.5999, k18 = -1.5998, k28 = -1.23982, x9 = 1.45, y9 = 4.52891
h = 0.05, i = 9, x9 = 1.45, y9 = 4.52891, k19 = -1.25782, k29 = -0.932039, x10 = 1.5, y10 = 4.47416
Thus we find that with h = 0.05, we approximate y(1.5) ~ 4.47416, which when rounded to four decimal places is y(1.5) ~ 4.4742.