## Interface UnivariateFunction

• All Superinterfaces:
DoubleUnaryOperator
All Known Subinterfaces:
UnivariateDifferentiableFunction
All Known Implementing Classes:
Abs, Acos, Acosh, Asin, Asinh, Atan, Atanh, BesselJ, Cbrt, Ceil, Constant, Cos, Cosh, Exp, Expm1, Floor, Gaussian, HarmonicOscillator, Identity, Inverse, Log, Log10, Log1p, Logistic, Logit, Minus, PolynomialFunction, PolynomialFunctionLagrangeForm, PolynomialFunctionNewtonForm, PolynomialSplineFunction, Power, Rint, Sigmoid, Signum, Sin, Sinc, Sinh, Sqrt, StepFunction, Tan, Tanh, Ulp
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface
public interface UnivariateFunction
extends DoubleUnaryOperator
An interface representing a univariate real function.

When a user-defined function encounters an error during evaluation, the value method should throw a user-defined unchecked exception.

The following code excerpt shows the recommended way to do that using a root solver as an example, but the same construct is applicable to ODE integrators or optimizers.

 private static class LocalException extends RuntimeException {
// The x value that caused the problem.
private final double x;

public LocalException(double x) {
this.x = x;
}

public double getX() {
return x;
}
}

private static class MyFunction implements UnivariateFunction {
public double value(double x) {
double y = hugeFormula(x);
throw new LocalException(x);
}
return y;
}
}

public void compute() {
try {
solver.solve(maxEval, new MyFunction(a, b, c), min, max);
} catch (LocalException le) {
// Retrieve the x value.
}
}

As shown, the exception is local to the user's code and it is guaranteed that Apache Commons Math will not catch it.
• ### Method Summary

All Methods
Modifier and Type Method Description
default double applyAsDouble​(double x)
double value​(double x)
Compute the value of the function.
• ### Methods inherited from interface java.util.function.DoubleUnaryOperator

andThen, compose
• ### Method Detail

• #### value

double value​(double x)
Compute the value of the function.
Parameters:
x - Point at which the function value should be computed.
Returns:
the value of the function.
Throws:
IllegalArgumentException - when the activated method itself can ascertain that a precondition, specified in the API expressed at the level of the activated method, has been violated. When Commons Math throws an IllegalArgumentException, it is usually the consequence of checking the actual parameters passed to the method.
• #### applyAsDouble

default double applyAsDouble​(double x)
Specified by:
applyAsDouble in interface DoubleUnaryOperator