Class Parser

java.lang.Object
math.differentialcalculus.Parser

public class Parser extends Object
  • Field Details

    • evalPoint

      private double evalPoint
      The x coordinate at which the derivative is to be evaluated.
    • function

      private Function function
      The Function object created from the command
    • orderOfDifferentiation

      private int orderOfDifferentiation
      The number of times to differentiate the function.
    • result

      public Parser_Result result
    • diffType

      private int diffType
      This 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 to GRAD_VAL) or perhaps it should be differentiate and the gradient function itself returned (This sets this field to GRAD_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

      public Parser(String expression)
      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 the FunctionManager 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

      public Function 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

      private Function localParseDerivativeCommand(List<String> list)
      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

      public static void parseDerivativeCommand(List<String> list)
      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

      public static void main(String[] args)