Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
1.0
-
None
-
None
-
None
-
Operating System: Windows XP
Platform: PC
-
35042
Description
I'm using the BrentSolver class and I noticed that, when I call the solve()
method, it requests the boundary values of the initial interval twice from my
function. The function is quite expensive so it would be good to avoid these
two duplicate computations.
I had a look at the source code (see below) and I can see that
the 'verifyBracketing' check requests the boundary values from the function and
then the 'solve' method itself also requests those values. It looks like the
SecantSolver will exhibit this behaviour too. Would it be possible to change
the code so that the values are requested just once?
BrentSolver.class
public double solve(double min, double max) throws ConvergenceException,
FunctionEvaluationException {
clearResult();
verifyBracketing(min, max, f);
// Index 0 is the old approximation for the root.
// Index 1 is the last calculated approximation for the root.
// Index 2 is a bracket for the root with respect to x1.
double x0 = min;
double x1 = max;
double y0;
double y1;
y0 = f.value(x0); // ******* REQUESTS BOUNDARY (MIN) VALUE HERE ****
y1 = f.value(x1); // ******* REQUESTS BOUNDARY (MAX) VALUE HERE ****
UnivariateRealSolverImpl.class:
protected void verifyBracketing(double lower, double upper,
UnivariateRealFunction f) throws FunctionEvaluationException {
verifyInterval(lower, upper);
if (!isBracketing(lower, upper, f))
}
protected boolean isBracketing(double lower, double upper,
UnivariateRealFunction f) throws FunctionEvaluationException