Lecture Notes in Differential Equations - Bruce E. Shapiro

Lecture Notes in Differential Equations - Bruce E. Shapiro Lecture Notes in Differential Equations - Bruce E. Shapiro

bruce.shapiro.com
from bruce.shapiro.com More from this publisher
21.04.2015 Views

370 LESSON 33. NUMERICAL METHODS Heun’s Method is y n = y n−1 + h n 4 [ f(t n−1 , y n−1 ) + 3f ( t n−1 + 2 3 h, y n−1 + 2 )] 3 hf(t n−1, y n−1 ) (33.67) Both Heun’s method and the modified Euler method are second order and are examples of two-step Runge-Kutta methods. It is clearer to implement these in two “stages,” eg., for the modified Euler method, while for Heun’s method, ỹ n = y n−1 + hf(t n−1 , y n−1 ) (33.68) y n = y n−1 + h n 2 [f(t n−1, y n−1 ) + f(t n , ỹ n )] (33.69) ỹ n = y n−1 + 2 3 hf(t n−1, y n−1 ) (33.70) y n = y n−1 + h [ ( n f(t n−1 , y n−1 ) + 3f t n−1 + 2 )] 4 3 h, ỹ n (33.71) Runge-Kutta Fourth Order Method. This is the “gold standard” of numerical methods - its a lot higher order than Euler but still really easy to implement. Other higher order methods tend to be very tedious – even to code – although once coded they can be very useful. Four intermediate calculations are performed at each step: Then the subsequent iteration is given by k 1 = hf(t n , y n ) (33.72) k 2 = hf(t n + .5h, y n + .5k 1 ) (33.73) k 3 = hf(t n + .5h, y n + .5k 2 ) (33.74) k 4 = hf(t n + h, y n + k 3 ) (33.75) y n+1 = y n + 1 6 (k 1 + 2k 2 + 2k 3 + k 4 ) (33.76) Example 33.2. Compute the solution to the test equation y ′ = y, y(0) = 1 on [0, 1] using the 4-stage Runge Kutta method with h = 1/2. Since we start at t = 0 and need to compute through t = 1 we have to compute two iterations of RK. For the first iteration, k 1 = y 0 = 1 (33.77)

371 k 2 = y 0 + h 2 f(t 0, k 1 ) (33.78) = 1 + (0.25)(1) (33.79) = 1.25 (33.80) k 3 = y 0 + h 2 f(t 1/2, k 2 ) (33.81) = 1 + (0.25)(1.25) (33.82) = 1.3125 (33.83) k 4 = y 0 + hf(t 1/2 , k 3 ) (33.84) = 1 + (0.5)(1.3125) (33.85) = 1.65625 (33.86) y 1 = y 0 + h 6 (f(t 0, k 1 ) + 2f(t 1/2 , k 2 ) + 2f(t 1/2 , k 3 ) + f(t 1 , k 4 )) (33.87) = y 0 + h 6 (k 1 + 2k 2 + 2k 3 + k 4 ) (33.88) = 1 + .5 1 + 2(1.25) + 2(1.3125) + 1.65625 6 (33.89) = 1.64844 (33.90) Thus the numerical approximation to y(0.5) is y 1 ≈ 1.64844. For the second step, k 1 = y 1 = 1.64844 (33.91) k 2 = y 1 + h 2 f(t 1, k 1 ) (33.92) = 1.64844 + (0.25)(1.64844) (33.93) = 2.06055 (33.94) k 3 = y 1 + h 2 f(t 1.5, k 2 ) (33.95) = 1.64844 + (0.25)(2.06055) (33.96) = 2.16358 (33.97)

371<br />

k 2 = y 0 + h 2 f(t 0, k 1 ) (33.78)<br />

= 1 + (0.25)(1) (33.79)<br />

= 1.25 (33.80)<br />

k 3 = y 0 + h 2 f(t 1/2, k 2 ) (33.81)<br />

= 1 + (0.25)(1.25) (33.82)<br />

= 1.3125 (33.83)<br />

k 4 = y 0 + hf(t 1/2 , k 3 ) (33.84)<br />

= 1 + (0.5)(1.3125) (33.85)<br />

= 1.65625 (33.86)<br />

y 1 = y 0 + h 6 (f(t 0, k 1 ) + 2f(t 1/2 , k 2 ) + 2f(t 1/2 , k 3 ) + f(t 1 , k 4 )) (33.87)<br />

= y 0 + h 6 (k 1 + 2k 2 + 2k 3 + k 4 ) (33.88)<br />

= 1 + .5 1 + 2(1.25) + 2(1.3125) + 1.65625<br />

6<br />

(33.89)<br />

= 1.64844 (33.90)<br />

Thus the numerical approximation to y(0.5) is y 1 ≈ 1.64844. For the second<br />

step,<br />

k 1 = y 1 = 1.64844 (33.91)<br />

k 2 = y 1 + h 2 f(t 1, k 1 ) (33.92)<br />

= 1.64844 + (0.25)(1.64844) (33.93)<br />

= 2.06055 (33.94)<br />

k 3 = y 1 + h 2 f(t 1.5, k 2 ) (33.95)<br />

= 1.64844 + (0.25)(2.06055) (33.96)<br />

= 2.16358 (33.97)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!