[MATH-1204] backport to 3.5 branch.

This commit is contained in:
Thomas Neidhart 2015-02-19 22:23:10 +01:00
parent 68e6de3519
commit 9aa6382673
3 changed files with 15 additions and 3 deletions

View File

@ -54,6 +54,10 @@ If the output is not quite correct, check for invisible trailing spaces!
</release>
<release version="3.5" date="2015-01-11" description="">
<action dev="evanward" type="fix" issue="MATH-1204">
"UnivariateSolverUtils#bracket(...)" sometimes failed to bracket
if a reached the lower bound.
</action>
<action dev="sebb" type="add" issue="MATH-1198">
Simplified "FastMath#exp(double)" in order to avoid a potential
Java 1.5 JIT bug when calling with negative infinity as argument.

View File

@ -243,7 +243,7 @@ public class UnivariateSolverUtils {
* \( \delta_{k+1} = r \delta_k + q, \delta_0 = 0\) and starting search with \( k=1 \).
* The algorithm stops when one of the following happens: <ul>
* <li> at least one positive and one negative value have been found -- success!</li>
* <li> both endpoints have reached their respective limites -- NoBracketingException </li>
* <li> both endpoints have reached their respective limits -- NoBracketingException </li>
* <li> {@code maximumIterations} iterations elapse -- NoBracketingException </li></ul></p>
* <p>
* If different signs are found at first iteration ({@code k=1}), then the returned
@ -257,7 +257,7 @@ public class UnivariateSolverUtils {
* Interval expansion rate is tuned by changing the recurrence parameters {@code r} and
* {@code q}. When the multiplicative factor {@code r} is set to 1, the sequence is a
* simple arithmetic sequence with linear increase. When the multiplicative factor {@code r}
* is larger than 1, the sequence has an asymtotically exponential rate. Note than the
* is larger than 1, the sequence has an asymptotically exponential rate. Note than the
* additive parameter {@code q} should never be set to zero, otherwise the interval would
* degenerate to the single initial point for all values of {@code k}.
* </p>
@ -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;

View File

@ -175,6 +175,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();