Fortran Program For Runge Kutta Method

  1. How To Code Rk4
  2. First Order Runge Kutta Method

ExamplesExample 1Given the IVP y (1)( t) = 1 - t y( t) withy(0) = 1, approximate y(1) with one step.First, let t 0 = 0, y 0 = 1, and h = 1.Thus, we calculateK 0 = f(0, 1) = 1K 1 = f(0.5, 1.5) = 0.25K 2 = f(0.5, 1.125) = 0.4375K 3 = f(1, 1.4375) = -0.4375( K 0 + 2 K 1 + 2 K 2 + K 3)/6 = 0.Therefore, approximation is y 1 = y 0 + h 0. The actual value is 1.331309118 andtherefore the absolute error is approximately 0.0084, significantly smaller than the errorusing Heun's method. Example 2Given the same IVP shown in Example 1, approximatey(0.5).K 0 = f(0, 1) = 1K 1 = f(0.25, 1.25) = 0.6875K 2 = f(0.25, 1.171875) = 0.70703125K 3 = f(0.5, 1.353515625) = 0.( K 0 + 2 K 1 + 2 K 2 + K 3)/6 = 0.Therefore, approximation is y 1 = y 0 + h = 1 + 0.5⋅0. = 1.342692057.

How To Code Rk4

Fortran Program For Runge Kutta Method

The actual value is 1.342841185 andtherefore the absolute error is approximately 0.00015, or approximately 1/56th the errorwhen we used h = 1. This is significantly better than the estimated 1/32. Example 3Repeat Examples 1 and 2 but with with the initial valuey(0.5) = 2.5 and approximating y(1.5) and y(1.0).First, let t 0 = 0.5, y 0 = 2.5, and h = 1. ThereforeK 0 = f(0.5, 2.5) = -0.25K 1 = f(1, 2.375) = -1.375K 2 = f(1, 1.8125) = -0.8125K 3 = f(0.5, 1.6875) = -0.153125( K 0 + 2 K 1 + 2 K 2 + K 3)/6 = -1.026041667Therefore, our approximation is y 1 = y 0 + h(-1.026041667) = 1.473958333. The actual value is 1.502483616 andtherefore the absolute error is approximately 0.0285.Next, let t 0 = 0.5, y 0 = 2.5, and h = 0.5. ThereforeK 0 = f(0.5, 2.5) = -0.25K 1 = f(1, 2.4375) = -0.828125K 2 = f(1, 2.29296875) = -0.719726562K 3 = f(0.5, 2.140136719) = -1.140136719( K 0 + 2 K 1 + 2 K 2 + K 3)/6 = -0.Therefore, our approximation is y 1 = y 0 + h(-0.) = 2.126180013. The actual value is 2.126611964 andtherefore the absolute error is approximately 0.00043.

Fortran program for runge kutta method example

First Order Runge Kutta Method

Again, the erroris approximately 1/66th that of the previous calculation where h = 1.If we tabulate the errors for various values of h, as is shownin Table 1, we note that as h gets smaller, the error beginsto drops by a factor 1/32 each time we divide h by two.Table 1. Errors when approximating y( t 0 + h) for decreasing values of h. HApproximationof y(0.5 + h)Error330.028830.280.12530.00062000058You will note that with the last step, the error goes down by approximatelya factor of 1/32.7.Copyright ©2005 by Douglas Wilhelm Harder. All rights reserved.