Documentation of 'jhplot.F2D' Java class.
F2D
jhplot

Class F2D

  • All Implemented Interfaces:
    java.io.Serializable


    public class F2D
    extends DrawOptions
    Create 2D function. The function may have up to 2 independent variables: x,y.

    One can enabled fast math calculation using @see jhplot.HParam. For example, setting jhplot.HParam.setMath(true) makes calculation of elementary functions a factot 4-5 faster than using the standard Java Math, with precision of E-14.

    Operators and functions

    the following operators are supported:
    • Addition: '2 + 2'
    • Subtraction: '2 - 2'
    • Multiplication: '2 * 2'
    • Division: '2 / 2'
    • Exponential: '2 ^ 2' or ** (raise to a power)
    • Unary Minus,Plus (Sign Operators): '+2 - (-2)'
    • Modulo: '2 % 2'
    the following functions are supported:
    • abs: absolute value
    • acos: arc cosine
    • asin: arc sine
    • atan: arc tangent
    • cbrt: cubic root
    • ceil: nearest upper integer
    • cos: cosine
    • cosh: hyperbolic cosine
    • exp: euler's number raised to the power (e^x)
    • floor: nearest lower integer
    • log: logarithm natural (base e)
    • log10: logarithm (base 10)
    • sin: sine
    • sinh: hyperbolic sine
    • sqrt: square root
    • tan: tangent
    • tanh: hyperbolic tangent
    It also recognizes the pi (or Pi) values.
    See Also:
    Serialized Form
    • Constructor Detail

      • F2D

        public F2D(java.lang.String name)
        Create a function in 2D for evaluation. The function is not in range. The function may have up to 2 independent variables: x,y.

        Operators and functions

        the following operators are supported:

        • Addition: '2 + 2'
        • Subtraction: '2 - 2'
        • Multiplication: '2 * 2'
        • Division: '2 / 2'
        • Exponential: '2 ^ 2' or ** (raise to a power)
        • Unary Minus,Plus (Sign Operators): '+2 - (-2)'
        • Modulo: '2 % 2'
        the following functions are supported:
        • abs: absolute value
        • acos: arc cosine
        • asin: arc sine
        • atan: arc tangent
        • cbrt: cubic root
        • ceil: nearest upper integer
        • cos: cosine
        • cosh: hyperbolic cosine
        • exp: euler's number raised to the power (e^x)
        • floor: nearest lower integer
        • log: logarithm natural (base e)
        • sin: sine
        • sinh: hyperbolic sine
        • sqrt: square root
        • tan: tangent
        • tanh: hyperbolic tangent
        It also recognizes the pi (or Pi) values.
        Parameters:
        name - String representing the function
      • F2D

        public F2D(java.lang.String title,
                   java.lang.String name)
        Create new function.
        Parameters:
        title - title
        name - definition
      • F2D

        public F2D(java.lang.String title,
                   java.lang.String name,
                   double Xmin,
                   double Xmax,
                   double Ymin,
                   double Ymax)
        Create a function in 2D. This is a ranged function. Uses 200 points between min and max value for evaluation. The function may have up to 2 independent variables in it (x,y). Operators and functions

        the following operators are supported:
        • Addition: '2 + 2'
        • Subtraction: '2 - 2'
        • Multiplication: '2 * 2'
        • Division: '2 / 2'
        • Exponential: '2 ^ 2' or ** (raise to a power)
        • Unary Minus,Plus (Sign Operators): '+2 - (-2)'
        • Modulo: '2 % 2'
        the following functions are supported:
        • abs: absolute value
        • acos: arc cosine
        • asin: arc sine
        • atan: arc tangent
        • cbrt: cubic root
        • ceil: nearest upper integer
        • cos: cosine
        • cosh: hyperbolic cosine
        • exp: euler's number raised to the power (e^x)
        • floor: nearest lower integer
        • log: logarithm natural (base e)
        • sin: sine
        • sinh: hyperbolic sine
        • sqrt: square root
        • tan: tangent
        • tanh: hyperbolic tangent
        Parameters:
        name - String representing the function.
        Xmin - Min value in X
        Xmax - Max value in X
        Ymin - Min value in Y
        Ymax - Max value in Y
      • F2D

        public F2D(java.lang.String name,
                   double Xmin,
                   double Xmax,
                   double Ymin,
                   double Ymax)
        Build a 2D function. Title is set to the name. This is ranged function.
        Parameters:
        name - Name
        Xmin - X-min
        Xmax - X-max
        Ymin - Y-min
        Ymax - Y-max
      • F2D

        public F2D(java.lang.String title,
                   IFunction iname,
                   double Xmin,
                   double Xmax,
                   double Ymin,
                   double Ymax)
        Create a F2D function from JAIDA IFunction. By default, 500 points for evaluation are used. Ranged function.
        Parameters:
        title - Title
        name - new function name
        iname - input IFunction
        Xmin - Min X value
        Xmax - Max X value
        Ymin - Min Y value
        Ymax - Max Y value
      • F2D

        public F2D(java.lang.String title,
                   Expression calc,
                   double Xmin,
                   double Xmax,
                   double Ymin,
                   double Ymax)
        Create a function in 2D. 500 points are used between Min and Max for evaluation. The function may have x as independent variable. Make sure that expression has 2 variables, x and y.
        Parameters:
        title - Title
        function - Expression after parsing and building
        Xmin - Min X value
        Xmax - Max X value
        Ymin - Min Y value
        Ymax - Max Y value
      • F2D

        public F2D(Expression calc,
                   double Xmin,
                   double Xmax,
                   double Ymin,
                   double Ymax)
        Create a function in 2D. 200 points are used between Min and Max for evaluation. The function may have x as independent variable. Make sure that expression has 2 variables, x and y.
        Parameters:
        title - Title
        function - Expression after parsing and building
        Xmin - Min X value
        Xmax - Max X value
        Ymin - Min Y value
        Ymax - Max Y value
      • F2D

        public F2D(IFunction iname)
        Create a F2D function from JAIDA IFunction. By default, 500 points for evaluation are used. Unranged function.
        Parameters:
        iname -
      • F2D

        public F2D(FProxy f)
        Initialize function from proxy.
        Parameters:
        f -
      • F2D

        public F2D(IFunction iname,
                   double Xmin,
                   double Xmax,
                   double Ymin,
                   double Ymax)
        Create a F2D function from JAIDA IFunction.
        Parameters:
        iname - input IFunction
        Xmin - Min X value
        Xmax - Max X value
        Ymin - Min Y value
        Ymax - Max Y value
    • Method Detail

      • eval

        public double eval(double x,
                           double y)
        Evaluate a function at a specific point in (x,y)
        Parameters:
        x - value in x for evaluation
        y - value in y for evaluation
        Returns:
        function value at (x,y)
      • getIFunction

        public IFunction getIFunction()
        Get Jaida function
        Returns:
      • eval

        public double[][] eval(double[] x,
                               double[] y)
        Evaluate a function for an array of x-values
        Parameters:
        x - array of values in x for evaluation
        y - array of values in y for evaluation
        Returns:
        array of function values
      • setMinX

        public void setMinX(double min)
        Set Min in X
        Parameters:
        min - Min value
      • parse

        public boolean parse()
        Parse the function.
        Returns:
        true if parsed without problems.
      • getMinX

        public double getMinX()
        Get Min value in X
        Returns:
        Min value in X
      • setMinY

        public void setMinY(double min)
        Set Min value in Y
        Parameters:
        min - Min value in Y
      • doc

        public void doc()
        Show online documentation.
      • getMinY

        public double getMinY()
        Get Min value in Y
        Returns:
        Min value in Y
      • setMaxX

        public void setMaxX(double max)
        Set Max value in X
        Parameters:
        max - Max value in X
      • setName

        public void setName(java.lang.String name)
        Sets a name of the function, i.e. what will be used for evaluation
        Parameters:
        name - Name
      • getName

        public java.lang.String getName()
        Get the name of the function used for evaluation
        Returns:
        Name
      • getMaxX

        public double getMaxX()
        Get Max value in X
        Returns:
        Max value in X
      • setMaxY

        public void setMaxY(double max)
        Set Max value in Y
        Parameters:
        max - Max value in Y
      • getMaxY

        public double getMaxY()
        Get Max value in Y
        Returns:
        Max value in Y
      • setPoints

        public void setPoints(int bins)
        Set the number of points
        Parameters:
        bins - Number of points
      • setPar

        public void setPar(java.lang.String parameter,
                           double value)
        Replace abstract parameter with the value (double). Case sensitive!
        Parameters:
        parameter - parameter name
        value - value to be inserted
      • getPoints

        public int getPoints()
        Get the number of points for evaluation of a function
        Returns:
        Number of points
      • integral

        public double integral(int N,
                               double minX,
                               double maxX,
                               double minY,
                               double maxY)
        Numerical integration using trapezium rule.
        Parameters:
        N - the number of strips to use for integration (in X and Y the same)
        minX - the first ordinate in X.
        maxX - the last ordinate in X.
        minY - the first ordinate in X.
        maxY - the last ordinate in Y.
        Returns:
        integral
      • integral

        public double integral(double minX,
                               double maxX,
                               double minY,
                               double maxY)
        Integral using fastest trapezium rule method. It uses the default number of points (500).
        Parameters:
        minX - the first ordinate in X.
        maxX - the last ordinate in X.
        minY - the first ordinate in X.
        maxY - the last ordinate in Y.
      • simplify

        public boolean simplify()
        Try to simplify this function. It is often useful to rewrite an expression in term of elementary functions (log, exp, frac, sqrt, implicit roots), using the "elementary()" before simplifying it. Retrieve the simplified name as a string using getName() method.
        Returns:
        false if error occurs. Retrieve this error as a string using getException().
      • getException

        public java.lang.String getException()
        If error occurs at some step, this is the way to retrieve it.
        Returns:
        last exception happened in any method of this class.
      • getParse

        public Expression getParse()
        Return parsed function. One can evaluate it as "calculate()".
        Returns:
        function
      • getH2D

        public H2D getH2D(java.lang.String hname,
                          int hbinX,
                          double hminX,
                          double hmaxX,
                          int hbinY,
                          double hminY,
                          double hmaxY)
        Generate a 2D histogram from the F2D function using a custom number of bins and given min and max values.
        Parameters:
        hname - histogram name
        hbinX - number of X bins
        hminX - min value in X
        hmaxX - max value in X
        hbinY - number of bins in Y
        hminY - min value in Y
        hmaxY - max value in Y
        Returns:
        2D histogram from the function
      • integral

        public double integral()
        Integral using fastest trapezium rule method. This function return non-zero if it the range was defined during the initialization. The default number of points is 500. Increase it if needed more precision.
        Returns:
        integral in the range defined during the initialization.
      • integral

        public double integral(int xSegs,
                               int ySegs,
                               double minX,
                               double maxX,
                               double minY,
                               double maxY)
        Finds the volume under the surface described by the function f(x, y) for a <= x <= b, c <= y <= d. It uses the trapezoid rule. Using xSegs number of segments across the x axis and ySegs number of segments across the y axis.
        Parameters:
        xSegs - The number of segments in the x axis.
        ySegs - The number of segments in the y axis.
        minX - The lower bound of x.
        maxX - The upper bound of x.
        minX - The lower bound of y.
        maxY - The upper bound of y.
        Returns:
        The volume under the function f(x, y).
      • isParsed

        public boolean isParsed()
        If the function is parsed correctly, return true. Use this check before drawing it.
        Returns:
        true if parsed.
      • toMathML

        public java.lang.String toMathML()
        Convert the function into MathML form.
        Returns:
        String representing this function in MathML.
      • toJava

        public java.lang.String toJava()
        Convert the function into Java code.
        Returns:
        String representing this function in Java.
      • elementary

        public boolean elementary()
        Convert this function rewrite in term of elementary functions (log, exp, frac, sqrt, implicit roots) This is useful before simplifying function. Retrieve the simplified name as a string using getName() method.
        Returns:
        false if error occurs. Retrieve this error as a string using getException().
      • expand

        public boolean expand()
        Convert this function rewrite in expanded form. Retrieve the expanded name as a string using getName() method.
        Returns:
        false if error occurs. Retrieve this error as a string using getException().
      • factorize

        public boolean factorize()
        Convert this function rewrite in factorized form (if can). Retrieve the expanded name as a string using getName() method.
        Returns:
        false if error occurs. Retrieve this error as a string using getException().
      • numeric

        public boolean numeric()
        Perform some numeric substitutions. Examples: exp(1) should be 2.71828182, "pi" should be 3.14159 etc. Retrieve the expanded name as a string using getName() method.
        Returns:
        false if error occurs. Retrieve this error as a string using getException().
      • get

        public FProxy get()
        Get the proxy of this function used for serialization and non-graphical representations.
        Parameters:
        proxy - proxy of this function.
      • toString

        public java.lang.String toString()
        Get this function as a string.
        Overrides:
        toString in class java.lang.Object
        Returns:
        Convert to string.

DMelt 3.0 © DataMelt by jWork.ORG