fixed an Adams-Moulton order error, it was one unit too large
and inconsistent with the order of the underlying predictor git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@768565 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
5548ffccb2
commit
97bbb9cf25
|
@ -83,7 +83,7 @@ public class AdamsMoultonIntegrator extends MultistepIntegrator {
|
||||||
super(METHOD_NAME, order + 1, new AdamsMoultonStepInterpolator());
|
super(METHOD_NAME, order + 1, new AdamsMoultonStepInterpolator());
|
||||||
|
|
||||||
// compute the integration coefficients
|
// compute the integration coefficients
|
||||||
int[][] bdArray = AdamsBashforthIntegrator.computeBackwardDifferencesArray(order + 1);
|
int[][] bdArray = AdamsBashforthIntegrator.computeBackwardDifferencesArray(order);
|
||||||
|
|
||||||
Fraction[] gamma = AdamsBashforthIntegrator.computeGammaArray(order);
|
Fraction[] gamma = AdamsBashforthIntegrator.computeGammaArray(order);
|
||||||
predictorCoeffs = new double[order];
|
predictorCoeffs = new double[order];
|
||||||
|
@ -97,10 +97,10 @@ public class AdamsMoultonIntegrator extends MultistepIntegrator {
|
||||||
}
|
}
|
||||||
|
|
||||||
Fraction[] gammaStar = computeGammaStarArray(order);
|
Fraction[] gammaStar = computeGammaStarArray(order);
|
||||||
correctorCoeffs = new double[order + 1];
|
correctorCoeffs = new double[order];
|
||||||
for (int i = 0; i <= order; ++i) {
|
for (int i = 0; i < order; ++i) {
|
||||||
Fraction fCorrector = Fraction.ZERO;
|
Fraction fCorrector = Fraction.ZERO;
|
||||||
for (int j = i; j <= order; ++j) {
|
for (int j = i; j < order; ++j) {
|
||||||
Fraction f = new Fraction(bdArray[j][i], 1);
|
Fraction f = new Fraction(bdArray[j][i], 1);
|
||||||
fCorrector = fCorrector.add(gammaStar[j].multiply(f));
|
fCorrector = fCorrector.add(gammaStar[j].multiply(f));
|
||||||
}
|
}
|
||||||
|
@ -272,7 +272,7 @@ public class AdamsMoultonIntegrator extends MultistepIntegrator {
|
||||||
* @param order order of the integration method
|
* @param order order of the integration method
|
||||||
* @return gamma star coefficients array
|
* @return gamma star coefficients array
|
||||||
*/
|
*/
|
||||||
static Fraction[] computeGammaStarArray(final int order) {
|
public static Fraction[] computeGammaStarArray(final int order) {
|
||||||
|
|
||||||
// create the array
|
// create the array
|
||||||
Fraction[] gammaStarArray = new Fraction[order + 1];
|
Fraction[] gammaStarArray = new Fraction[order + 1];
|
||||||
|
|
|
@ -46,25 +46,25 @@ public class AdamsMoultonIntegratorTest
|
||||||
|
|
||||||
public void testCorrectorCoefficients() {
|
public void testCorrectorCoefficients() {
|
||||||
|
|
||||||
double[] coeffs1 = new AdamsMoultonIntegrator(1, 0.01).getCorrectorCoeffs();
|
double[] coeffs1 = new AdamsMoultonIntegrator(2, 0.01).getCorrectorCoeffs();
|
||||||
assertEquals(2, coeffs1.length);
|
assertEquals(2, coeffs1.length);
|
||||||
assertEquals(1.0 / 2.0, coeffs1[0], 1.0e-16);
|
assertEquals(1.0 / 2.0, coeffs1[0], 1.0e-16);
|
||||||
assertEquals(1.0 / 2.0, coeffs1[1], 1.0e-16);
|
assertEquals(1.0 / 2.0, coeffs1[1], 1.0e-16);
|
||||||
|
|
||||||
double[] coeffs2 = new AdamsMoultonIntegrator(2, 0.01).getCorrectorCoeffs();
|
double[] coeffs2 = new AdamsMoultonIntegrator(3, 0.01).getCorrectorCoeffs();
|
||||||
assertEquals(3, coeffs2.length);
|
assertEquals(3, coeffs2.length);
|
||||||
assertEquals( 5.0 / 12.0, coeffs2[0], 1.0e-16);
|
assertEquals( 5.0 / 12.0, coeffs2[0], 1.0e-16);
|
||||||
assertEquals( 8.0 / 12.0, coeffs2[1], 1.0e-16);
|
assertEquals( 8.0 / 12.0, coeffs2[1], 1.0e-16);
|
||||||
assertEquals(-1.0 / 12.0, coeffs2[2], 1.0e-16);
|
assertEquals(-1.0 / 12.0, coeffs2[2], 1.0e-16);
|
||||||
|
|
||||||
double[] coeffs3 = new AdamsMoultonIntegrator(3, 0.01).getCorrectorCoeffs();
|
double[] coeffs3 = new AdamsMoultonIntegrator(4, 0.01).getCorrectorCoeffs();
|
||||||
assertEquals(4, coeffs3.length);
|
assertEquals(4, coeffs3.length);
|
||||||
assertEquals( 9.0 / 24.0, coeffs3[0], 1.0e-16);
|
assertEquals( 9.0 / 24.0, coeffs3[0], 1.0e-16);
|
||||||
assertEquals(19.0 / 24.0, coeffs3[1], 1.0e-16);
|
assertEquals(19.0 / 24.0, coeffs3[1], 1.0e-16);
|
||||||
assertEquals(-5.0 / 24.0, coeffs3[2], 1.0e-16);
|
assertEquals(-5.0 / 24.0, coeffs3[2], 1.0e-16);
|
||||||
assertEquals( 1.0 / 24.0, coeffs3[3], 1.0e-16);
|
assertEquals( 1.0 / 24.0, coeffs3[3], 1.0e-16);
|
||||||
|
|
||||||
double[] coeffs4 = new AdamsMoultonIntegrator(4, 0.01).getCorrectorCoeffs();
|
double[] coeffs4 = new AdamsMoultonIntegrator(5, 0.01).getCorrectorCoeffs();
|
||||||
assertEquals(5, coeffs4.length);
|
assertEquals(5, coeffs4.length);
|
||||||
assertEquals( 251.0 / 720.0, coeffs4[0], 1.0e-16);
|
assertEquals( 251.0 / 720.0, coeffs4[0], 1.0e-16);
|
||||||
assertEquals( 646.0 / 720.0, coeffs4[1], 1.0e-16);
|
assertEquals( 646.0 / 720.0, coeffs4[1], 1.0e-16);
|
||||||
|
@ -72,7 +72,7 @@ public class AdamsMoultonIntegratorTest
|
||||||
assertEquals( 106.0 / 720.0, coeffs4[3], 1.0e-16);
|
assertEquals( 106.0 / 720.0, coeffs4[3], 1.0e-16);
|
||||||
assertEquals( -19.0 / 720.0, coeffs4[4], 1.0e-16);
|
assertEquals( -19.0 / 720.0, coeffs4[4], 1.0e-16);
|
||||||
|
|
||||||
double[] coeffs5 = new AdamsMoultonIntegrator(5, 0.01).getCorrectorCoeffs();
|
double[] coeffs5 = new AdamsMoultonIntegrator(6, 0.01).getCorrectorCoeffs();
|
||||||
assertEquals(6, coeffs5.length);
|
assertEquals(6, coeffs5.length);
|
||||||
assertEquals( 475.0 / 1440.0, coeffs5[0], 1.0e-16);
|
assertEquals( 475.0 / 1440.0, coeffs5[0], 1.0e-16);
|
||||||
assertEquals(1427.0 / 1440.0, coeffs5[1], 1.0e-16);
|
assertEquals(1427.0 / 1440.0, coeffs5[1], 1.0e-16);
|
||||||
|
@ -81,7 +81,7 @@ public class AdamsMoultonIntegratorTest
|
||||||
assertEquals(-173.0 / 1440.0, coeffs5[4], 1.0e-16);
|
assertEquals(-173.0 / 1440.0, coeffs5[4], 1.0e-16);
|
||||||
assertEquals( 27.0 / 1440.0, coeffs5[5], 1.0e-16);
|
assertEquals( 27.0 / 1440.0, coeffs5[5], 1.0e-16);
|
||||||
|
|
||||||
double[] coeffs6 = new AdamsMoultonIntegrator(6, 0.01).getCorrectorCoeffs();
|
double[] coeffs6 = new AdamsMoultonIntegrator(7, 0.01).getCorrectorCoeffs();
|
||||||
assertEquals(7, coeffs6.length);
|
assertEquals(7, coeffs6.length);
|
||||||
assertEquals( 19087.0 / 60480.0, coeffs6[0], 1.0e-16);
|
assertEquals( 19087.0 / 60480.0, coeffs6[0], 1.0e-16);
|
||||||
assertEquals( 65112.0 / 60480.0, coeffs6[1], 1.0e-16);
|
assertEquals( 65112.0 / 60480.0, coeffs6[1], 1.0e-16);
|
||||||
|
@ -91,7 +91,7 @@ public class AdamsMoultonIntegratorTest
|
||||||
assertEquals( 6312.0 / 60480.0, coeffs6[5], 1.0e-16);
|
assertEquals( 6312.0 / 60480.0, coeffs6[5], 1.0e-16);
|
||||||
assertEquals( -863.0 / 60480.0, coeffs6[6], 1.0e-16);
|
assertEquals( -863.0 / 60480.0, coeffs6[6], 1.0e-16);
|
||||||
|
|
||||||
double[] coeffs7 = new AdamsMoultonIntegrator(7, 0.01).getCorrectorCoeffs();
|
double[] coeffs7 = new AdamsMoultonIntegrator(8, 0.01).getCorrectorCoeffs();
|
||||||
assertEquals(8, coeffs7.length);
|
assertEquals(8, coeffs7.length);
|
||||||
assertEquals( 36799.0 / 120960.0, coeffs7[0], 1.0e-16);
|
assertEquals( 36799.0 / 120960.0, coeffs7[0], 1.0e-16);
|
||||||
assertEquals( 139849.0 / 120960.0, coeffs7[1], 1.0e-16);
|
assertEquals( 139849.0 / 120960.0, coeffs7[1], 1.0e-16);
|
||||||
|
@ -102,7 +102,7 @@ public class AdamsMoultonIntegratorTest
|
||||||
assertEquals( -11351.0 / 120960.0, coeffs7[6], 1.0e-16);
|
assertEquals( -11351.0 / 120960.0, coeffs7[6], 1.0e-16);
|
||||||
assertEquals( 1375.0 / 120960.0, coeffs7[7], 1.0e-16);
|
assertEquals( 1375.0 / 120960.0, coeffs7[7], 1.0e-16);
|
||||||
|
|
||||||
double[] coeffs8 = new AdamsMoultonIntegrator(8, 0.01).getCorrectorCoeffs();
|
double[] coeffs8 = new AdamsMoultonIntegrator(9, 0.01).getCorrectorCoeffs();
|
||||||
assertEquals(9, coeffs8.length);
|
assertEquals(9, coeffs8.length);
|
||||||
assertEquals( 1070017.0 / 3628800.0, coeffs8[0], 1.0e-16);
|
assertEquals( 1070017.0 / 3628800.0, coeffs8[0], 1.0e-16);
|
||||||
assertEquals( 4467094.0 / 3628800.0, coeffs8[1], 1.0e-16);
|
assertEquals( 4467094.0 / 3628800.0, coeffs8[1], 1.0e-16);
|
||||||
|
@ -183,9 +183,9 @@ public class AdamsMoultonIntegratorTest
|
||||||
pb.getInitialTime(), pb.getInitialState(),
|
pb.getInitialTime(), pb.getInitialState(),
|
||||||
pb.getFinalTime(), new double[pb.getDimension()]);
|
pb.getFinalTime(), new double[pb.getDimension()]);
|
||||||
|
|
||||||
assertTrue(handler.getLastError() < 7.0e-12);
|
assertTrue(handler.getLastError() < 3.0e-10);
|
||||||
assertTrue(handler.getMaximalValueError() < 4.0e-11);
|
assertTrue(handler.getMaximalValueError() < 2.0e-9);
|
||||||
assertEquals(0, handler.getMaximalTimeError(), 1.0e-14);
|
assertEquals(0, handler.getMaximalTimeError(), 1.0e-15);
|
||||||
assertEquals("Adams-Moulton", integ.getName());
|
assertEquals("Adams-Moulton", integ.getName());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue