예제 #1
0
  /**
   * Create a function in any dimension evaluation.
   *
   * <p>The function may have many independent variables.
   *
   * <p>
   *
   * <h3>List of commands</h3>
   *
   * <ul>
   *   <li>( ) parenthesis , comma
   *   <li>+, -, unary -, unary +
   *   <li>*, /
   *   <li>^ (raise to a power)
   *   <li>pi, e, All the constants in class SpecialFunction
   *   <li>log
   *   <li>sin, cos, tan, sinh, cosh, tanh
   *   <li>asin, acos, atan, asinh, acosh, atanh
   *   <li>sqrt
   *   <li>rand
   *   <li>exp
   *   <li>remainder
   *   <li>atan2
   *   <li>Special functions and constants. Look at the book
   *   <li>All the functions in class SpecialFunction
   *   <li>Independent variables x
   *   <li>Scientific notation using "e", "E", "d", "D".
   * </ul>
   *
   * @prama title Title of the function
   * @param name String representing the function
   * @param vars String representing variables. Each variable should be separated by a comma.
   *     Example "x,y,z"
   */
  public FND(String title, String name, String vars) {

    this.title = title;
    proxy = new FProxy(3, title, name, null, new double[] {0, 0, 0, 0, 0, 0}, maxpoints, true);

    name = proxy.getName();
    proxy.setVariables(vars);
    setTitle(title);
    lpp.setType(LinePars.F1D);
    jep = new XJep();
    jep.addStandardConstants();
    jep.addStandardFunctions();
    jep.setAllowUndeclared(true);
    jep.setImplicitMul(true);
    jep.setAllowAssignment(true);

    // get all variables
    avars = vars.split(",");
    for (int i = 0; i < avars.length; i++) {
      jep.addVariable(avars[i].trim(), 0);
    }

    jep.addVariable("x", 0);

    try {
      node = jep.parse(name);
      processed = jep.preprocess(node);
    } catch (ParseException e) {
    } catch (Exception e) {
      ErrorMessage("Error in parsing " + name);
    }
  }
예제 #2
0
  /**
   * Initialize function from proxy.
   *
   * @param f
   */
  public FND(FProxy f) {
    proxy = f;
    String name = proxy.getName();
    if (proxy.getType() != 4) {
      ErrorMessage("Error in parsing FND. Wrong type! " + name);
      return;
    }

    setTitle(proxy.getTitle());
    lpp.setType(LinePars.F1D);
    jep = new XJep();
    jep.addStandardConstants();
    jep.addStandardFunctions();
    jep.setAllowUndeclared(true);
    jep.setImplicitMul(true);
    jep.setAllowAssignment(true);

    // get all variables
    String vars = proxy.getVariables();
    avars = vars.split(",");
    for (int i = 0; i < avars.length; i++) {
      jep.addVariable(avars[i].trim(), 0);
    }

    jep.addVariable("x", 0);

    try {
      node = jep.parse(name);
      processed = jep.preprocess(node);
    } catch (ParseException e) {
    } catch (Exception e) {
      ErrorMessage("Error in parsing " + name);
    }
  }