## Solving a Second Order Ordinary Differential Equation by the Shooting Method and the RK Method

Using the Runge-Kutta method should produce much smaller errors than does Euler's method. Figure 11-8 shows the application of the RK method to the preceding problem, the solution of the differential equation y" - y = 0. Four columns, B:F, were inserted and labeled TZ1...TZ4, for the four RK terms used to calculate z. Similarly, four columns were inserted for the calculation of y. As in Figure 11-7, the values in bold are the two boundary values (in cells G6 and L6) and the target value (cell L34). Columns B through G contain the series of

 A B D E F G H I J K L M N 5 x dz/dx=y TZ1 122 TZ3 TZ4 z=dy/dx TY1 TY2 TY3 TY4 y y(exact) % error 6 0.0 0.0000 0.997 0.0000 0.0000 7 0.1 0.1049 0.000 0.000 0.000 0000 0.997 0.100 0.105 0.105 0.110 0.1049 0.1002 4.7 8 0.2 0.2097 0.010 0.011 0.011 0.012 1.008 0.100 0.105 0.105 0.110 0.2097 0.2013 4.2 9 0.3 0.3158 0.021 0.022 0.022 0.023 1.030 0.101 0.106 0.106 0.111 0.3158 0.3045 3.7 10 0.4 0 4241 0 032 0.033 0 033 0.035 1.063 0.103 0.108 0.1G8 0.114 0.4241 0.4108 3.3 11 0.5 0.5360 0.042 0.045 0.045 0.047 1.108 0.106 0.112 0.112 0.118 0.5360 0.5211 2.9 12 0.6 0.6525 0.054 0.056 0.056 0.059 1.164 0.111 0.116 0.117 0.122 0.6525 0.6367 2.5 13 0,7 0.7750 0.065 0.069 0.069 0.072 1.233 0.116 0.122 0.123 0.129 0.7750 0.7586 2.2 14 0.8 0.9047 0.077 0.081 0.082 0.086 1.315 0.123 0.129 0.130 0136 0.9047 0.8881 1.9 15 0.9 1.0429 0.090 0.095 0.095 0.100 1.410 0.131 0.138 0.138 0.145 1.0429 1.0265 1.6 16 1.0 1.1912 0.104 0.110 0.110 0.115 1.519 0.141 0.152 0.148 0.148 0.156 1.1912 1.1752 1.4 17 1.1 1.3510 0.119 0.125 0,125 0.132 0.149 0.168 1.645 0.160 0.1 B0 0.168 1.3510 1.3356 1.1 18 1.2 1.5239 0.135 0.142 0.142 1.787 0.164 0.173 0.173 0.182 0.197 1.5239 1.5095 1.0 19 1.3 1.7118 0.152 0.160 0.160 1,947 0.179 0.188 0.188 1.7118 1.6984 0.8 20 1.4 1.9166 0.171 0.180 0.180 0.189 2.127 0.195 0.204 0.205 0.215 1.9166 1.9043 0.6 21 1.5 2.1403 0.192 0.201 0,202 0.212 2.329 0.213 0.223 0.224 0.235 2.1403 2.1293 0.5 22 1.6 2.3852 0.214 0.225 0.225 0.237 2.554 0.233 0.245 0.245 0.257 2.3852 2.3756 0.4 23 1.7 2.6538 0.239 0.250 0.251 0.264 2.805 0.255 0.268 0.269 0 282 2.6538 2 6456 0.3 24 1.8 2.9488 0.265 0.279 0.279 0.293 3.084 0.280 0.294 0.295 0.310 2.9488 2.9422 0.2 25 1.9 3.2731 0.295 0.310 0.310 0.326 3 394 0.308 0.324 0,325 0.341 3.2731 3.2682 0.2 26 2.0 3.6300 0.327 0.344 0.344 0.362 3.738 0.339 0.356 0.357 0.375 3.6300 3,6269 0.1

Figure 11-8. Final values for the solution of the differential equation y-y = 0

by the shooting method, using the RK method to calculate / and y. (folder 'Chapter 11 Examples', workbook 'ODE-BVP', worksheet 'y"-y=0 (RK)')

RK formulas to calculate z, columns H through M a similar series to calculate y. The RK formulas in cells C7 through G7 are, respectively

As expected, application of the RK method reduces the errors significantly. The results from the more precise calculation are shown in Figure 11-9. Every fifth data point has been plotted.

Even better accuracy can be obtained by using the RK method with a smaller Ax. When a Ax value of 0.01 is used instead of 0.1, the maximum error is 0.25% Figure 11-9. Solution of the differential equation y" -y = 0 by the shooting method, using the RK method to calculate y' and y. Maximum error is ca. 1%. (folder 'Chapter 11 Examples', workbook 'ODE-BVP', worksheet 'y"-y=0 (RK)')

Figure 11-9. Solution of the differential equation y" -y = 0 by the shooting method, using the RK method to calculate y' and y. Maximum error is ca. 1%. (folder 'Chapter 11 Examples', workbook 'ODE-BVP', worksheet 'y"-y=0 (RK)')