Package math.differentialcalculus
Class Parser
java.lang.Object
math.differentialcalculus.Parser
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
double
int
boolean
boolean
private Function
static void
static void
parseDerivativeCommand
(List<String> list) void
setDiffType
(int diffType) void
setOrderOfDifferentiation
(int orderOfDifferentiation)
-
Field Details
-
evalPoint
private double evalPointThe x coordinate at which the derivative is to be evaluated. -
function
TheFunction
object created from the command -
orderOfDifferentiation
private int orderOfDifferentiationThe number of times to differentiate the function. -
result
-
diffType
private int diffTypeThis is a very important field as it tells if the function is to be differentiated and the value of its derivative at a point evaluated, (This sets this field toGRAD_VAL
) or perhaps it should be differentiate and the gradient function itself returned (This sets this field toGRAD_FUNC
). The first type is for expressions of type diff(func,x1,x2) where x1 is the point at which the derivative is to be evaluated and x2 is the number of times the function should be differentiated before evaluating it at x1. The second type is for expressions of type diff(func,x1) where x1 is the number of times the function should be differentiated. -
GRAD_FUNC
public static final int GRAD_FUNC- See Also:
-
GRAD_VAL
public static final int GRAD_VAL- See Also:
-
-
Constructor Details
-
Parser
- Parameters:
expression
- The expression to parse. e.g. diff(@(x)cos(x)+5*x,6,1) or diff(F,6,1) where F is a function that has been previously defined in the workspace and so is in theFunctionManager
It may also take the form diff(@(x)cos(x)+5*x,6) or diff(F,6) where it assumes that the function is to be differentiated only once. In the future, we have diff(F) or (diff(@(x)cos(x)+5*x) which will return the gradient function itself.
-
-
Method Details
-
getEvalPoint
public double getEvalPoint() -
getFunction
-
getOrderOfDifferentiation
public int getOrderOfDifferentiation() -
setOrderOfDifferentiation
public void setOrderOfDifferentiation(int orderOfDifferentiation) -
getDiffType
public int getDiffType() -
setDiffType
public void setDiffType(int diffType) -
isGradFunc
public boolean isGradFunc() -
isGradEval
public boolean isGradEval() -
localParseDerivativeCommand
- Parameters:
list
- A list containing the scanned form of an expression containing information about the function whose derivative is to be evaluated and the point at which the derivative is to be evaluated. Common forms for the expression are: diff(@(x)sin(x),5)... diff(@(x)sin(x),5,2)... diff(y,5)... diff(y,5,2)... The first command means the function, sin(x) is to be differentiated wrt x, and evaluated at x = 5. The second command means the function, sin(x) is to be differentiated wrt x, twice and then evaluated at x = 5. The third command means that a function called y has been pre-defined. The parser will load the function and differentiate it wrt x, and then evaluate it at x = 5. The fourth command means that a function called y has been pre-defined. The parser will load the function and differentiate it wrt x, twice, and then evaluate it at x = 5. Direct examples would be: diff(@(x)sin(x+1),4) diff(F,5.32) where F is a function that has been defined before in the workspace.. and so on.- Returns:
- the Function object in the expression and in the process also discovers the point at which the derivative is to be evaluated.
-
parseDerivativeCommand
- Parameters:
list
- A list containing the scanned form of an expression containing information about the function whose derivative is to be evaluated and the point at which the derivative is to be evaluated. Common forms for the expression are: diff(@(x)sin(x),5)... diff(@(x)sin(x),5,2)... diff(y,5)... diff(y,5,2)... The first command means the function, sin(x) is to be differentiated wrt x, and evaluated at x = 5. The second command means the function, sin(x) is to be differentiated wrt x, twice and then evaluated at x = 5. The third command means that a function called y has been pre-defined. The parser will load the function and differentiate it wrt x, and then evaluate it at x = 5. The fourth command means that a function called y has been pre-defined. The parser will load the function and differentiate it wrt x, twice, and then evaluate it at x = 5. Direct examples would be: diff(@(x)sin(x+1),4) diff(F,5.32) where F is a function that has been defined before in the workspace.. and so on.
-
main
-