Class RectangularFunc

java.lang.Object
net.algart.math.functions.RectangularFunc
All Implemented Interfaces:
Func

public final class RectangularFunc extends Object implements Func

Absolute value function: f(x0) = in if min<=x0<=max and f(x0) = out in other case, where min, max, in, out are parameters of this function. The get(double...) method of the instance of this class requires at least 1 argument and throws IndexOutOfBoundsException if the number of arguments is 0.

This class is immutable and thread-safe: there are no ways to modify settings of the created instance.

Author:
Daniel Alievsky
  • Method Details

    • getInstance

      public static RectangularFunc getInstance(Range range, double in, double out)
      Returns an instance of this class describing the rectangular function with the following parameters: range.min(), range.max(), in, out. The get method of the function will return in if range.contains(x0) and out otherwise.
      Parameters:
      range - the min and max parameters of this function.
      in - the value returned inside the range.
      out - the value returned outside the range.
      Returns:
      an instance of this class with the passed parameters.
      Throws:
      NullPointerException - if range is null.
    • getInstance

      public static RectangularFunc getInstance(double min, double max, double in, double out)
      Returns an instance of this class describing the rectangular function with the passed parameters. The get method of the function will return in if min<=x0<=max and out otherwise.
      Parameters:
      min - the minimum number in the range, inclusive.
      max - the maximum number in the range, inclusive.
      in - the value returned inside the range.
      out - the value returned outside the range.
      Returns:
      an instance of this class with the passed parameters.
      Throws:
      IllegalArgumentException - if min > max, min is NaN or max is NaN.
    • range

      public Range range()
      Returns min..max range, inside which this function returns in value.
      Returns:
      min..max range, specified while creating this instance.
    • in

      public double in()
      Returns the value, which is returned by this function inside min..max range.
      Returns:
      in value, specified while creating this instance.
    • out

      public double out()
      Returns the value, which is returned by this function outside min..max range.
      Returns:
      out value, specified while creating this instance.
    • get

      public double get(double... x)
      Description copied from interface: Func
      Returns the result of this function for the given arguments: f(x0, x1, ..., xx.length-1).

      This method must not change the values of x elements!

      Specified by:
      get in interface Func
      Parameters:
      x - the function arguments.
      Returns:
      the function result.
    • get

      public double get()
      Description copied from interface: Func
      Equivalent to get(new double[0]). Provides better performance because it does not require Java array creation.
      Specified by:
      get in interface Func
      Returns:
      the function result.
    • get

      public double get(double x0)
      Description copied from interface: Func
      Equivalent to get(new double[] {x0}). Provides better performance because it does not require Java array creation.
      Specified by:
      get in interface Func
      Parameters:
      x0 - the function argument.
      Returns:
      the function result.
    • get

      public double get(double x0, double x1)
      Description copied from interface: Func
      Equivalent to get(new double[] {x0, x1}). Provides better performance because it does not require Java array creation.
      Specified by:
      get in interface Func
      Parameters:
      x0 - the first function argument.
      x1 - the second function argument.
      Returns:
      the function result.
    • get

      public double get(double x0, double x1, double x2)
      Description copied from interface: Func
      Equivalent to get(new double[] {x0, x1, x2}). Provides better performance because it does not require Java array creation.
      Specified by:
      get in interface Func
      Parameters:
      x0 - the first function argument.
      x1 - the second function argument.
      x2 - the third function argument.
      Returns:
      the function result.
    • get

      public double get(double x0, double x1, double x2, double x3)
      Description copied from interface: Func
      Equivalent to get(new double[] {x0, x1, x2, x3}). Provides better performance because it does not require Java array creation.
      Specified by:
      get in interface Func
      Parameters:
      x0 - the first function argument.
      x1 - the second function argument.
      x2 - the third function argument.
      x3 - the fourth function argument.
      Returns:
      the function result.
    • toString

      public String toString()
      Returns a brief string description of this object.
      Overrides:
      toString in class Object
      Returns:
      a brief string description of this object.