Class FunctionUtils
- java.lang.Object
-
- org.apache.commons.math3.analysis.FunctionUtils
-
public class FunctionUtils extends java.lang.ObjectUtilities for manipulating function objects.- Since:
- 3.0
-
-
Constructor Summary
Constructors Modifier Constructor Description privateFunctionUtils()Class only contains static methods.
-
Method Summary
-
-
-
Method Detail
-
compose
public static UnivariateFunction compose(UnivariateFunction... f)
Composes functions.The functions in the argument list are composed sequentially, in the given order. For example, compose(f1,f2,f3) acts like f1(f2(f3(x))).
- Parameters:
f- List of functions.- Returns:
- the composite function.
-
compose
public static UnivariateDifferentiableFunction compose(UnivariateDifferentiableFunction... f)
Composes functions.The functions in the argument list are composed sequentially, in the given order. For example, compose(f1,f2,f3) acts like f1(f2(f3(x))).
- Parameters:
f- List of functions.- Returns:
- the composite function.
- Since:
- 3.1
-
compose
@Deprecated public static DifferentiableUnivariateFunction compose(DifferentiableUnivariateFunction... f)
Deprecated.as of 3.1 replaced bycompose(UnivariateDifferentiableFunction...)Composes functions.The functions in the argument list are composed sequentially, in the given order. For example, compose(f1,f2,f3) acts like f1(f2(f3(x))).
- Parameters:
f- List of functions.- Returns:
- the composite function.
-
add
public static UnivariateFunction add(UnivariateFunction... f)
Adds functions.- Parameters:
f- List of functions.- Returns:
- a function that computes the sum of the functions.
-
add
public static UnivariateDifferentiableFunction add(UnivariateDifferentiableFunction... f)
Adds functions.- Parameters:
f- List of functions.- Returns:
- a function that computes the sum of the functions.
- Since:
- 3.1
-
add
@Deprecated public static DifferentiableUnivariateFunction add(DifferentiableUnivariateFunction... f)
Deprecated.as of 3.1 replaced byadd(UnivariateDifferentiableFunction...)Adds functions.- Parameters:
f- List of functions.- Returns:
- a function that computes the sum of the functions.
-
multiply
public static UnivariateFunction multiply(UnivariateFunction... f)
Multiplies functions.- Parameters:
f- List of functions.- Returns:
- a function that computes the product of the functions.
-
multiply
public static UnivariateDifferentiableFunction multiply(UnivariateDifferentiableFunction... f)
Multiplies functions.- Parameters:
f- List of functions.- Returns:
- a function that computes the product of the functions.
- Since:
- 3.1
-
multiply
@Deprecated public static DifferentiableUnivariateFunction multiply(DifferentiableUnivariateFunction... f)
Deprecated.as of 3.1 replaced bymultiply(UnivariateDifferentiableFunction...)Multiplies functions.- Parameters:
f- List of functions.- Returns:
- a function that computes the product of the functions.
-
combine
public static UnivariateFunction combine(BivariateFunction combiner, UnivariateFunction f, UnivariateFunction g)
Returns the univariate functionh(x) = combiner(f(x), g(x)).- Parameters:
combiner- Combiner function.f- Function.g- Function.- Returns:
- the composite function.
-
collector
public static MultivariateFunction collector(BivariateFunction combiner, UnivariateFunction f, double initialValue)
Returns a MultivariateFunction h(x[]) defined byh(x[]) = combiner(...combiner(combiner(initialValue,f(x[0])),f(x[1]))...),f(x[x.length-1]))- Parameters:
combiner- Combiner function.f- Function.initialValue- Initial value.- Returns:
- a collector function.
-
collector
public static MultivariateFunction collector(BivariateFunction combiner, double initialValue)
Returns a MultivariateFunction h(x[]) defined byh(x[]) = combiner(...combiner(combiner(initialValue,x[0]),x[1])...),x[x.length-1])- Parameters:
combiner- Combiner function.initialValue- Initial value.- Returns:
- a collector function.
-
fix1stArgument
public static UnivariateFunction fix1stArgument(BivariateFunction f, double fixed)
Creates a unary function by fixing the first argument of a binary function.- Parameters:
f- Binary function.fixed- value to which the first argument offis set.- Returns:
- the unary function h(x) = f(fixed, x)
-
fix2ndArgument
public static UnivariateFunction fix2ndArgument(BivariateFunction f, double fixed)
Creates a unary function by fixing the second argument of a binary function.- Parameters:
f- Binary function.fixed- value to which the second argument offis set.- Returns:
- the unary function h(x) = f(x, fixed)
-
sample
public static double[] sample(UnivariateFunction f, double min, double max, int n) throws NumberIsTooLargeException, NotStrictlyPositiveException
Samples the specified univariate real function on the specified interval.The interval is divided equally into
nsections and sample points are taken frommintomax - (max - min) / n; thereforefis not sampled at the upper boundmax.- Parameters:
f- Function to be sampledmin- Lower bound of the interval (included).max- Upper bound of the interval (excluded).n- Number of sample points.- Returns:
- the array of samples.
- Throws:
NumberIsTooLargeException- if the lower boundminis greater than, or equal to the upper boundmax.NotStrictlyPositiveException- if the number of sample pointsnis negative.
-
toDifferentiableUnivariateFunction
@Deprecated public static DifferentiableUnivariateFunction toDifferentiableUnivariateFunction(UnivariateDifferentiableFunction f)
Deprecated.this conversion method is temporary in version 3.1, as theDifferentiableUnivariateFunctioninterface itself is deprecatedConvert aUnivariateDifferentiableFunctioninto aDifferentiableUnivariateFunction.- Parameters:
f- function to convert- Returns:
- converted function
-
toUnivariateDifferential
@Deprecated public static UnivariateDifferentiableFunction toUnivariateDifferential(DifferentiableUnivariateFunction f)
Deprecated.this conversion method is temporary in version 3.1, as theDifferentiableUnivariateFunctioninterface itself is deprecatedConvert aDifferentiableUnivariateFunctioninto aUnivariateDifferentiableFunction.Note that the converted function is able to handle
DerivativeStructureup to order one. If the function is called with higher order, aNumberIsTooLargeExceptionis thrown.- Parameters:
f- function to convert- Returns:
- converted function
-
toDifferentiableMultivariateFunction
@Deprecated public static DifferentiableMultivariateFunction toDifferentiableMultivariateFunction(MultivariateDifferentiableFunction f)
Deprecated.this conversion method is temporary in version 3.1, as theDifferentiableMultivariateFunctioninterface itself is deprecatedConvert aMultivariateDifferentiableFunctioninto aDifferentiableMultivariateFunction.- Parameters:
f- function to convert- Returns:
- converted function
-
toMultivariateDifferentiableFunction
@Deprecated public static MultivariateDifferentiableFunction toMultivariateDifferentiableFunction(DifferentiableMultivariateFunction f)
Deprecated.this conversion method is temporary in version 3.1, as theDifferentiableMultivariateFunctioninterface itself is deprecatedConvert aDifferentiableMultivariateFunctioninto aMultivariateDifferentiableFunction.Note that the converted function is able to handle
DerivativeStructureelements that all have the same number of free parameters and order, and with order at most 1. If the function is called with inconsistent numbers of free parameters or higher order, aDimensionMismatchExceptionor aNumberIsTooLargeExceptionwill be thrown.- Parameters:
f- function to convert- Returns:
- converted function
-
toDifferentiableMultivariateVectorFunction
@Deprecated public static DifferentiableMultivariateVectorFunction toDifferentiableMultivariateVectorFunction(MultivariateDifferentiableVectorFunction f)
Deprecated.this conversion method is temporary in version 3.1, as theDifferentiableMultivariateVectorFunctioninterface itself is deprecated- Parameters:
f- function to convert- Returns:
- converted function
-
toMultivariateDifferentiableVectorFunction
@Deprecated public static MultivariateDifferentiableVectorFunction toMultivariateDifferentiableVectorFunction(DifferentiableMultivariateVectorFunction f)
Deprecated.this conversion method is temporary in version 3.1, as theDifferentiableMultivariateFunctioninterface itself is deprecatedConvert aDifferentiableMultivariateVectorFunctioninto aMultivariateDifferentiableVectorFunction.Note that the converted function is able to handle
DerivativeStructureelements that all have the same number of free parameters and order, and with order at most 1. If the function is called with inconsistent numbers of free parameters or higher order, aDimensionMismatchExceptionor aNumberIsTooLargeExceptionwill be thrown.- Parameters:
f- function to convert- Returns:
- converted function
-
-