org.apache.commons.math3.analysis

## Class FunctionUtils

• ```public class FunctionUtils
extends Object```
Utilities for manipulating function objects.
Since:
3.0
Version:
\$Id\$
• ### Method Summary

Methods
Modifier and Type Method and Description
`static DifferentiableUnivariateFunction` `add(DifferentiableUnivariateFunction... 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)`
Compose functions.
`static UnivariateFunction` `compose(UnivariateFunction... f)`
Compose functions.
`static UnivariateFunction` ```fix1stArgument(BivariateFunction f, double fixed)```
Create a unary function by fixing the first argument of a binary function.
`static UnivariateFunction` ```fix2ndArgument(BivariateFunction f, double fixed)```
Create a unary function by fixing the second argument of a binary function.
`static DifferentiableUnivariateFunction` `multiply(DifferentiableUnivariateFunction... f)`
Multiply functions.
`static UnivariateFunction` `multiply(UnivariateFunction... f)`
Multiply functions.
`static double[]` ```sample(UnivariateFunction f, double min, double max, int n)```
Samples the specified univariate real function on the specified interval.
• ### 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)`
Compose functions. The functions in the argument list are composed sequentially, in the order given. For example, compose(f1,f2,f3) acts like f1(f2(f3(x))).
Parameters:
`f` - List of functions.
Returns:
the composite function.
• #### compose

`public static DifferentiableUnivariateFunction compose(DifferentiableUnivariateFunction... f)`
Compose functions. The functions in the argument list are composed sequentially, in the order given. 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 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)`
Multiply functions.
Parameters:
`f` - List of functions.
Returns:
a function that computes the product of the functions.
• #### multiply

`public static DifferentiableUnivariateFunction multiply(DifferentiableUnivariateFunction... f)`
Multiply 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)```
Create 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)```
Create 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)```

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` - the function to be sampled
`min` - the (inclusive) lower bound of the interval
`max` - the (exclusive) upper bound of the interval
`n` - the 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