Class PiecewiseFunction

  • All Implemented Interfaces:
    Function


    public class PiecewiseFunction
    extends Object
    implements Function
    This function pieces several separate functions together. This makes no guarantees about continuity; it is possible this function is discontinuous.
    • Constructor Detail

      • PiecewiseFunction

        public PiecewiseFunction(Function[] functions,
                                 double[] upperBounds)
        Creates a new PiecewiseFunction.
        Parameters:
        functions -
        upperBounds - the right-most edge of functions. If there are n-elements in functions, there should be (n-1) elements in this array.

        So if you pass 2 functions [a, b], and this value is the array [k], then for all values less than k: a will be used. For all values greater than k, b will be be used.

    • Method Detail

      • create

        public static PiecewiseFunction create(Function f,
                                               Function fDeriv,
                                               double min,
                                               double max,
                                               int functions)
        This creates a PiecewiseFunction that resembles another function. This method should be used when the argument f is normally expensive to calculate, and generally predictable/simple in curvature.

        The pieces of the new PiecewiseFunction are going to be PolynomialFunctions.

        Parameters:
        f - the function to mimic.
        fDeriv - a derivative of f.
        min - the left edge of the domain you're interested in mimicking.
        max - the right edge of the domain you're interested in mimicking.
        functions - the number of functions/partitions the PiecewiseFunction should use.
        Returns:
        a function that resembles another function.
      • toString

        public String toString()
      • evaluate

        public double evaluate(double x)
        Description copied from interface: Function
        Evaluates f(x).
        Specified by:
        evaluate in interface  Function
        Parameters:
        x - the input for this function.
        Returns:
        the output of this function.
      • evaluateInverse

        public double[] evaluateInverse(double y)
        Description copied from interface: Function
        Returns all the x-values for the equation f(x) = y.
        Specified by:
        evaluateInverse in interface  Function
        Parameters:
        y - a possible output of this function.
        Returns:
        all the possible inputs that would map to the argument.
      • getFunction

        public Function getFunction(int index)
      • getFunctionCount

        public int getFunctionCount()
      • setFunction

        public void setFunction(int index,
                                Function f)