public class FunctionUtils extends Object
public static UnivariateFunction compose(UnivariateFunction... f)
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))).
f
- List of functions.public static UnivariateDifferentiableFunction compose(UnivariateDifferentiableFunction... f)
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))).
f
- List of functions.public static UnivariateFunction add(UnivariateFunction... f)
f
- List of functions.public static UnivariateDifferentiableFunction add(UnivariateDifferentiableFunction... f)
f
- List of functions.public static UnivariateFunction multiply(UnivariateFunction... f)
f
- List of functions.public static UnivariateDifferentiableFunction multiply(UnivariateDifferentiableFunction... f)
f
- List of functions.public static UnivariateFunction combine(BivariateFunction combiner, UnivariateFunction f, UnivariateFunction g)
h(x) = combiner(f(x), g(x)).
combiner
- Combiner function.f
- Function.g
- Function.public static MultivariateFunction collector(BivariateFunction combiner, UnivariateFunction f, double initialValue)
h(x[]) = combiner(...combiner(combiner(initialValue,f(x[0])),f(x[1]))...),f(x[x.length-1]))
combiner
- Combiner function.f
- Function.initialValue
- Initial value.public static MultivariateFunction collector(BivariateFunction combiner, double initialValue)
h(x[]) = combiner(...combiner(combiner(initialValue,x[0]),x[1])...),x[x.length-1])
combiner
- Combiner function.initialValue
- Initial value.public static UnivariateFunction fix1stArgument(BivariateFunction f, double fixed)
f
- Binary function.fixed
- value to which the first argument of f
is set.public static UnivariateFunction fix2ndArgument(BivariateFunction f, double fixed)
f
- Binary function.fixed
- value to which the second argument of f
is set.public static double[] sample(UnivariateFunction f, double min, double max, int n) throws MathIllegalArgumentException
The interval is divided equally into n
sections and sample points
are taken from min
to max - (max - min) / n
; therefore
f
is not sampled at the upper bound max
.
f
- Function to be sampledmin
- Lower bound of the interval (included).max
- Upper bound of the interval (excluded).n
- Number of sample points.MathIllegalArgumentException
- if the lower bound min
is
greater than, or equal to the upper bound max
.MathIllegalArgumentException
- if the number of sample points
n
is negative.public static UnivariateDifferentiableFunction toDifferentiable(UnivariateFunction f, UnivariateFunction... derivatives)
UnivariateDifferentiableFunction
.
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.
f
- base function f(x)derivatives
- derivatives of the base function, in increasing differentiation ordertoDifferentiable(MultivariateFunction, MultivariateVectorFunction)
,
derivative(UnivariateDifferentiableFunction, int)
public static MultivariateDifferentiableFunction toDifferentiable(MultivariateFunction f, MultivariateVectorFunction gradient)
MultivariateDifferentiableFunction
.
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.
f
- base function f(x)gradient
- gradient of the base functiontoDifferentiable(UnivariateFunction, UnivariateFunction...)
,
derivative(MultivariateDifferentiableFunction, int[])
public static UnivariateFunction derivative(UnivariateDifferentiableFunction f, int order)
UnivariateDifferentiableFunction
to an
UnivariateFunction
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.
f
- original function, with value and all its derivativesorder
- of the derivative to extractderivative(MultivariateDifferentiableFunction, int[])
,
toDifferentiable(UnivariateFunction, UnivariateFunction...)
public static MultivariateFunction derivative(MultivariateDifferentiableFunction f, int[] orders)
MultivariateDifferentiableFunction
to an
MultivariateFunction
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.
f
- original function, with value and all its derivativesorders
- of the derivative to extract, for each free parametersderivative(UnivariateDifferentiableFunction, int)
,
toDifferentiable(MultivariateFunction, MultivariateVectorFunction)
Copyright © 2016–2020 Hipparchus.org. All rights reserved.