本文整理汇总了Java中org.apache.commons.math3.analysis.solvers.AllowedSolution类的典型用法代码示例。如果您正苦于以下问题:Java AllowedSolution类的具体用法?Java AllowedSolution怎么用?Java AllowedSolution使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AllowedSolution类属于org.apache.commons.math3.analysis.solvers包,在下文中一共展示了AllowedSolution类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: solve
import org.apache.commons.math3.analysis.solvers.AllowedSolution; //导入依赖的package包/类
/**
* Solve for a zero in the given interval, start at {@code startValue}.
* A solver may require that the interval brackets a single zero root.
* Solvers that do require bracketing should be able to handle the case
* where one of the endpoints is itself a root.
*
* @param maxEval Maximum number of evaluations.
* @param f Function to solve.
* @param min Lower bound for the interval.
* @param max Upper bound for the interval.
* @param startValue Start value to use.
* @param allowedSolution The kind of solutions that the root-finding algorithm may
* accept as solutions.
* @return a value where the function is zero.
* @exception NullArgumentException if f is null.
* @exception NoBracketingException if root cannot be bracketed
*/
public Dfp solve(final int maxEval, final UnivariateDfpFunction f,
final Dfp min, final Dfp max, final Dfp startValue,
final AllowedSolution allowedSolution)
throws NullArgumentException, NoBracketingException {
// checks
MathUtils.checkNotNull(f);
// wrap the function
RealFieldUnivariateFunction<Dfp> fieldF = new RealFieldUnivariateFunction<Dfp>() {
/** {@inheritDoc} */
public Dfp value(final Dfp x) {
return f.value(x);
}
};
// delegate to general field solver
return solve(maxEval, fieldF, min, max, startValue, allowedSolution);
}
示例2: testConvergenceOnFunctionAccuracy
import org.apache.commons.math3.analysis.solvers.AllowedSolution; //导入依赖的package包/类
@Test
public void testConvergenceOnFunctionAccuracy() {
BracketingNthOrderBrentSolverDFP solver =
new BracketingNthOrderBrentSolverDFP(relativeAccuracy, absoluteAccuracy,
field.newDfp(1.0e-20), 20);
UnivariateDfpFunction f = new UnivariateDfpFunction() {
public Dfp value(Dfp x) {
Dfp one = field.getOne();
Dfp oneHalf = one.divide(2);
Dfp xMo = x.subtract(one);
Dfp xMh = x.subtract(oneHalf);
Dfp xPh = x.add(oneHalf);
Dfp xPo = x.add(one);
return xMo.multiply(xMh).multiply(x).multiply(xPh).multiply(xPo);
}
};
Dfp result = solver.solve(20, f, field.newDfp(0.2), field.newDfp(0.9),
field.newDfp(0.4), AllowedSolution.BELOW_SIDE);
Assert.assertTrue(f.value(result).abs().lessThan(solver.getFunctionValueAccuracy()));
Assert.assertTrue(f.value(result).negativeOrNull());
Assert.assertTrue(result.subtract(field.newDfp(0.5)).subtract(solver.getAbsoluteAccuracy()).positiveOrNull());
result = solver.solve(20, f, field.newDfp(-0.9), field.newDfp(-0.2),
field.newDfp(-0.4), AllowedSolution.ABOVE_SIDE);
Assert.assertTrue(f.value(result).abs().lessThan(solver.getFunctionValueAccuracy()));
Assert.assertTrue(f.value(result).positiveOrNull());
Assert.assertTrue(result.add(field.newDfp(0.5)).subtract(solver.getAbsoluteAccuracy()).negativeOrNull());
}
示例3: solve
import org.apache.commons.math3.analysis.solvers.AllowedSolution; //导入依赖的package包/类
/**
* Solve for a zero in the given interval.
* A solver may require that the interval brackets a single zero root.
* Solvers that do require bracketing should be able to handle the case
* where one of the endpoints is itself a root.
*
* @param maxEval Maximum number of evaluations.
* @param f Function to solve.
* @param min Lower bound for the interval.
* @param max Upper bound for the interval.
* @param allowedSolution The kind of solutions that the root-finding algorithm may
* accept as solutions.
* @return a value where the function is zero.
* @exception NullArgumentException if f is null.
* @exception NoBracketingException if root cannot be bracketed
*/
public Dfp solve(final int maxEval, final UnivariateDfpFunction f,
final Dfp min, final Dfp max, final AllowedSolution allowedSolution)
throws NullArgumentException, NoBracketingException {
return solve(maxEval, f, min, max, min.add(max).divide(2), allowedSolution);
}