예제 #1
0
파일: context.c 프로젝트: akobel/MPSolve
/**
 * @brief Set active polynomial as a real floating point coefficient
 * polynomial of degree <code>n</code> with coefficient exactly
 * determined by components of vector coeff.
 *
 * Precisely, if \f${\mathrm coeff}\f$ is a vector of \f$n+1\f$ components,
 * \f[
 *   p(x) = \sum_{i = 0}^{n} {\mathrm coeff}_i  x^i
 * \f]
 */
int
mps_context_set_poly_d (mps_context * s, cplx_t * coeff, long unsigned int n)
{
  int i;

  /* Allocate space for a polynomial of degree n */
  mps_monomial_poly * p = mps_monomial_poly_new (s, n);

  /* Fill polynomial coefficients */
  for (i = 0; i <= n; i++)
    {
      mps_monomial_poly_set_coefficient_d (s, p, i, cplx_Re (coeff[i]),
                                           cplx_Im (coeff[i]));
    }

  mps_context_set_input_poly (s, MPS_POLYNOMIAL (p));

  return 0;
}
예제 #2
0
파일: mps_impl.c 프로젝트: robol/MPSolve
/**
 * @brief Caller for mps_solve routine.
 *
 * Since fortran complex are
 * identical to internal mpsolve cplx_t complex type, i.e.
 * two double in a struct, we can simply cast silently the
 * arguments of the fortran routine.
 */
void
mps_roots_ (int * n, cplx_t * coeff, cplx_t * roots)
{
    /* Create a new mps_context and a new polynomial */
    mps_context *s = mps_context_new ();
    mps_monomial_poly * p = mps_monomial_poly_new (s, *n);
    int i;

    for (i = 0; i <= *n; i++)
        mps_monomial_poly_set_coefficient_d (s, p, i, cplx_Re (coeff[i]), cplx_Im (coeff[i]));
    mps_context_set_input_poly (s, MPS_POLYNOMIAL (p));

    /* Set the output precision to DBL_EPSILON and the default goal
     * to approximate. Try to find all the possible digits representable
     * in floating point. */
    mps_context_set_output_prec (s, 53);
    mps_context_set_output_goal (s, MPS_OUTPUT_GOAL_APPROXIMATE);

    mps_mpsolve (s);

    mps_context_get_roots_d (s, &roots, NULL);
    mps_context_free (s);
}