mirror of
https://github.com/apache/commons-math.git
synced 2025-02-06 10:09:26 +00:00
Fixed bracketing interval balancing in BracketingNthOrderBrentSolver.
Jira: MATH-716 git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1209307 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b241c3962f
commit
faa7785779
@ -232,10 +232,16 @@ public class BracketingNthOrderBrentSolver
|
||||
double targetY;
|
||||
if (agingA >= MAXIMAL_AGING) {
|
||||
// we keep updating the high bracket, try to compensate this
|
||||
targetY = -REDUCTION_FACTOR * yB;
|
||||
final int p = agingA - MAXIMAL_AGING;
|
||||
final double weightA = (1 << p) - 1;
|
||||
final double weightB = p + 1;
|
||||
targetY = (weightA * yA - weightB * REDUCTION_FACTOR * yB) / (weightA + weightB);
|
||||
} else if (agingB >= MAXIMAL_AGING) {
|
||||
// we keep updating the low bracket, try to compensate this
|
||||
targetY = -REDUCTION_FACTOR * yA;
|
||||
final int p = agingB - MAXIMAL_AGING;
|
||||
final double weightA = p + 1;
|
||||
final double weightB = (1 << p) - 1;
|
||||
targetY = (weightB * yB - weightA * REDUCTION_FACTOR * yA) / (weightA + weightB);
|
||||
} else {
|
||||
// bracketing is balanced, try to find the root itself
|
||||
targetY = 0;
|
||||
|
@ -52,6 +52,9 @@ The <action> type attribute can be add,update,fix,remove.
|
||||
If the output is not quite correct, check for invisible trailing spaces!
|
||||
-->
|
||||
<release version="3.0" date="TBD" description="TBD">
|
||||
<action dev="luc" type="fix" issue="MATH-716">
|
||||
Fixed bracketing interval balancing in BracketingNthOrderBrentSolver.
|
||||
</action>
|
||||
<action dev="erans" type="fix" issue="MATH-690">
|
||||
Removed unused or duplicate utility methods from "MathUtils".
|
||||
Math functions with "double" arguments were moved to class "FastMath".
|
||||
|
@ -41,7 +41,7 @@ public final class BracketingNthOrderBrentSolverTest extends BaseSecantSolverAbs
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
protected int[] getQuinticEvalCounts() {
|
||||
return new int[] {1, 3, 8, 1, 9, 4, 8, 1, 12, 1, 14};
|
||||
return new int[] {1, 3, 8, 1, 9, 4, 8, 1, 12, 1, 16};
|
||||
}
|
||||
|
||||
@Test(expected=NumberIsTooSmallException.class)
|
||||
@ -81,6 +81,21 @@ public final class BracketingNthOrderBrentSolverTest extends BaseSecantSolverAbs
|
||||
Assert.assertTrue(result + 0.5 < -solver.getAbsoluteAccuracy());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIssue716() {
|
||||
BracketingNthOrderBrentSolver solver =
|
||||
new BracketingNthOrderBrentSolver(1.0e-12, 1.0e-10, 1.0e-22, 5);
|
||||
UnivariateFunction sharpTurn = new UnivariateFunction() {
|
||||
public double value(double x) {
|
||||
return (2 * x + 1) / (1.0e9 * (x + 1));
|
||||
}
|
||||
};
|
||||
double result = solver.solve(100, sharpTurn, -0.9999999, 30, 15, AllowedSolution.RIGHT_SIDE);
|
||||
Assert.assertEquals(0, sharpTurn.value(result), solver.getFunctionValueAccuracy());
|
||||
Assert.assertTrue(sharpTurn.value(result) >= 0);
|
||||
Assert.assertEquals(-0.5, result, 1.0e-10);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFasterThanNewton() {
|
||||
// the following test functions come from Beny Neta's paper:
|
||||
|
Loading…
x
Reference in New Issue
Block a user