Class FunctionUtils
- java.lang.Object
-
- org.apache.commons.math3.analysis.FunctionUtils
-
public class FunctionUtils extends java.lang.Object
Utilities for manipulating function objects.- Since:
- 3.0
-
-
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 off
is 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 off
is 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
n
sections and sample points are taken frommin
tomax - (max - min) / n
; thereforef
is 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 boundmin
is greater than, or equal to the upper boundmax
.NotStrictlyPositiveException
- if the number of sample pointsn
is negative.
-
toDifferentiableUnivariateFunction
@Deprecated public static DifferentiableUnivariateFunction toDifferentiableUnivariateFunction(UnivariateDifferentiableFunction f)
Deprecated.this conversion method is temporary in version 3.1, as theDifferentiableUnivariateFunction
interface itself is deprecatedConvert aUnivariateDifferentiableFunction
into 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 theDifferentiableUnivariateFunction
interface itself is deprecatedConvert aDifferentiableUnivariateFunction
into aUnivariateDifferentiableFunction
.Note that the converted function is able to handle
DerivativeStructure
up to order one. If the function is called with higher order, aNumberIsTooLargeException
is 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 theDifferentiableMultivariateFunction
interface itself is deprecatedConvert aMultivariateDifferentiableFunction
into 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 theDifferentiableMultivariateFunction
interface itself is deprecatedConvert aDifferentiableMultivariateFunction
into aMultivariateDifferentiableFunction
.Note that the converted function is able to handle
DerivativeStructure
elements 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, aDimensionMismatchException
or aNumberIsTooLargeException
will 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 theDifferentiableMultivariateVectorFunction
interface 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 theDifferentiableMultivariateFunction
interface itself is deprecatedConvert aDifferentiableMultivariateVectorFunction
into aMultivariateDifferentiableVectorFunction
.Note that the converted function is able to handle
DerivativeStructure
elements 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, aDimensionMismatchException
or aNumberIsTooLargeException
will be thrown.- Parameters:
f
- function to convert- Returns:
- converted function
-
-