org.apache.commons.math3.analysis

## Class FunctionUtils

• public class FunctionUtils
extends Object
Utilities for manipulating function objects.
Since:
3.0
• ### Method Summary

Methods
Modifier and Type Method and Description
static DifferentiableUnivariateFunction add(DifferentiableUnivariateFunction... f)
Deprecated.
static UnivariateDifferentiableFunction add(UnivariateDifferentiableFunction... f)
static UnivariateFunction add(UnivariateFunction... f)
static MultivariateFunction collector(BivariateFunction combiner, double initialValue)
Returns a MultivariateFunction h(x[]) defined by
static MultivariateFunction collector(BivariateFunction combiner, UnivariateFunction f, double initialValue)
Returns a MultivariateFunction h(x[]) defined by
static UnivariateFunction combine(BivariateFunction combiner, UnivariateFunction f, UnivariateFunction g)
Returns the univariate function
h(x) = combiner(f(x), g(x)).
static DifferentiableUnivariateFunction compose(DifferentiableUnivariateFunction... f)
static UnivariateDifferentiableFunction compose(UnivariateDifferentiableFunction... f)
Composes functions.
static UnivariateFunction compose(UnivariateFunction... f)
Composes functions.
static UnivariateFunction fix1stArgument(BivariateFunction f, double fixed)
Creates a unary function by fixing the first argument of a binary function.
static UnivariateFunction fix2ndArgument(BivariateFunction f, double fixed)
Creates a unary function by fixing the second argument of a binary function.
static DifferentiableUnivariateFunction multiply(DifferentiableUnivariateFunction... f)
static UnivariateDifferentiableFunction multiply(UnivariateDifferentiableFunction... f)
Multiplies functions.
static UnivariateFunction multiply(UnivariateFunction... f)
Multiplies functions.
static double[] sample(UnivariateFunction f, double min, double max, int n)
Samples the specified univariate real function on the specified interval.
static DifferentiableMultivariateFunction toDifferentiableMultivariateFunction(MultivariateDifferentiableFunction f)
Deprecated.
this conversion method is temporary in version 3.1, as the DifferentiableMultivariateFunction interface itself is deprecated
static DifferentiableMultivariateVectorFunction toDifferentiableMultivariateVectorFunction(MultivariateDifferentiableVectorFunction f)
Deprecated.
this conversion method is temporary in version 3.1, as the DifferentiableMultivariateVectorFunction interface itself is deprecated
static DifferentiableUnivariateFunction toDifferentiableUnivariateFunction(UnivariateDifferentiableFunction f)
Deprecated.
this conversion method is temporary in version 3.1, as the DifferentiableUnivariateFunction interface itself is deprecated
static MultivariateDifferentiableFunction toMultivariateDifferentiableFunction(DifferentiableMultivariateFunction f)
Deprecated.
this conversion method is temporary in version 3.1, as the DifferentiableMultivariateFunction interface itself is deprecated
static MultivariateDifferentiableVectorFunction toMultivariateDifferentiableVectorFunction(DifferentiableMultivariateVectorFunction f)
Deprecated.
this conversion method is temporary in version 3.1, as the DifferentiableMultivariateFunction interface itself is deprecated
static UnivariateDifferentiableFunction toUnivariateDifferential(DifferentiableUnivariateFunction f)
Deprecated.
this conversion method is temporary in version 3.1, as the DifferentiableUnivariateFunction interface itself is deprecated
• ### Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
• ### 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)
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.

public static UnivariateFunction add(UnivariateFunction... f)
Parameters:
f - List of functions.
Returns:
a function that computes the sum of the functions.

public static UnivariateDifferentiableFunction add(UnivariateDifferentiableFunction... f)
Parameters:
f - List of functions.
Returns:
a function that computes the sum of the functions.
Since:
3.1

@Deprecated
public static DifferentiableUnivariateFunction add(DifferentiableUnivariateFunction... f)
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)
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 function
h(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 of f 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 of f 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 from min to max - (max - min) / n; therefore f is not sampled at the upper bound max.
Parameters:
f - Function to be sampled
min - 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 bound min is greater than, or equal to the upper bound max.
NotStrictlyPositiveException - if the number of sample points n is negative.
• #### toDifferentiableUnivariateFunction

@Deprecated
public static DifferentiableUnivariateFunction toDifferentiableUnivariateFunction(UnivariateDifferentiableFunction f)
Deprecated. this conversion method is temporary in version 3.1, as the DifferentiableUnivariateFunction interface itself is deprecated
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 the DifferentiableMultivariateFunction interface itself is deprecated
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 the DifferentiableMultivariateVectorFunction interface itself is deprecated
Parameters:
f - function to convert
Returns:
converted function