Class FunctionUtils
- java.lang.Object
-
- org.apache.commons.math4.legacy.analysis.FunctionUtils
-
public final class FunctionUtils extends 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
-
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
-
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
-
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 by:h(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 by:h(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)
-
toDifferentiable
public static UnivariateDifferentiableFunction toDifferentiable(UnivariateFunction f, UnivariateFunction... derivatives)
Convert regular functions toUnivariateDifferentiableFunction
.This method handle the case with one free parameter and several derivatives. For the case with several free parameters and only first order derivatives, see
toDifferentiable(MultivariateFunction, MultivariateVectorFunction)
. There are no direct support for intermediate cases, with several free parameters and order 2 or more derivatives, as is would be difficult to specify all the cross derivatives.Note that the derivatives are expected to be computed only with respect to the raw parameter x of the base function, i.e. they are df/dx, df2/dx2, ... Even if the built function is later used in a composition like f(sin(t)), the provided derivatives should not apply the composition with sine and its derivatives by themselves. The composition will be done automatically here and the result will properly contain f(sin(t)), df(sin(t))/dt, df2(sin(t))/dt2 despite the provided derivatives functions know nothing about the sine function.
- Parameters:
f
- base function f(x)derivatives
- derivatives of the base function, in increasing differentiation order- Returns:
- a differentiable function with value and all specified derivatives
- See Also:
toDifferentiable(MultivariateFunction, MultivariateVectorFunction)
,derivative(UnivariateDifferentiableFunction, int)
-
toDifferentiable
public static MultivariateDifferentiableFunction toDifferentiable(MultivariateFunction f, MultivariateVectorFunction gradient)
Convert regular functions toMultivariateDifferentiableFunction
.This method handle the case with several free parameters and only first order derivatives. For the case with one free parameter and several derivatives, see
toDifferentiable(UnivariateFunction, UnivariateFunction...)
. There are no direct support for intermediate cases, with several free parameters and order 2 or more derivatives, as is would be difficult to specify all the cross derivatives.Note that the gradient is expected to be computed only with respect to the raw parameter x of the base function, i.e. it is df/dx1, df/dx2, ... Even if the built function is later used in a composition like f(sin(t), cos(t)), the provided gradient should not apply the composition with sine or cosine and their derivative by itself. The composition will be done automatically here and the result will properly contain f(sin(t), cos(t)), df(sin(t), cos(t))/dt despite the provided derivatives functions know nothing about the sine or cosine functions.
- Parameters:
f
- base function f(x)gradient
- gradient of the base function- Returns:
- a differentiable function with value and gradient
- See Also:
toDifferentiable(UnivariateFunction, UnivariateFunction...)
,derivative(MultivariateDifferentiableFunction, int[])
-
derivative
public static UnivariateFunction derivative(UnivariateDifferentiableFunction f, int order)
Convert anUnivariateDifferentiableFunction
to anUnivariateFunction
computing nth order derivative.This converter is only a convenience method. Beware computing only one derivative does not save any computation as the original function will really be called under the hood. The derivative will be extracted from the full
DerivativeStructure
result.- Parameters:
f
- original function, with value and all its derivativesorder
- of the derivative to extract- Returns:
- function computing the derivative at required order
- See Also:
derivative(MultivariateDifferentiableFunction, int[])
,toDifferentiable(UnivariateFunction, UnivariateFunction...)
-
derivative
public static MultivariateFunction derivative(MultivariateDifferentiableFunction f, int[] orders)
Convert anMultivariateDifferentiableFunction
to anMultivariateFunction
computing nth order derivative.This converter is only a convenience method. Beware computing only one derivative does not save any computation as the original function will really be called under the hood. The derivative will be extracted from the full
DerivativeStructure
result.- Parameters:
f
- original function, with value and all its derivativesorders
- of the derivative to extract, for each free parameters- Returns:
- function computing the derivative at required order
- See Also:
derivative(UnivariateDifferentiableFunction, int)
,toDifferentiable(MultivariateFunction, MultivariateVectorFunction)
-
-