Package parser

Class Function


  • public class Function
    extends java.lang.Object
    Author:
    JIBOYE OLUWAGBEMIRO OLAOLUWA
    • Constructor Detail

      • Function

        public Function​(Matrix matrix)
        Parameters:
        matrix - A Matrix to be used to initialize the function..
      • Function

        public Function​(java.lang.String input)
        Parameters:
        input - The user input into the system, usually of the form: F(x,y,z,w,....)=mathexpr;..where mathexpr is an algebraic expression in terms of x,y,z,...
    • Method Detail

      • setType

        public void setType​(int type)
      • getType

        public int getType()
      • calc

        public double calc​(double... x)
        Parameters:
        x - A list of variable values to set for the function. The supplied value list is applied to the function's parameter list in the order they were supplied in the original question.
        Returns:
        the value of the function with these variables set.
      • assignObject

        public static boolean assignObject​(java.lang.String input)
      • setDependentVariable

        public void setDependentVariable​(Variable dependentVariable)
      • getDependentVariable

        public Variable getDependentVariable()
      • setMathExpression

        public void setMathExpression​(MathExpression mathExpression)
      • setIndependentVariables

        public void setIndependentVariables​(java.util.ArrayList<Variable> independentVariables)
      • getIndependentVariables

        public java.util.ArrayList<Variable> getIndependentVariables()
      • numberOfParameters

        public int numberOfParameters()
        Returns:
        the number of independent variables possessed by this Function object.
      • getMatrix

        public Matrix getMatrix()
      • getIndependentVariable

        public Variable getIndependentVariable​(java.lang.String name)
        Parameters:
        name - The name of the variable.
        Returns:
        the Variable if it exists in the parameter list of this Function. Returns null if no Variable having that name is to be found in the parameter list of this Function.
      • hasIndependentVariable

        public boolean hasIndependentVariable​(java.lang.String var)
        Parameters:
        var - The name of the Variable to check.
        Returns:
        true if this object has an independent variable that goes by the given name.
      • getParameters

        public static java.lang.String[] getParameters​(java.lang.String paramList)
        Parameters:
        paramList - A string containing info. about the arguments to be passed to the Function. The format is (var1,var2,var3,....)
        Returns:
        an array containing the parameters, if its format is valid.
      • isParam

        public boolean isParam​(java.lang.String name)
        Parameters:
        name - The name of the Variable object to check, whether or not it is a parameter of this Function object.
        Returns:
        true if a Variable of the specified name exists in the parameter list of this Function object.
      • storeAnonymousMatrixFunction

        public static java.lang.String storeAnonymousMatrixFunction​(Matrix matrix)
        Parameters:
        matrix - The Matrix object to be wrapped in a function
        Returns:
        the name assigned to the anonymous function created.
      • evalArgs

        public java.lang.String evalArgs​(java.lang.String args)
        Returns:
        the value of a function when valid arguments are passed into its parentheses. e.g if the fullname of the Function is f(x,y,c), this method could be passed..f(3,-4,9)
      • evalRange

        public java.lang.String[][] evalRange​(java.lang.String rangeDescr)
        Parameters:
        rangeDescr - Describes the range between which this Function object should be plotted. e.g. x:-10:10:0.0001
        Returns:
        an 2D array containing two 1d arrays. The first array contains the values that the Function object will have for all values specified for the range of the independent variable. The second array contains the values that the independent variable will assume in its given range. If the rangeDescr parameter is not valid.. it returns a2D array containing 2 null arrays.
      • evalRange

        public double[][] evalRange​(double xLower,
                                    double xUpper,
                                    double xStep,
                                    java.lang.String variableName,
                                    int DRG)
        Parameters:
        xLower - The lower limit from which plotting begins.
        xUpper - The upper limit from which plotting begins.
        xStep - The plot step.
        variableName - The name of the independent(the horizontal axis variable..usually x)
        DRG - States whether the function should be evaluated in Degrees, Radians, and Grad.
        Returns:
        an 2D array containing two 1d arrays. The first array contains the values that the Function object will have for all values specified for the range of the independent variable. The second array contains the values that the independent variable will assume in its given range. If the rangeDescr parameter is not valid.. it returns a2D array containing 2 null arrays.
      • print2DArray

        public static void print2DArray​(java.lang.Object[][] obj)
        Prints the content of a 2D array
      • eval

        public java.lang.String eval()
        Returns:
        the value of the function based on assigned values of its variables and constants.
      • isFunctionFullName

        public static boolean isFunctionFullName​(java.lang.String str)
        Parameters:
        str - The input string to check if or not it is of the format of the full name of a Function. e.g. F(x),p(x,y) e.t.c.
        Returns:
        true if the input string has the format of the full name of a Function. This method will be used to identify when the input into a calculator is to be treated as a Function problem...i.e. identify when the user is trying to create or modify a Function. F(x,y,x1,c,e3,u)
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
        Returns:
        the standard math form of this Function object.
      • isAnonymous

        public boolean isAnonymous()
      • isAnonymous

        public static boolean isAnonymous​(Function f)
      • isAnonymous

        public static boolean isAnonymous​(java.lang.String name)
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • getFullName

        public java.lang.String getFullName()
        Returns:
        the dependent variable together with its independent variables within its circular parentheses. e.g if the Function is y=x^2, this method will return y(x)
      • getName

        public java.lang.String getName()
        Returns:
        the simple name of the function. e.g if the function is y=@(x)cos(x), then this method returns 'y'.
      • calcDet

        public double calcDet()
        Returns:
        the determinant of the function if it is of type MATRIX Otherwise it returns Double.NaN
      • calcInverse

        public Matrix calcInverse()
        Returns:
        the inverse of the matrix-function if it is of type MATRIX Otherwise it returns null
      • triangularMatrix

        public Matrix triangularMatrix()
        Returns:
        the triangular Matrix of the function if it is of type MATRIX Otherwise it returns null
      • reduceToEchelon

        public Matrix reduceToEchelon()
        Returns:
        the row-reduced echelon matrix of the function if it is of type MATRIX Otherwise it returns null
      • expressionForm

        public java.lang.String expressionForm()
        Returns:
        the sub-expression on the right hand side of the assignment '=' sign in the expression that created this Function object.
      • listToMatrix

        public static Matrix listToMatrix​(java.util.List<java.lang.String> data)
        Parameters:
        data - The input list The input list is such that: The first 2 entries specify the number of rows and columns. The remaining entries are the Matrix's entries.
        Returns:
        a number list which represents the row-reduced echelon Matrix that the entries reduce to.
      • matrixToList

        public static java.util.List<java.lang.String> matrixToList​(Matrix mat)
        The input list is such that: The first 2 entries specify the number of rows and columns. The remaining entries are the Matrix's entries.
        Returns:
        a list containing the data of the Matrix. This list does not contain the dimensions of the Matrix, only the data.
      • matrixToCommaList

        public static java.lang.String matrixToCommaList​(Matrix mat)
        Parameters:
        mat - The Matrix object
        Returns:
        a comma separated string containing the data of the Matrix. This string does not contain the dimensions of the Matrix, only the data.
      • parse

        public static Function parse​(java.lang.String json)
      • main

        public static void main​(java.lang.String[] args)