Class UnivariateRealSolverUtils
- java.lang.Object
 - 
- org.apache.commons.math.analysis.solvers.UnivariateRealSolverUtils
 
 
- 
public class UnivariateRealSolverUtils extends java.lang.ObjectUtility routines forUnivariateRealSolverobjects. 
- 
- 
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static double[]bracket(UnivariateRealFunction function, double initial, double lowerBound, double upperBound)This method attempts to find two values a and b satisfyinglowerBound <= a < initial < b <= upperBoundf(a) * f(b) < 0If f is continuous on[a,b],this means thataandbbracket a root of f.static double[]bracket(UnivariateRealFunction function, double initial, double lowerBound, double upperBound, int maximumIterations)This method attempts to find two values a and b satisfyinglowerBound <= a < initial < b <= upperBoundf(a) * f(b) <= 0If f is continuous on[a,b],this means thataandbbracket a root of f.static doublemidpoint(double a, double b)Compute the midpoint of two values.static doublesolve(UnivariateRealFunction f, double x0, double x1)Convenience method to find a zero of a univariate real function.static doublesolve(UnivariateRealFunction f, double x0, double x1, double absoluteAccuracy)Convenience method to find a zero of a univariate real function. 
 - 
 
- 
- 
Method Detail
- 
solve
public static double solve(UnivariateRealFunction f, double x0, double x1) throws ConvergenceException, FunctionEvaluationException
Convenience method to find a zero of a univariate real function. A default solver is used.- Parameters:
 f- the function.x0- the lower bound for the interval.x1- the upper bound for the interval.- Returns:
 - a value where the function is zero.
 - Throws:
 ConvergenceException- if the iteration count was exceededFunctionEvaluationException- if an error occurs evaluating the functionjava.lang.IllegalArgumentException- if f is null or the endpoints do not specify a valid interval
 
- 
solve
public static double solve(UnivariateRealFunction f, double x0, double x1, double absoluteAccuracy) throws ConvergenceException, FunctionEvaluationException
Convenience method to find a zero of a univariate real function. A default solver is used.- Parameters:
 f- the functionx0- the lower bound for the intervalx1- the upper bound for the intervalabsoluteAccuracy- the accuracy to be used by the solver- Returns:
 - a value where the function is zero
 - Throws:
 ConvergenceException- if the iteration count is exceededFunctionEvaluationException- if an error occurs evaluating the functionjava.lang.IllegalArgumentException- if f is null, the endpoints do not specify a valid interval, or the absoluteAccuracy is not valid for the default solver
 
- 
bracket
public static double[] bracket(UnivariateRealFunction function, double initial, double lowerBound, double upperBound) throws ConvergenceException, FunctionEvaluationException
This method attempts to find two values a and b satisfying-  
lowerBound <= a < initial < b <= upperBound -  
f(a) * f(b) < 0 
[a,b],this means thataandbbracket a root of f.The algorithm starts by setting
a := initial -1; b := initial +1,examines the value of the function ataandband keeps moving the endpoints out by one unit each time through a loop that terminates when one of the following happens:-  
f(a) * f(b) < 0-- success! -  
a = lowerandb = upper-- ConvergenceException -  
Integer.MAX_VALUEiterations elapse -- ConvergenceException 
Note: this method can take
Integer.MAX_VALUEiterations to throw aConvergenceException.Unless you are confident that there is a root betweenlowerBoundandupperBoundnearinitial,it is better to usebracket(UnivariateRealFunction, double, double, double, int), explicitly specifying the maximum number of iterations.- Parameters:
 function- the functioninitial- initial midpoint of interval being expanded to bracket a rootlowerBound- lower bound (a is never lower than this value)upperBound- upper bound (b never is greater than this value)- Returns:
 - a two element array holding {a, b}
 - Throws:
 ConvergenceException- if a root can not be brackettedFunctionEvaluationException- if an error occurs evaluating the functionjava.lang.IllegalArgumentException- if function is null, maximumIterations is not positive, or initial is not between lowerBound and upperBound
 -  
 
- 
bracket
public static double[] bracket(UnivariateRealFunction function, double initial, double lowerBound, double upperBound, int maximumIterations) throws ConvergenceException, FunctionEvaluationException
This method attempts to find two values a and b satisfying-  
lowerBound <= a < initial < b <= upperBound -  
f(a) * f(b) <= 0 
[a,b],this means thataandbbracket a root of f.The algorithm starts by setting
a := initial -1; b := initial +1,examines the value of the function ataandband keeps moving the endpoints out by one unit each time through a loop that terminates when one of the following happens:-  
f(a) * f(b) <= 0-- success! -  
a = lowerandb = upper-- ConvergenceException -  
maximumIterationsiterations elapse -- ConvergenceException 
- Parameters:
 function- the functioninitial- initial midpoint of interval being expanded to bracket a rootlowerBound- lower bound (a is never lower than this value)upperBound- upper bound (b never is greater than this value)maximumIterations- maximum number of iterations to perform- Returns:
 - a two element array holding {a, b}.
 - Throws:
 ConvergenceException- if the algorithm fails to find a and b satisfying the desired conditionsFunctionEvaluationException- if an error occurs evaluating the functionjava.lang.IllegalArgumentException- if function is null, maximumIterations is not positive, or initial is not between lowerBound and upperBound
 -  
 
- 
midpoint
public static double midpoint(double a, double b)Compute the midpoint of two values.- Parameters:
 a- first value.b- second value.- Returns:
 - the midpoint.
 
 
 - 
 
 -