Documentation of 'jhplot.F1D' Java class.
F1D
jhplot

Class F1D

  • All Implemented Interfaces:
    java.io.Serializable


    public class F1D
    extends DrawOptions
    Create a function in one dimension using "x" as a variable. The function name could have parameters named in unique way as P0, P1, P2. In this case, the function should not be parsed. Parameters have to be replaced with values using setPar(x) method for evaluation.

    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.

    The function may have one independent variable: x

    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

      • F1D

        public F1D(java.lang.String name)
        Create a function in 1D. 500 points are used between Min and Max for evaluation. The title is set to the function's definition.

        A function can be ranged (range min and max is included) or unranged (min and max are not defined). Ranged function determines the plot ranges, integration range etc. The function may have one independent variable: x. Example: x*x 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's definition
      • F1D

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

        public F1D(java.lang.String title,
                   java.lang.String name)
        Create new function. The function is unranged (nor range is defined).
        Parameters:
        title - title
        name - definition
      • F1D

        public F1D(java.lang.String title,
                   java.lang.String name,
                   double min,
                   double max)
        Create a new function. Do not parse it when using parameters. You should apply substitution first and create a function with one variable "x". If min=0 and max=0, the ranges are determined by plotting canvases. The function is ranged. The function is parsed. The function may have one independent variable: x

        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 10 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:
        title - title
        name - definition
        min - minimum value for plotting
        max - maximum value for plotting
      • F1D

        public F1D(java.lang.String name,
                   double min,
                   double max,
                   boolean parsed)
        Define a ranged function.
        Parameters:
        name - name
        min - min value
        max - max value
        parsed - is parsed?
      • F1D

        public F1D(java.lang.String title,
                   IFunction iname,
                   double min,
                   double max)
        Create F1D function from JAIDA IFunction. By default 500 points are used. The function is ranged.
        Parameters:
        title - Title
        iname - input IFunction
        min - Min X values
        max - Max X values
      • F1D

        public F1D(java.lang.String title,
                   java.lang.String name,
                   double min,
                   double max,
                   boolean parse)
        Create a new function. Do not parse it when using parameters. You should apply substitution first and create a function with one variable "x". If min=0 and max=0, the ranges are determined by plotting canvases. The function is ranged. The function may have one independent variable: x

        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 10 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:
        title - title
        name - definition
        min - minimum value for plotting
        max - maximum value for plotting
        parse - parse or not. Do not parse when using parameters.
      • F1D

        public F1D(IFunction iname,
                   double min,
                   double max)
        Create a F1D function from JAIDA IFunction in ranges. By default, 500 points for evaluation are used
        Parameters:
        iname - input IFunction
        min - Min value
        max - Max value
      • F1D

        public F1D(java.lang.String name,
                   double min,
                   double max)
        Create a new function in pre-defined range for plotting. Do not parse it when using parameters. You should apply substitution first and create a function with one variable "x". If min=0 and max=0, ranges are determined by plotting canvaces. The function may have one independent variable: x

        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 10 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 - definition
        min - min value for plotting
        max - max value for plotting
        parse - parse or not. Do not parse when using parameters.
      • F1D

        public F1D(java.lang.String title,
                   java.lang.String name,
                   boolean parsed)
        Create a new function in pre-defined range for plotting. Do not parse it when using parameters. You should apply substitution first and create a function with one variable "x". Ranges for the function are not defined. The function may have one independent variable: x

        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 10 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:
        title - title
        name - definition
        parse - parse or not. Do not parse when using parameters.
      • F1D

        public F1D(java.lang.String title,
                   double[] pars,
                   boolean parse)
        Create a polynomial analytical function using a list of values. Example: pars[0]+pars[1]*x+pars[2]*x*x +pars[3]*x*x*x
        Parameters:
        title - Title of this function
        pars - array of coefficients for polynomial function
        parse - set true if it should be parsed
      • F1D

        public F1D(java.lang.String name,
                   boolean parse)
        Build a function. The function may have one independent variable: x. Function can have parameters, in which case set parsing to false. You can parse this function later after substitution of numeric parameter.

        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 - name
        parse - is parsed or not?
      • F1D

        public F1D(java.lang.String title,
                   ExpressionBuilder function)
        Create a function in 1D. 500 points are used between Min and Max for evaluation. The function may have x as independent variable.
        Parameters:
        title - Title
        function - ExpressionBuilder
        min - Min value
        max - Max value
      • F1D

        public F1D(Expression calc,
                   double min,
                   double max)
        Create a function from the expression. The function is in the range.
        Parameters:
        calc - expression
        min - Min value
        max - Max value
      • F1D

        public F1D(java.lang.String title,
                   Expression calc,
                   double min,
                   double max)
        Create a function in 1D. 500 points are used between Min and Max for evaluation. The function may have x as independent variable.
        Parameters:
        title - Title
        function - Expression after parsing and building
      • F1D

        public F1D(java.lang.String title,
                   Expression calc)
        Create a function in 1D. 500 points are used between Min and Max for evaluation. The function may have x as independent variable.
        Parameters:
        title - Title
        function - Expression after parsing and building
      • F1D

        public F1D(Expression calc)
        Create a function in 1D. The function may have x as independent variable.
        Parameters:
        function - expression
      • F1D

        public F1D(ExpressionBuilder function)
        Build a function.
        Parameters:
        function - input of expression
      • F1D

        public F1D(IFunction iname)
        Create a F1D function from JAIDA IFunction. By default, 500 points for evaluation are used. No ranges are set.
        Parameters:
        iname - input IFunction
      • F1D

        public F1D(java.lang.String title,
                   IFunction iname)
        Create F1D function from JAIDA IFunction. By default 500 points are used
        Parameters:
        title - Title
        iname - input IFunction
        min - Min X values
        max - Max X values
    • Method Detail

      • get

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

        public boolean parse()
        Parse the function. To speed up calculation of repertitive tasks, you can parse the function first.
        Returns:
        true if parsed without problems.
      • eval

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

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

        public void eval(double xMin,
                         double xMax)
        Evaluate a function for graphic representation. Number of points for evaluations is 500.
        Parameters:
        XMin - value in x
        XMax - value in x
      • eval

        public void eval()
        Evaluate a function for graphic representation. The function is assumed to me ranged (the range is defined during the initialization).
      • eval

        public void eval(double min,
                         double max,
                         int Npoints)
        Evaluate a function for graphic representation. Number of points for evaluations is 500.
        Parameters:
        Min - value in x
        Max - value in x
        Number - of evaluation points
      • doc

        public void doc()
        Show online documentation.
      • toTable

        public void toTable()
        Print the F1D function to a Table in a separate Frame. The numbers are formatted to scientific format. One can sort and search the data in this table (data cannot be modified)
        Parameters:
        min -
        max -
      • 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
      • getH1D

        public H1D getH1D()
        Return H1D histogram from F1D function. The number of points are given by setPoints() method, but the default 500 is used if not given. Min and Max values are given during the function initialisation (ranged function) The number of points is 500 by default.
        Returns:
        histogram
      • getH1D

        public H1D getH1D(double min,
                          double max)
        Return H1D histogram from F1D function. The number of points are given by setPoints() method, but the default 500 is used if not given. Min and Max values are given by the values used to parse the function.
        Parameters:
        min - value
        max - value
        Returns:
        histogram
      • getH1D

        public H1D getH1D(java.lang.String hname,
                          int bins,
                          double hmin,
                          double hmax)
        Return a Histogram given by the F1D function. All statistical characteristics of such histogram are meaningless. Bins and Min and Max values are user defined. The function is evaluated at the bin center which is important for small number of bins.
        Parameters:
        hname - Name of the histogram
        bins - number of bins for histogram
        hmin - min value of histogram
        hmax - max value of histogram
        Returns:
        H1D histogram
      • setPar

        public void setPar(java.lang.String parameter,
                           int value)
        Replace abstract parameter with the value (integer). Case sensitive. You will need to call parse() to finish this function.
        Parameters:
        parameter - parameter name
        value - integer value to be inserted.
      • getX

        public double getX(int i)
        Get value in X-axis
        Parameters:
        i - index
        Returns:
        value in X
      • getY

        public double getY(int i)
        Get value in Y-axis
        Parameters:
        i - index
        Returns:
        value in Y
      • 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
      • getParse

        public Expression getParse()
        Return parsed function. One can evaluate Y as: y =function.getResult(x), where function is what returned by this method.
        Returns:
        function
      • setPoints

        public void setPoints(int bins)
        Sets the number points between Min and Max for evaluation
        Parameters:
        bins - Number of points
      • 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 pecision.
        Returns:
        integral in the range defined during the initisliazation.
      • integral

        public double integral(double min,
                               double max)
        Integral using fastest trapezium rule method. It uses the default number of points (500).
        Parameters:
        min - the first ordinate.
        max - the last ordinate.
      • integral

        public double integral(java.lang.String type,
                               int N,
                               double min,
                               double max)
        Numerical integration. Define types as:
        type="gauss4" - Gaussian integration formula (4 points)
        type="gauss8" - Gaussian integration formula (8 points)
        type="richardson" - Richardson extrapolation
        type="simpson" - using Simpson's rule.
        type="trapezium" - trapezium rule.
        Parameters:
        type - type of algorithm. Can be: "gauss4","gauss8","richardson","simpson","trapezium".
        N - the number of strips to use for integration
        min - the first ordinate.
        max - the last ordinate.
        Returns:
        integral
      • integral

        public double integral(int N,
                               double min,
                               double max)
        Numerical integration using trapezium rule.
        Parameters:
        N - the number of strips to use for integration
        min - the first ordinate.
        max - the last ordinate.
        Returns:
        integral
      • getIFunction

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

        public double[] getArrayX()
        Get array of X-values after function after evaluation using the default number of points
        Returns:
        X-values
      • getArrayY

        public double[] getArrayY()
        Get array of Y-values after function after evaluation using the default number of points
        Returns:
        Y-values
      • 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.
      • 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().
      • 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().
      • differentiate

        public double[] differentiate(int N,
                                      double min,
                                      double max)
        Numerical differentiation.
        Parameters:
        N - the number of points to use.
        min - the first ordinate.
        max - the last ordinate.
        Returns:
        array with differentials
      • differentiate

        public double[] differentiate()
        Numerical differentiation of a function. Range of the function is given during the initisalisation (ranged function)
        Returns:
        array with differentials
      • getPoints

        public int getPoints()
        Get the number of points used for plotting, integration and differentiation.
        Returns:
        Number of points
      • 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.
      • setMin

        public void setMin(double min)
        Set Min value in X
        Parameters:
        min - Minimum value
      • getMin

        public double getMin()
        Get the minimum value in X
        Returns:
        min Minimum value
      • setMax

        public void setMax(double max)
        Set the maximum value in X
        Parameters:
        max - Maximal value
      • set

        public void set(FProxy f)
        Set proxy function
        Parameters:
        f -
      • getMax

        public double getMax()
        Get the maximum value in X
        Returns:
        Maximal value
      • 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