Fixed wrong return values when enpoints are roots in Brent solver with a user provided initial guess
JIRA: MATH-344 git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@915522 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f6dd42b4fc
commit
a0b4b4b798
|
@ -112,7 +112,7 @@ public class BrentSolver extends UnivariateRealSolverImpl {
|
|||
// return the first endpoint if it is good enough
|
||||
double yMin = f.value(min);
|
||||
if (Math.abs(yMin) <= functionValueAccuracy) {
|
||||
setResult(yMin, 0);
|
||||
setResult(min, 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -124,7 +124,7 @@ public class BrentSolver extends UnivariateRealSolverImpl {
|
|||
// return the second endpoint if it is good enough
|
||||
double yMax = f.value(max);
|
||||
if (Math.abs(yMax) <= functionValueAccuracy) {
|
||||
setResult(yMax, 0);
|
||||
setResult(max, 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -39,6 +39,10 @@ The <action> type attribute can be add,update,fix,remove.
|
|||
</properties>
|
||||
<body>
|
||||
<release version="2.1" date="TBD" description="TBD">
|
||||
<action dev="luc" type="fix" issue="MATH-344" >
|
||||
Fixed wrong return values when enpoints are roots in Brent solver with
|
||||
a user provided initial guess
|
||||
</action>
|
||||
<action dev="luc" type="fix" issue="MATH-343" >
|
||||
Fixed a missing bracketing check of initial interval in Brent solver.
|
||||
</action>
|
||||
|
|
|
@ -308,10 +308,17 @@ public final class BrentSolverTest extends TestCase {
|
|||
|
||||
// endpoint is root
|
||||
double result = solver.solve(f, Math.PI, 4);
|
||||
assertEquals(result, Math.PI, solver.getAbsoluteAccuracy());
|
||||
assertEquals(Math.PI, result, solver.getAbsoluteAccuracy());
|
||||
|
||||
result = solver.solve(f, 3, Math.PI);
|
||||
assertEquals(result, Math.PI, solver.getAbsoluteAccuracy());
|
||||
assertEquals(Math.PI, result, solver.getAbsoluteAccuracy());
|
||||
|
||||
result = solver.solve(f, Math.PI, 4, 3.5);
|
||||
assertEquals(Math.PI, result, solver.getAbsoluteAccuracy());
|
||||
|
||||
result = solver.solve(f, 3, Math.PI, 3.07);
|
||||
assertEquals(Math.PI, result, solver.getAbsoluteAccuracy());
|
||||
|
||||
}
|
||||
|
||||
public void testBadEndpoints() throws Exception {
|
||||
|
|
Loading…
Reference in New Issue