Author: luc
Date: Sun Jan 18 11:48:52 2009
New Revision: 735530
URL: http://svn.apache.org/viewvc?rev=735530&view=rev
Log:
trying to recover history for solvers
Added:
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/BisectionSolver.java
(contents, props changed)
- copied, changed from r735448,
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/BisectionSolver.java
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/BrentSolver.java
(contents, props changed)
- copied, changed from r735448,
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/BrentSolver.java
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/LaguerreSolver.java
(contents, props changed)
- copied, changed from r735448,
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/LaguerreSolver.java
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/MullerSolver.java
(contents, props changed)
- copied, changed from r735448,
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/MullerSolver.java
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/NewtonSolver.java
(contents, props changed)
- copied, changed from r735448,
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/NewtonSolver.java
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/RiddersSolver.java
(contents, props changed)
- copied, changed from r735448,
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/RiddersSolver.java
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/SecantSolver.java
(contents, props changed)
- copied, changed from r735448,
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/SecantSolver.java
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolver.java
(contents, props changed)
- copied, changed from r735448,
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/UnivariateRealSolver.java
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverFactory.java
(contents, props changed)
- copied, changed from r735448,
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/UnivariateRealSolverFactory.java
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverFactoryImpl.java
(contents, props changed)
- copied, changed from r735448,
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/UnivariateRealSolverFactoryImpl.java
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverImpl.java
(contents, props changed)
- copied, changed from r735448,
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/UnivariateRealSolverImpl.java
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverUtils.java
(contents, props changed)
- copied, changed from r735448,
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/UnivariateRealSolverUtils.java
Copied:
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/BisectionSolver.java
(from r735448,
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/BisectionSolver.java)
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/BisectionSolver.java?p2=commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/BisectionSolver.java&p1=commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/BisectionSolver.java&r1=735448&r2=735530&rev=735530&view=diff
==============================================================================
---
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/BisectionSolver.java
(original)
+++
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/BisectionSolver.java
Sun Jan 18 11:48:52 2009
@@ -14,10 +14,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.math.analysis;
+package org.apache.commons.math.analysis.solvers;
import org.apache.commons.math.FunctionEvaluationException;
import org.apache.commons.math.MaxIterationsExceededException;
+import org.apache.commons.math.analysis.UnivariateRealFunction;
/**
* Implements the <a href="http://mathworld.wolfram.com/Bisection.html">
Propchange:
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/BisectionSolver.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/BisectionSolver.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange:
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/BisectionSolver.java
------------------------------------------------------------------------------
svn:mergeinfo =
Propchange:
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/BisectionSolver.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Copied:
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/BrentSolver.java
(from r735448,
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/BrentSolver.java)
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/BrentSolver.java?p2=commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/BrentSolver.java&p1=commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/BrentSolver.java&r1=735448&r2=735530&rev=735530&view=diff
==============================================================================
---
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/BrentSolver.java
(original)
+++
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/BrentSolver.java
Sun Jan 18 11:48:52 2009
@@ -14,11 +14,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.math.analysis;
+package org.apache.commons.math.analysis.solvers;
import org.apache.commons.math.FunctionEvaluationException;
+import org.apache.commons.math.MathRuntimeException;
import org.apache.commons.math.MaxIterationsExceededException;
+import org.apache.commons.math.analysis.UnivariateRealFunction;
/**
* Implements the <a href="http://mathworld.wolfram.com/BrentsMethod.html">
@@ -92,11 +94,8 @@
final double min, final double max, final double
initial)
throws MaxIterationsExceededException, FunctionEvaluationException {
- if (((initial - min) * (max -initial)) < 0) {
- throw new IllegalArgumentException("Initial guess is not in
search" +
- " interval." + " Initial: " + initial +
- " Endpoints: [" + min + "," + max + "]");
- }
+ clearResult();
+ verifySequence(min, initial, max);
// return the initial guess if it is good enough
double yInitial = f.value(initial);
@@ -176,10 +175,10 @@
ret = max;
} else {
// neither value is close to zero and min and max do not
bracket root.
- throw new IllegalArgumentException
- ("Function values at endpoints do not have different signs." +
- " Endpoints: [" + min + "," + max + "]" +
- " Values: [" + yMin + "," + yMax + "]");
+ throw MathRuntimeException.createIllegalArgumentException(
+ "function values at endpoints do not have different
signs. " +
+ "Endpoints: [{0}, {1}], Values: [{2}, {3}]",
+ new Object[] { min, max, yMin, yMax });
}
} else if (sign < 0){
// solve using only the first endpoint as initial guess
Propchange:
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/BrentSolver.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/BrentSolver.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange:
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/BrentSolver.java
------------------------------------------------------------------------------
svn:mergeinfo =
Propchange:
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/BrentSolver.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Copied:
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/LaguerreSolver.java
(from r735448,
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/LaguerreSolver.java)
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/LaguerreSolver.java?p2=commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/LaguerreSolver.java&p1=commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/LaguerreSolver.java&r1=735448&r2=735530&rev=735530&view=diff
==============================================================================
---
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/LaguerreSolver.java
(original)
+++
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/LaguerreSolver.java
Sun Jan 18 11:48:52 2009
@@ -14,12 +14,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.math.analysis;
+package org.apache.commons.math.analysis.solvers;
import org.apache.commons.math.ConvergenceException;
import org.apache.commons.math.FunctionEvaluationException;
import org.apache.commons.math.MathRuntimeException;
import org.apache.commons.math.MaxIterationsExceededException;
+import org.apache.commons.math.analysis.UnivariateRealFunction;
+import org.apache.commons.math.analysis.polynomials.PolynomialFunction;
import org.apache.commons.math.complex.Complex;
/**
Propchange:
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/LaguerreSolver.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/LaguerreSolver.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange:
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/LaguerreSolver.java
------------------------------------------------------------------------------
svn:mergeinfo =
Copied:
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/MullerSolver.java
(from r735448,
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/MullerSolver.java)
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/MullerSolver.java?p2=commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/MullerSolver.java&p1=commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/MullerSolver.java&r1=735448&r2=735530&rev=735530&view=diff
==============================================================================
---
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/MullerSolver.java
(original)
+++
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/MullerSolver.java
Sun Jan 18 11:48:52 2009
@@ -14,11 +14,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.math.analysis;
+package org.apache.commons.math.analysis.solvers;
import org.apache.commons.math.ConvergenceException;
import org.apache.commons.math.FunctionEvaluationException;
import org.apache.commons.math.MaxIterationsExceededException;
+import org.apache.commons.math.analysis.UnivariateRealFunction;
import org.apache.commons.math.util.MathUtils;
/**
Propchange:
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/MullerSolver.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/MullerSolver.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange:
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/MullerSolver.java
------------------------------------------------------------------------------
svn:mergeinfo =
Copied:
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/NewtonSolver.java
(from r735448,
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/NewtonSolver.java)
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/NewtonSolver.java?p2=commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/NewtonSolver.java&p1=commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/NewtonSolver.java&r1=735448&r2=735530&rev=735530&view=diff
==============================================================================
---
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/NewtonSolver.java
(original)
+++
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/NewtonSolver.java
Sun Jan 18 11:48:52 2009
@@ -15,11 +15,13 @@
* limitations under the License.
*/
-package org.apache.commons.math.analysis;
+package org.apache.commons.math.analysis.solvers;
import org.apache.commons.math.FunctionEvaluationException;
import org.apache.commons.math.MathRuntimeException;
import org.apache.commons.math.MaxIterationsExceededException;
+import org.apache.commons.math.analysis.DifferentiableUnivariateRealFunction;
+import org.apache.commons.math.analysis.UnivariateRealFunction;
/**
* Implements <a href="http://mathworld.wolfram.com/NewtonsMethod.html">
Propchange:
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/NewtonSolver.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/NewtonSolver.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange:
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/NewtonSolver.java
------------------------------------------------------------------------------
svn:mergeinfo =
Propchange:
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/NewtonSolver.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Copied:
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/RiddersSolver.java
(from r735448,
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/RiddersSolver.java)
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/RiddersSolver.java?p2=commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/RiddersSolver.java&p1=commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/RiddersSolver.java&r1=735448&r2=735530&rev=735530&view=diff
==============================================================================
---
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/RiddersSolver.java
(original)
+++
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/RiddersSolver.java
Sun Jan 18 11:48:52 2009
@@ -14,11 +14,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.math.analysis;
+package org.apache.commons.math.analysis.solvers;
import org.apache.commons.math.ConvergenceException;
import org.apache.commons.math.FunctionEvaluationException;
import org.apache.commons.math.MaxIterationsExceededException;
+import org.apache.commons.math.analysis.UnivariateRealFunction;
import org.apache.commons.math.util.MathUtils;
/**
Propchange:
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/RiddersSolver.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/RiddersSolver.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange:
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/RiddersSolver.java
------------------------------------------------------------------------------
svn:mergeinfo =
Copied:
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/SecantSolver.java
(from r735448,
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/SecantSolver.java)
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/SecantSolver.java?p2=commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/SecantSolver.java&p1=commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/SecantSolver.java&r1=735448&r2=735530&rev=735530&view=diff
==============================================================================
---
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/SecantSolver.java
(original)
+++
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/SecantSolver.java
Sun Jan 18 11:48:52 2009
@@ -14,13 +14,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.math.analysis;
+package org.apache.commons.math.analysis.solvers;
import java.io.Serializable;
import org.apache.commons.math.ConvergenceException;
import org.apache.commons.math.FunctionEvaluationException;
import org.apache.commons.math.MaxIterationsExceededException;
+import org.apache.commons.math.analysis.UnivariateRealFunction;
/**
Propchange:
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/SecantSolver.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/SecantSolver.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange:
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/SecantSolver.java
------------------------------------------------------------------------------
svn:mergeinfo =
Propchange:
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/SecantSolver.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Copied:
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolver.java
(from r735448,
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/UnivariateRealSolver.java)
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolver.java?p2=commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolver.java&p1=commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/UnivariateRealSolver.java&r1=735448&r2=735530&rev=735530&view=diff
==============================================================================
---
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/UnivariateRealSolver.java
(original)
+++
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolver.java
Sun Jan 18 11:48:52 2009
@@ -14,10 +14,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.math.analysis;
+package org.apache.commons.math.analysis.solvers;
import org.apache.commons.math.ConvergenceException;
+import org.apache.commons.math.ConvergingAlgorithm;
import org.apache.commons.math.FunctionEvaluationException;
+import org.apache.commons.math.analysis.UnivariateRealFunction;
/**
@@ -27,96 +29,7 @@
*
* @version $Revision$ $Date$
*/
-public interface UnivariateRealSolver {
-
- /**
- * Set the upper limit for the number of iterations.
- * <p>
- * Usually a high iteration count indicates convergence problems. However,
- * the "reasonable value" varies widely for different solvers. Users are
- * advised to use the default value supplied by the solver.</p>
- * <p>
- * A <code>ConvergenceException</code> will be thrown if this number
- * is exceeded.</p>
- *
- * @param count maximum number of iterations
- */
- void setMaximalIterationCount(int count);
-
- /**
- * Get the upper limit for the number of iterations.
- *
- * @return the actual upper limit
- */
- int getMaximalIterationCount();
-
- /**
- * Reset the upper limit for the number of iterations to the default.
- * <p>
- * The default value is supplied by the solver implementation.</p>
- *
- * @see #setMaximalIterationCount(int)
- */
- void resetMaximalIterationCount();
-
- /**
- * Set the absolute accuracy.
- * <p>
- * The default is usually choosen so that roots in the interval
- * -10..-0.1 and +0.1..+10 can be found with a reasonable accuracy. If the
- * expected absolute value of your roots is of much smaller magnitude, set
- * this to a smaller value.</p>
- * <p>
- * Solvers are advised to do a plausibility check with the relative
- * accuracy, but clients should not rely on this.</p>
- *
- * @param accuracy the accuracy.
- * @throws IllegalArgumentException if the accuracy can't be achieved by
- * the solver or is otherwise deemed unreasonable.
- */
- void setAbsoluteAccuracy(double accuracy);
-
- /**
- * Get the actual absolute accuracy.
- *
- * @return the accuracy
- */
- double getAbsoluteAccuracy();
-
- /**
- * Reset the absolute accuracy to the default.
- * <p>
- * The default value is provided by the solver implementation.</p>
- */
- void resetAbsoluteAccuracy();
-
- /**
- * Set the relative accuracy.
- * <p>
- * This is used to stop iterations if the absolute accuracy can't be
- * achieved due to large values or short mantissa length.</p>
- * <p>
- * If this should be the primary criterion for convergence rather then a
- * safety measure, set the absolute accuracy to a ridiculously small value,
- * like 1E-1000.</p>
- *
- * @param accuracy the relative accuracy.
- * @throws IllegalArgumentException if the accuracy can't be achieved by
- * the solver or is otherwise deemed unreasonable.
- */
- void setRelativeAccuracy(double accuracy);
-
- /**
- * Get the actual relative accuracy.
- * @return the accuracy
- */
- double getRelativeAccuracy();
-
- /**
- * Reset the relative accuracy to the default.
- * The default value is provided by the solver implementation.
- */
- void resetRelativeAccuracy();
+public interface UnivariateRealSolver extends ConvergingAlgorithm {
/**
* Set the function value accuracy.
@@ -204,7 +117,7 @@
*/
@Deprecated
double solve(double min, double max, double startValue)
- throws ConvergenceException, FunctionEvaluationException;
+ throws ConvergenceException, FunctionEvaluationException,
IllegalArgumentException;
/**
* Solve for a zero in the given interval, start at startValue.
@@ -224,7 +137,7 @@
* @since 2.0
*/
double solve(UnivariateRealFunction f, double min, double max, double
startValue)
- throws ConvergenceException, FunctionEvaluationException;
+ throws ConvergenceException, FunctionEvaluationException,
IllegalArgumentException;
/**
* Get the result of the last run of the solver.
@@ -236,17 +149,11 @@
double getResult();
/**
- * Get the number of iterations in the last run of the solver.
- * <p>
- * This is mainly meant for testing purposes. It may occasionally
- * help track down performance problems: if the iteration count
- * is notoriously high, check whether the function is evaluated
- * properly, and whether another solver is more amenable to the
- * problem.</p>
+ * Get the result of the last run of the solver.
*
- * @return the last iteration count.
+ * @return the value of the function at the last result.
* @throws IllegalStateException if there is no result available, either
* because no result was yet computed or the last attempt failed.
*/
- int getIterationCount();
+ double getFunctionValue();
}
\ No newline at end of file
Propchange:
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolver.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolver.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange:
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolver.java
------------------------------------------------------------------------------
svn:mergeinfo =
Propchange:
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolver.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Copied:
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverFactory.java
(from r735448,
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/UnivariateRealSolverFactory.java)
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverFactory.java?p2=commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverFactory.java&p1=commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/UnivariateRealSolverFactory.java&r1=735448&r2=735530&rev=735530&view=diff
==============================================================================
---
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/UnivariateRealSolverFactory.java
(original)
+++
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverFactory.java
Sun Jan 18 11:48:52 2009
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.math.analysis;
+package org.apache.commons.math.analysis.solvers;
/**
* Abstract factory class used to create {...@link UnivariateRealSolver}
instances.
Propchange:
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverFactory.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange:
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverFactory.java
------------------------------------------------------------------------------
svn:mergeinfo =
Propchange:
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverFactory.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Copied:
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverFactoryImpl.java
(from r735448,
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/UnivariateRealSolverFactoryImpl.java)
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverFactoryImpl.java?p2=commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverFactoryImpl.java&p1=commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/UnivariateRealSolverFactoryImpl.java&r1=735448&r2=735530&rev=735530&view=diff
==============================================================================
---
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/UnivariateRealSolverFactoryImpl.java
(original)
+++
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverFactoryImpl.java
Sun Jan 18 11:48:52 2009
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.math.analysis;
+package org.apache.commons.math.analysis.solvers;
/**
* A concrete {...@link UnivariateRealSolverFactory}. This is the default
solver factory
Propchange:
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverFactoryImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverFactoryImpl.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange:
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverFactoryImpl.java
------------------------------------------------------------------------------
svn:mergeinfo =
Propchange:
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverFactoryImpl.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Copied:
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverImpl.java
(from r735448,
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/UnivariateRealSolverImpl.java)
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverImpl.java?p2=commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverImpl.java&p1=commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/UnivariateRealSolverImpl.java&r1=735448&r2=735530&rev=735530&view=diff
==============================================================================
---
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/UnivariateRealSolverImpl.java
(original)
+++
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverImpl.java
Sun Jan 18 11:48:52 2009
@@ -15,12 +15,12 @@
* limitations under the License.
*/
-package org.apache.commons.math.analysis;
-
-import java.io.Serializable;
+package org.apache.commons.math.analysis.solvers;
+import org.apache.commons.math.ConvergingAlgorithmImpl;
import org.apache.commons.math.FunctionEvaluationException;
import org.apache.commons.math.MathRuntimeException;
+import org.apache.commons.math.analysis.UnivariateRealFunction;
/**
* Provide a default implementation for several functions useful to generic
@@ -28,45 +28,26 @@
*
* @version $Revision$ $Date$
*/
-public abstract class UnivariateRealSolverImpl implements UnivariateRealSolver,
- Serializable {
+public abstract class UnivariateRealSolverImpl
+ extends ConvergingAlgorithmImpl implements UnivariateRealSolver {
/** Serializable version identifier */
private static final long serialVersionUID = 1112491292565386596L;
- /** Maximum absolute error. */
- protected double absoluteAccuracy;
-
- /** Maximum relative error. */
- protected double relativeAccuracy;
-
/** Maximum error of function. */
protected double functionValueAccuracy;
- /** Maximum number of iterations. */
- protected int maximalIterationCount;
-
- /** Default maximum absolute error. */
- protected double defaultAbsoluteAccuracy;
-
- /** Default maximum relative error. */
- protected double defaultRelativeAccuracy;
-
/** Default maximum error of function. */
protected double defaultFunctionValueAccuracy;
- /** Default maximum number of iterations. */
- protected int defaultMaximalIterationCount;
-
/** Indicates where a root has been computed. */
protected boolean resultComputed = false;
/** The last computed root. */
protected double result;
- // Mainly for test framework.
- /** The last iteration count. */
- protected int iterationCount;
+ /** Value of the function at the last computed result. */
+ protected double functionValue;
/** The function to solve.
* @deprecated as of 2.0 the function to solve is passed as an argument
@@ -90,25 +71,17 @@
* method.
*/
@Deprecated
- protected UnivariateRealSolverImpl(
- UnivariateRealFunction f,
- int defaultMaximalIterationCount,
- double defaultAbsoluteAccuracy) {
-
+ protected UnivariateRealSolverImpl(final UnivariateRealFunction f,
+ final int defaultMaximalIterationCount,
+ final double defaultAbsoluteAccuracy) {
+ super(defaultMaximalIterationCount, defaultAbsoluteAccuracy);
if (f == null) {
throw
MathRuntimeException.createIllegalArgumentException("function to solve cannot
be null",
null);
}
this.f = f;
-
- this.defaultAbsoluteAccuracy = defaultAbsoluteAccuracy;
- this.defaultRelativeAccuracy = 1E-14;
- this.defaultFunctionValueAccuracy = 1E-15;
- this.absoluteAccuracy = defaultAbsoluteAccuracy;
- this.relativeAccuracy = defaultRelativeAccuracy;
+ this.defaultFunctionValueAccuracy = 1.0e-15;
this.functionValueAccuracy = defaultFunctionValueAccuracy;
- this.defaultMaximalIterationCount = defaultMaximalIterationCount;
- this.maximalIterationCount = defaultMaximalIterationCount;
}
/**
@@ -119,172 +92,85 @@
* @throws IllegalArgumentException if f is null or the
* defaultAbsoluteAccuracy is not valid
*/
- protected UnivariateRealSolverImpl(int defaultMaximalIterationCount,
- double defaultAbsoluteAccuracy) {
- this.defaultAbsoluteAccuracy = defaultAbsoluteAccuracy;
- this.defaultRelativeAccuracy = 1E-14;
- this.defaultFunctionValueAccuracy = 1E-15;
- this.absoluteAccuracy = defaultAbsoluteAccuracy;
- this.relativeAccuracy = defaultRelativeAccuracy;
+ protected UnivariateRealSolverImpl(final int defaultMaximalIterationCount,
+ final double defaultAbsoluteAccuracy) {
+ super(defaultMaximalIterationCount, defaultAbsoluteAccuracy);
+ this.defaultFunctionValueAccuracy = 1.0e-15;
this.functionValueAccuracy = defaultFunctionValueAccuracy;
- this.defaultMaximalIterationCount = defaultMaximalIterationCount;
- this.maximalIterationCount = defaultMaximalIterationCount;
}
- /**
- * Access the last computed root.
- *
- * @return the last computed root
- * @throws IllegalStateException if no root has been computed
+ /** Check if a result has been computed.
+ * @exception IllegalStateException if no result has been computed
*/
- public double getResult() {
- if (resultComputed) {
- return result;
- } else {
+ protected void checkResultComputed() throws IllegalStateException {
+ if (!resultComputed) {
throw MathRuntimeException.createIllegalStateException("no result
available", null);
}
}
- /**
- * Access the last iteration count.
- *
- * @return the last iteration count
- * @throws IllegalStateException if no root has been computed
- *
- */
- public int getIterationCount() {
- if (resultComputed) {
- return iterationCount;
- } else {
- throw MathRuntimeException.createIllegalStateException("no result
available", null);
- }
- }
-
- /**
- * Convenience function for implementations.
- *
- * @param result the result to set
- * @param iterationCount the iteration count to set
- */
- protected final void setResult(double result, int iterationCount) {
- this.result = result;
- this.iterationCount = iterationCount;
- this.resultComputed = true;
- }
-
- /**
- * Convenience function for implementations.
- */
- protected final void clearResult() {
- this.resultComputed = false;
- }
-
- /**
- * Set the absolute accuracy.
- *
- * @param accuracy the accuracy.
- * @throws IllegalArgumentException if the accuracy can't be achieved by
- * the solver or is otherwise deemed unreasonable.
- */
- public void setAbsoluteAccuracy(double accuracy) {
- absoluteAccuracy = accuracy;
+ /** {...@inheritdoc} */
+ public double getResult() {
+ checkResultComputed();
+ return result;
}
- /**
- * Get the actual absolute accuracy.
- *
- * @return the accuracy
- */
- public double getAbsoluteAccuracy() {
- return absoluteAccuracy;
+ /** {...@inheritdoc} */
+ public double getFunctionValue() {
+ checkResultComputed();
+ return functionValue;
}
- /**
- * Reset the absolute accuracy to the default.
- */
- public void resetAbsoluteAccuracy() {
- absoluteAccuracy = defaultAbsoluteAccuracy;
- }
-
- /**
- * Set the upper limit for the number of iterations.
- *
- * @param count maximum number of iterations
- */
- public void setMaximalIterationCount(int count) {
- maximalIterationCount = count;
+ /** {...@inheritdoc} */
+ public void setFunctionValueAccuracy(final double accuracy) {
+ functionValueAccuracy = accuracy;
}
- /**
- * Get the upper limit for the number of iterations.
- *
- * @return the actual upper limit
- */
- public int getMaximalIterationCount() {
- return maximalIterationCount;
+ /** {...@inheritdoc} */
+ public double getFunctionValueAccuracy() {
+ return functionValueAccuracy;
}
- /**
- * Reset the upper limit for the number of iterations to the default.
- */
- public void resetMaximalIterationCount() {
- maximalIterationCount = defaultMaximalIterationCount;
+ /** {...@inheritdoc} */
+ public void resetFunctionValueAccuracy() {
+ functionValueAccuracy = defaultFunctionValueAccuracy;
}
/**
- * Set the relative accuracy.
+ * Convenience function for implementations.
*
- * @param accuracy the relative accuracy.
- * @throws IllegalArgumentException if the accuracy can't be achieved by
- * the solver or is otherwise deemed unreasonable.
- */
- public void setRelativeAccuracy(double accuracy) {
- relativeAccuracy = accuracy;
- }
-
- /**
- * Get the actual relative accuracy.
- * @return the accuracy
- */
- public double getRelativeAccuracy() {
- return relativeAccuracy;
- }
-
- /**
- * Reset the relative accuracy to the default.
+ * @param result the result to set
+ * @param iterationCount the iteration count to set
*/
- public void resetRelativeAccuracy() {
- relativeAccuracy = defaultRelativeAccuracy;
+ protected final void setResult(final double result, final int
iterationCount) {
+ this.result = result;
+ this.iterationCount = iterationCount;
+ this.resultComputed = true;
}
/**
- * Set the function value accuracy.
+ * Convenience function for implementations.
*
- * @param accuracy the accuracy.
- * @throws IllegalArgumentException if the accuracy can't be achieved by
- * the solver or is otherwise deemed unreasonable.
+ * @param x the result to set
+ * @param fx the result to set
+ * @param iterationCount the iteration count to set
*/
- public void setFunctionValueAccuracy(double accuracy) {
- functionValueAccuracy = accuracy;
+ protected final void setResult(final double x, final double fx,
+ final int iterationCount) {
+ this.result = x;
+ this.functionValue = fx;
+ this.iterationCount = iterationCount;
+ this.resultComputed = true;
}
/**
- * Get the actual function value accuracy.
- * @return the accuracy
+ * Convenience function for implementations.
*/
- public double getFunctionValueAccuracy() {
- return functionValueAccuracy;
+ protected final void clearResult() {
+ this.iterationCount = 0;
+ this.resultComputed = false;
}
/**
- * Reset the actual function accuracy to the default.
- */
- public void resetFunctionValueAccuracy() {
- functionValueAccuracy = defaultFunctionValueAccuracy;
- }
-
-
- /**
* Returns true iff the function takes opposite signs at the endpoints.
*
* @param lower the lower endpoint
@@ -294,10 +180,11 @@
* @throws FunctionEvaluationException if an error occurs evaluating the
* function at the endpoints
*/
- protected boolean isBracketing(double lower, double upper,
- UnivariateRealFunction f) throws FunctionEvaluationException {
- double f1 = f.value(lower);
- double f2 = f.value(upper);
+ protected boolean isBracketing(final double lower, final double upper,
+ final UnivariateRealFunction f)
+ throws FunctionEvaluationException {
+ final double f1 = f.value(lower);
+ final double f2 = f.value(upper);
return ((f1 > 0 && f2 < 0) || (f1 < 0 && f2 > 0));
}
@@ -309,7 +196,7 @@
* @param end third number
* @return true if the arguments form an increasing sequence
*/
- protected boolean isSequence(double start, double mid, double end) {
+ protected boolean isSequence(final double start, final double mid, final
double end) {
return (start < mid) && (mid < end);
}
@@ -321,11 +208,11 @@
* @param upper upper endpoint
* @throws IllegalArgumentException
*/
- protected void verifyInterval(double lower, double upper) {
+ protected void verifyInterval(final double lower, final double upper) {
if (lower >= upper) {
- throw new IllegalArgumentException
- ("Endpoints do not specify an interval: [" + lower +
- "," + upper + "]");
+ throw MathRuntimeException.createIllegalArgumentException(
+ "endpoints do not specify an interval: [{0}, {1}]",
+ new Object[] { lower, upper });
}
}
@@ -338,11 +225,11 @@
* @param upper upper endpoint
* @throws IllegalArgumentException
*/
- protected void verifySequence(double lower, double initial, double upper) {
+ protected void verifySequence(final double lower, final double initial,
final double upper) {
if (!isSequence(lower, initial, upper)) {
- throw new IllegalArgumentException
- ("Invalid interval, initial value parameters: lower=" +
- lower + " initial=" + initial + " upper=" + upper);
+ throw MathRuntimeException.createIllegalArgumentException(
+ "invalid interval, initial value parameters: lower={0},
initial={1}, upper={2}",
+ new Object[] { lower, initial, upper });
}
}
@@ -357,15 +244,16 @@
* @throws FunctionEvaluationException if an error occurs evaluating the
* function at the endpoints
*/
- protected void verifyBracketing(double lower, double upper,
- UnivariateRealFunction f) throws FunctionEvaluationException {
+ protected void verifyBracketing(final double lower, final double upper,
+ final UnivariateRealFunction f)
+ throws FunctionEvaluationException {
verifyInterval(lower, upper);
if (!isBracketing(lower, upper, f)) {
- throw new IllegalArgumentException
- ("Function values at endpoints do not have different signs." +
- " Endpoints: [" + lower + "," + upper + "]" +
- " Values: [" + f.value(lower) + "," + f.value(upper) +
"]");
+ throw MathRuntimeException.createIllegalArgumentException(
+ "function values at endpoints do not have different signs.
" +
+ "Endpoints: [{0}, {1}], Values: [{2}, {3}]",
+ new Object[] { lower, upper, f.value(lower),
f.value(upper) });
}
}
}
Propchange:
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverImpl.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange:
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverImpl.java
------------------------------------------------------------------------------
svn:mergeinfo =
Propchange:
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverImpl.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Copied:
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverUtils.java
(from r735448,
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/UnivariateRealSolverUtils.java)
URL:
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverUtils.java?p2=commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverUtils.java&p1=commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/UnivariateRealSolverUtils.java&r1=735448&r2=735530&rev=735530&view=diff
==============================================================================
---
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/UnivariateRealSolverUtils.java
(original)
+++
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverUtils.java
Sun Jan 18 11:48:52 2009
@@ -14,10 +14,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.commons.math.analysis;
+package org.apache.commons.math.analysis.solvers;
import org.apache.commons.math.FunctionEvaluationException;
import org.apache.commons.math.ConvergenceException;
+import org.apache.commons.math.analysis.UnivariateRealFunction;
/**
* Utility routines for {...@link UnivariateRealSolver} objects.
Propchange:
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverUtils.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverUtils.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange:
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverUtils.java
------------------------------------------------------------------------------
svn:mergeinfo =
Propchange:
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverUtils.java
------------------------------------------------------------------------------
svn:mime-type = text/plain