Class Function
java.lang.Object
com.github.gbenroscience.parser.Function
- All Implemented Interfaces:
Savable,MethodRegistry.MethodAction,Serializable
- Author:
- JIBOYE OLUWAGBEMIRO OLAOLUWA
- See Also:
-
Field Summary
Fields inherited from interface com.github.gbenroscience.parser.methods.MethodRegistry.MethodAction
serialVersionUID -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanassignAnonymousToNamedFunction(String fname, String anonFuncName) Assigns a stored anonymous function to become a named function.static booleanassignObject(String input, ErrorLog log) doublecalc()calc(MathExpression.EvalResult nextResult, int arity, MathExpression.EvalResult[] x) Allows methods like diff(fn,args) to differentiate an expression using the MethodRegistry interface Is the intersection between methods and user-defined functionsdoublecalcDet()copy()Creates a deep copy of this Function instance.booleaneval()evalArgs(double... args) Deprecated.doubleevalArgsTurbo(double... args) double[][]double[][]double[][]intgetArity()getIndependentVariable(String name) getName()static String[]getParameters(String paramList) getType()booleanbooleanstatic booleanstatic booleanisAnonymous(String name) static booleanisFunctionFullName(String str) booleanisMatrix()booleanstatic MatrixlistToMatrix(List<String> data) static voidstatic StringmatrixToCommaList(Matrix mat) matrixToList(Matrix mat) The input list is such that: The first 2 entries specify the number of rows and columns.intstatic Functionstatic voidprint2DArray(Object[][] obj) Prints the content of a 2D arrayvoidsetDependentVariable(Variable dependentVariable) voidsetIndependentVariables(ArrayList<Variable> independentVariables) voidsetMathExpression(MathExpression mathExpression) voidvoidsetTurboExpr(FastCompositeExpression turboExpr) voidstatic FunctionstoreAnonymousFunction(String expression) static StringstoreAnonymousMatrixFunction(Matrix matrix) toString()voidupdateArgs(double... x)
-
Constructor Details
-
Function
public Function() -
Function
- Parameters:
matrix- A Matrix to be used to initialize the function..
-
Function
- Parameters:
input- The user input into the system, usually of the form: F(x,y,z,w,....)=mathexpr; or F= @(x,y,z,w,...)mathexpr.....where mathexpr is an algebraic expression in terms of x,y,z,w,... OR JUST PLAIN- Throws:
InputMismatchException
-
-
Method Details
-
setType
-
getType
-
updateArgs
public void updateArgs(double... x) -
calc
public double calc()- Returns:
- the value of the function with these variables set.
-
calc
- 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.
-
calc
public MathExpression.EvalResult calc(MathExpression.EvalResult nextResult, int arity, MathExpression.EvalResult[] x) Description copied from interface:MethodRegistry.MethodActionAllows methods like diff(fn,args) to differentiate an expression using the MethodRegistry interface Is the intersection between methods and user-defined functions- Specified by:
calcin interfaceMethodRegistry.MethodAction- Parameters:
nextResult-arity- The number of argument to read from the args arrayx- The args passed to the function- Returns:
-
assignObject
-
assignAnonymousToNamedFunction
-
setTurboExpr
-
getTurboExpr
-
setDependentVariable
-
getDependentVariable
-
setMathExpression
-
getWideningArgsExpression
-
getArrayArgsExpression
-
setMatrix
-
getMathExpression
-
setIndependentVariables
-
getIndependentVariables
-
numberOfParameters
public int numberOfParameters()- Returns:
- the number of independent variables possessed by this Function object.
-
getArity
public int getArity() -
getMatrix
-
getIndependentVariable
-
hasIndependentVariable
- 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
-
isParam
- 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
-
storeAnonymousFunction
-
isMatrix
public boolean isMatrix() -
evalArgs
Deprecated.Deprecated this in favor ofevalArgs(double...)which is far faster due to direct passing of args- Parameters:
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)
-
evalArgs
-
evalArgsTurbo
public double evalArgsTurbo(double... args) -
evalRange
- 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 containsAlgebraicFunction the values that the Function object will have for all values specified for the range of the independent variable. The second array containsAlgebraicFunction the values that the independent variable will assume in its given range. If the rangeDescr parameter is not valid.. it returns a 2D array containing 2 null arrays.
-
evalRange
public double[][] evalRange(double xLower, double xUpper, double xStep, 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 containsAlgebraicFunction the values that the Function object will have for all values specified for the range of the independent variable. The second array containsAlgebraicFunction 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, String variableName, int DRG, boolean turbo) -
print2DArray
-
eval
- Returns:
- the value of the function based on assigned values of its variables and constants.
-
isFunctionFullName
- 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
-
isAnonymous
public boolean isAnonymous() -
isAnonymous
-
isAnonymous
-
equals
-
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
- 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
Otherwise it returns
invalid reference
Function#MATRIXDouble.NaN
-
calcInverse
- Returns:
- the inverse of the matrix-function if it is of type
Otherwise it returns null
invalid reference
Function#MATRIX
-
triangularMatrix
- Returns:
- the triangular Matrix of the function if it is of type
Otherwise it returns null
invalid reference
Function#MATRIX
-
reduceToEchelon
- Returns:
- the row-reduced echelon matrix of the function if it is of type
Otherwise it returns null
invalid reference
Function#MATRIX
-
expressionForm
- Returns:
- the sub-expression on the right hand side of the assignment '=' sign in the expression that created this Function object.
-
listToMatrix
- 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
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
-
copy
Creates a deep copy of this Function instance. Essential for thread-safe parallel integration. Each thread gets an independent Function with: - Same expression and parsed structure - Independent state variables - No shared mutable references- Returns:
- A new Function instance safe for concurrent use
-
parse
-
main
-
serialize
-
evalArgs(double...)which is far faster due to direct passing of args