Adam Bashforth predictor corrector method second order differential equation

numerical methodsordinary differential equationsrunge-kutta-methods

I'm trying to numerical solve a 2nd order differential equation, I know the usual way of doing this is using Runge-Kutta's Method. But then I wonder if I could do it with Adam-Bashford and Adam-Bashford predictor-corrector. To my surprise, although theoretically, it is possible to do so, I didn't end up finding any implementation nor straight forward formula, so I wrote this:

# AB
Y[i + 1] = Y[i] + h*(55.0 * U[i] - 59.0 * U[i-1] + 37.0 * U[i-2] - 9.0 * U[i-3])/24.0
U[i + 1] = U[i] + h*(55.0 * dudx(X[i],Y[i],U[i]) - 59.0 * dudx(X[i-1],Y[i-1],U[i-1]) + 37.0 * dudx(X[i-2],Y[i-2],U[i-2]) - 9.0 * dudx(X[i-3],Y[i-3],U[i-1]))/24.0
#AB predictor-corrector
Y[i + 1] = Y[i] + h*(55.0 * U[i] - 59.0 * U[i-1] + 37.0 * U[i-2] - 9.0 * U[i-3])/24.0
U[i + 1] = U[i] + h*(55.0 * dudx(X[i],Y[i],U[i]) - 59.0 * dudx(X[i-1],Y[i-1], U[i-1]) + 37.0 * dudx(X[i-2],Y[i-2], U[i-2]) - 9.0 * dudx(X[i-3],Y[i-3],U[i-3]))/24.0
            
            
Y[i + 1] = Y[i] + h*(9.0 * U[i+1] + 19.0 * U[i] - 5.0 * U[i-1] + U[i-2])/24.0
U[i + 1] = U[i] + h*(9.0 * dudx(X[i+1], Y[i + 1], U[i+1]) + 19.0 * dudx(X[i],Y[i], U[i]) - 5.0 * dudx(X[i-1],Y[i-1], U[i-1]) + dudx(X[i-2],Y[i-2], U[i-2]))/24.0

where $u=\frac{dy}{dx}$ and $dudx=\frac{d^2 y}{dx^2}$. I believed that this would result in a better estimate of the solution. But it seems AB is less accurate than rk4 and ABP-C is just a little better than rk4, Have I done something wrong? If not, Is there any way that someone can explain why this happens?

This is the result I got for the equation:
$$
\left\{\begin{array}{l}
y''+y'-6y=0\\
y(0)=1, y'(0)=2
\end{array}\right.
$$

where $y(x)=e^{2x}$ with this different methods:
enter image description here

Best Answer

There is one error and one non-standard feature in your formulas, and thus apparently also in your computations. In the AB4 formula for the Y component, the last index should be i-3 as the ones directly before it, not i-1. In the repetition as predictor for AM4 you have that correct. In the corrector you are using the freshly computed value for Y[i+1] in the computation of U[i+1]. This will produce a difference to vector-based standard implementations. This is basically the difference between a Gauß-Seidel scheme and a Jacobi scheme. If one were to continue the corrector iteration until numerical convergence, there should be no differences above floating point noise.

To check if you implemented the method correctly, you can compare the errors when dividing the step size by N=2,4,8 etc. You should observe a reduction in error by a factor $16$ in each step. For a more visual confirmation, divide the step size by N=10, 100, etc. Then the number of correct digits should increase by 4 in each step. I computed such tables below, they show that clearly in the columns for N=10. It should be true in general that the columns have about 2, 6 and 10 correct digits after the dot, respectively, RK4 and AM4 partially a little more, AB4 a little less.

Runge-Kutta 4

x N=1 N=10 N=100
0.0 [ 1.000000000000, 2.000000000000] [ 1.000000000000, 2.000000000000] [ 1.000000000000, 2.000000000000]
0.1 [ 1.221400000000, 2.442800000000] [ 1.221402757840, 2.442805515680] [ 1.221402758160, 2.442805516320]
0.2 [ 1.491817960000, 2.983635920000] [ 1.491824696859, 2.983649393718] [ 1.491824697641, 2.983649395282]
0.3 [ 1.822106456344, 3.644212912688] [ 1.822118798957, 3.644237597914] [ 1.822118800390, 3.644237600781]
0.4 [ 2.225520825779, 4.451041651557] [ 2.225540926158, 4.451081852316] [ 2.225540928492, 4.451081856984]
0.5 [ 2.718251136606, 5.436502273212] [ 2.718281824895, 5.436563649789] [ 2.718281828459, 5.436563656917]
0.6 [ 3.320071938250, 6.640143876501] [ 3.320116917512, 6.640233835024] [ 3.320116922736, 6.640233845472]
0.7 [ 4.055135865379, 8.110271730758] [ 4.055199959400, 8.110399918800] [ 4.055199966844, 8.110399933688]
0.8 [ 4.952942945974, 9.905885891948] [ 4.953032414003, 9.906064828007] [ 4.953032424394, 9.906064848788]
0.9 [ 6.049524514213, 12.099049028426] [ 6.049647450134, 12.099294900267] [ 6.049647464411, 12.099294928823]
1.0 [ 7.388889241659, 14.777778483319] [ 7.389056079552, 14.778112159104] [ 7.389056098929, 14.778112197857]

Adams-Bashford 4

x N=1 N=10 N=100
0.0 [ 1.000000000000, 2.000000000000] [ 1.000000000000, 2.000000000000] [ 1.000000000000, 2.000000000000]
0.1 [ 1.221400000000, 2.442800000000] [ 1.221402748820, 2.442805497640] [ 1.221402758159, 2.442805516318]
0.2 [ 1.491817960000, 2.983635920000] [ 1.491824670099, 2.983649340199] [ 1.491824697638, 2.983649395276]
0.3 [ 1.822106456344, 3.644212912688] [ 1.822118747045, 3.644237494090] [ 1.822118800384, 3.644237600769]
0.4 [ 2.225359751835, 4.450719503670] [ 2.225540839268, 4.451081678535] [ 2.225540928483, 4.451081856965]
0.5 [ 2.717819501390, 5.435639002780] [ 2.718281690082, 5.436563380165] [ 2.718281828444, 5.436563656888]
0.6 [ 3.319281371915, 6.638562743829] [ 3.320116717817, 6.640233435634] [ 3.320116922715, 6.640233845429]
0.7 [ 4.053852018449, 8.107704036897] [ 4.055199672699, 8.110399345399] [ 4.055199966813, 8.110399933626]
0.8 [ 4.950979883921, 9.901959767841] [ 4.953032011560, 9.906064023120] [ 4.953032424351, 9.906064848702]
0.9 [ 6.046643715383, 12.093287430766] [ 6.049646894750, 12.099293789499] [ 6.049647464353, 12.099294928705]
1.0 [ 7.384781911467, 14.769563822935] [ 7.389055323232, 14.778110646464] [ 7.389056098849, 14.778112197697]

Adams-Moulton 4-1

x N=1 N=10 N=100
0.0 [ 1.000000000000, 2.000000000000] [ 1.000000000000, 2.000000000000] [ 1.000000000000, 2.000000000000]
0.1 [ 1.221400000000, 2.442800000000] [ 1.221402758700, 2.442805517401] [ 1.221402758160, 2.442805516321]
0.2 [ 1.491817960000, 2.983635920000] [ 1.491824699412, 2.983649398824] [ 1.491824697642, 2.983649395283]
0.3 [ 1.822106456344, 3.644212912688] [ 1.822118803910, 3.644237607820] [ 1.822118800391, 3.644237600782]
0.4 [ 2.225527878319, 4.451055756639] [ 2.225540934448, 4.451081868896] [ 2.225540928493, 4.451081856986]
0.5 [ 2.718268691144, 5.436537382288] [ 2.718281837757, 5.436563675514] [ 2.718281828460, 5.436563656920]
0.6 [ 3.320104159474, 6.640208318947] [ 3.320116936565, 6.640233873130] [ 3.320116922738, 6.640233845476]
0.7 [ 4.055188406071, 8.110376812142] [ 4.055199986754, 8.110399973508] [ 4.055199966847, 8.110399933694]
0.8 [ 4.953023229681, 9.906046459362] [ 4.953032452400, 9.906064904800] [ 4.953032424398, 9.906064848797]
0.9 [ 6.049642249362, 12.099284498725] [ 6.049647503123, 12.099295006245] [ 6.049647464417, 12.099294928835]
1.0 [ 7.389057076415, 14.778114152830] [ 7.389056151712, 14.778112303424] [ 7.389056098937, 14.778112197874]
Related Question