コード例 #1
0
ファイル: FND.java プロジェクト: christinapanto/project
  /**
   * Evaluate a function at a specific point for one single variable. Evaluation is done between
   * xmin and xmax. It is assumed that there are no any other variable involved
   *
   * @param indvars Define independent variable, like 'x' Only one variable is allowed
   * @param xmin xmin value for independent varible
   * @param xmax xmax value for independent varible
   * @return true if no errors
   */
  public boolean eval(String indvars, double xmin, double xmax) {

    boolean suc = true;
    String name = proxy.getName();
    int points = proxy.getPoints();

    double min = xmin;
    double max = xmax;
    x = new double[points];
    y = new double[points];
    for (int i = 0; i < points; i++) {
      x[i] = min + i * (max - min) / (points - 1);
      jep.addVariable(indvars.trim(), x[i]);

      try {
        Object result = jep.evaluate(node);
        if (result instanceof Double) {
          y[i] = ((Double) jep.evaluate(node)).doubleValue();
        }
      } catch (ParseException e) {
        jhplot.utils.Util.ErrorMessage(
            "Failed to parse function " + name + " Error:" + e.toString());
        suc = false;
      }
    }

    if (suc) isEvaluated = true;

    return suc;
  } // end 1-D evaluation
コード例 #2
0
ファイル: FND.java プロジェクト: christinapanto/project
  /**
   * Evaluate a function at a specific point for one single variable. Evaluation is done between
   * xmin and xmax
   *
   * @param indvars Define independent variable, like 'x' Only one variable is allowed
   * @param xmin xmin value for independent varible
   * @param xmax xmax value for independent varible
   * @param vars define values for other variables, like 'y=1,z=3'
   * @return true if no errors
   */
  public boolean eval(String indvars, double xmin, double xmax, String vars) {
    String name = proxy.getName();
    int points = proxy.getPoints();
    boolean suc = true;
    String[] tmp = vars.split(",");
    // double[] vd = new double[tmp.length];
    fixedVars = vars;

    for (int i = 0; i < tmp.length; i++) {
      String[] vv = tmp[i].split("=");

      if (vv.length != 2) {
        ErrorMessage("Error in parsing list of input variablse. Did you use val=number? ");
      }

      try {
        double d = Double.valueOf(vv[1].trim()).doubleValue();
        jep.addVariable(vv[0].trim(), d);
      } catch (NumberFormatException nfe) {
        System.out.println("NumberFormatException: " + nfe.getMessage());
        suc = false;
      }
    }

    double min = xmin;
    double max = xmax;
    x = new double[points];
    y = new double[points];
    for (int i = 0; i < points; i++) {
      x[i] = min + i * (max - min) / (points - 1);
      jep.addVariable(indvars.trim(), x[i]);

      try {
        Object result = jep.evaluate(node);
        if (result instanceof Double) {
          y[i] = ((Double) jep.evaluate(node)).doubleValue();
        }
      } catch (ParseException e) {
        jhplot.utils.Util.ErrorMessage(
            "Failed to parse function " + name + " Error:" + e.toString());
        suc = false;
      }
    }

    if (suc) isEvaluated = true;

    return suc;
  } // end 1-D evaluation