Example #1
0
static int
show_user_equation(struct fitlocal *fitlocal, const char *func, MathValue *par, int disp)
{
  int i, prev_char;
  GString *equation;

  equation = g_string_sized_new(256);
  if (equation == NULL) {
    return 1;
  }

  prev_char = '\0';
  for (i = 0; func[i] != '\0'; i++) {
    double val;
    char *format;
    int prm_index;

    switch (func[i]) {
    case '%':
      if (isdigit(func[i + 1]) && isdigit(func[i + 2]) && isdigit(func[i + 3])) {
	prm_index = (func[i + 1] - '0') * 100 + (func[i + 2] - '0') * 10 + (func[i + 3] - '0');
	i += 3;
      } else if (isdigit(func[i + 1]) && isdigit(func[i + 2])) {
	prm_index = (func[i + 1] - '0') * 10 + (func[i + 2] - '0');
	i += 2;
      } else {
	prm_index = (func[i + 1] - '0');
	i += 1;
      }

      val = par[prm_index].val;
      switch (prev_char) {
      case '-':
	val = - val;
	/* fall-through */
      case '+':
	g_string_truncate(equation, equation->len - 1);
	format = "%+.7e";
	break;
      default:
	format = "%.7e";
      }
      prev_char = '\0';
      g_string_append_printf(equation, format, val);
      break;
    case ' ':
      break;
    default:
      prev_char = func[i];
      g_string_append_c(equation, toupper(prev_char));
    }
  }

  fitlocal->equation = g_string_free(equation, FALSE);
  if (disp) {
    display_equation(fitlocal->equation);
  }

  return 0;
}
Example #2
0
void grobner::display_equations(std::ostream & out, equation_set const & v, char const * header) const {
    if (!v.empty()) {
        out << header << "\n";
        equation_set::iterator it  = v.begin();
        equation_set::iterator end = v.end();
        for (; it != end; ++it)
            display_equation(out, *(*it));
    }
}
Example #3
0
static int
show_poly_result(struct fitlocal *fitlocal, enum FIT_OBJ_TYPE type, vector coe, int num)
{
  int j;
  GString *info;

  info = g_string_new("");
  if (info == NULL) {
    return 1;
  }

  g_string_append_printf(info, "--------\nfit:%d (^%d)\n", fitlocal->id, fitlocal->oid);
  switch (type) {
  case FIT_TYPE_POLY:
    g_string_append_printf(info,"Eq: %%0i*X^i (i=0-%d)\n\n", fitlocal->dim - 1);
    break;
  case FIT_TYPE_POW:
    g_string_append(info,"Eq: exp(%00)*X^%01\n\n");
    break;
  case FIT_TYPE_EXP:
    g_string_append(info,"Eq: exp(%01*X+%00)\n\n");
    break;
  case FIT_TYPE_LOG:
    g_string_append(info,"Eq: %01*Ln(X)+%00\n\n");
    break;
  case FIT_TYPE_USER:
    /* never reached */
    break;
  }
  for (j = 0; j < fitlocal->dim; j++) {
    g_string_append_printf(info, "       %%0%d = %+.7e\n", j, coe[j]);
  }
  g_string_append_c(info, '\n');
  g_string_append_printf(info, "    points = %d\n", fitlocal->num);
  g_string_append_printf(info, "    <DY^2> = %+.7e\n", fitlocal->derror);
  if (fitlocal->correlation >= 0) {
    g_string_append_printf(info, "|r| or |R| = %+.7e\n", fitlocal->correlation);
  } else {
    g_string_append(info, "|r| or |R| = -------------\n");
  }
  ndisplaydialog(info->str);
  g_string_free(info, TRUE);

  display_equation(fitlocal->equation);

  return 0;
}