MATH-1204 bracket function gives up too early
In UnivariateSolverUtils.bracket(...) the search ends prematurely if a = lowerBound, which ignores some roots in the interval. Fixed by changing the loop condition so the search continues while b < upperBound. Also added a test case.
This commit is contained in:
parent
d746a54c2e
commit
a56d4998cf
|
@ -314,7 +314,7 @@ public class UnivariateSolverUtils {
|
|||
double delta = 0;
|
||||
|
||||
for (int numIterations = 0;
|
||||
(numIterations < maximumIterations) && (a > lowerBound || b > upperBound);
|
||||
(numIterations < maximumIterations) && (a > lowerBound || b < upperBound);
|
||||
++numIterations) {
|
||||
|
||||
final double previousA = a;
|
||||
|
|
|
@ -176,6 +176,14 @@ public class UnivariateSolverUtilsTest {
|
|||
UnivariateSolverUtils.bracket(sin, 1.5, 0, 2.0, 0);
|
||||
}
|
||||
|
||||
/** check the search continues when a = lowerBound and b < upperBound. */
|
||||
@Test
|
||||
public void testBracketLoopConditionForB() {
|
||||
double[] result = UnivariateSolverUtils.bracket(sin, -0.9, -1, 1, 0.1, 1, 100);
|
||||
Assert.assertTrue(result[0] <= 0);
|
||||
Assert.assertTrue(result[1] >= 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMisc() {
|
||||
UnivariateFunction f = new QuinticFunction();
|
||||
|
|
Loading…
Reference in New Issue