Esempio n. 1
0
static void
y_pade(double R, double L, double G, double C, TXLine *h)
{

    /* float RdL, GdC; */
    double RdL, GdC;

    sqtCdL = sqrt(C / L);
    RdL = R / L;
    GdC = G / C;

    mac(GdC, RdL, &b1, &b2, &b3, &b4, &b5);

    A[0][0] = 1.0 - sqrt(GdC / RdL);
    A[0][1] = b1;
    A[0][2] = b2;
    A[0][3] = -b3;

    A[1][0] = b1;
    A[1][1] = b2;
    A[1][2] = b3;
    A[1][3] = -b4;

    A[2][0] = b2;
    A[2][1] = b3;
    A[2][2] = b4;
    A[2][3] = -b5;

    Gaussian_Elimination1(3);

    p3 = A[0][3];
    p2 = A[1][3];
    p1 = A[2][3];

    q1 = p1 + b1;
    q2 = b1 * p1 + p2 + b2;
    q3 = p3 * sqrt(GdC / RdL);

    find_roots(p1, p2, p3, &x1, &x2, &x3);
    c1 = eval2(q1 - p1, q2 - p2, q3 - p3, x1) /
         eval2(3.0, 2.0 * p1, p2, x1);
    c2 = eval2(q1 - p1, q2 - p2, q3 - p3, x2) /
         eval2(3.0, 2.0 * p1, p2, x2);
    c3 = eval2(q1 - p1, q2 - p2, q3 - p3, x3) /
         eval2(3.0, 2.0 * p1, p2, x3);

    h->sqtCdL = sqtCdL;
    h->h1_term[0].c = c1;
    h->h1_term[1].c = c2;
    h->h1_term[2].c = c3;
    h->h1_term[0].x = x1;
    h->h1_term[1].x = x2;
    h->h1_term[2].x = x3;

}
Esempio n. 2
0
/*-----------------------------------------------------------------------*/
int
find_poly_optima(int *deg, double **coeff, double skewness, double *optima)
{
	int n, nop, s;

/* zeros */
	nop = find_roots(deg[0], coeff[0], optima);
	nop += find_roots(deg[1], coeff[1], optima + nop);
	for (n = 0; n < nop; n++)
		optima[n] /= skewness;

/* extrema */
	for (s = 0; s < 2; s++) {
		double deriv[MAX_POLY_DEGREE + 1];
		double c[MAX_POLY_DEGREE + 1];
		double sp;
		int d, i;

		d = deg[s];
		sp = 1.;
		for (i = 0; i <= d; i++) {
			c[i] = coeff[s][i] * sp;
			sp *= skewness;
		}
		for (i = 0; i < d; i++)
			deriv[i] = -c[i + 1] * (double) (i + 1);
		deriv[d] = 0.;
		for (i = 0; i < d; i++)
			deriv[i + 1] += c[i] * (double) (d - i);
		while (d) {
			if (deriv[d])
				break;
			else
				d--;
		}
		nop += find_roots(d, deriv, optima + nop);
	}
	optima[nop++] = DBL_MIN;
	optima[nop++] = DBL_MAX;
	return nop;
}
Esempio n. 3
0
/* Once we have found a D and q, this will find a curve and point.
 * Returns: 0 (composite), 1 (didn't work), 2 (success)
 * It's debatable what to do with a 1 return.
 */
static int find_curve(mpz_t a, mpz_t b, mpz_t x, mpz_t y,
                      long D, int poly_index, mpz_t m, mpz_t q, mpz_t N, int maxroots)
{
  long nroots, npoints, i, rooti, unity, result;
  mpz_t g, t, t2;
  mpz_t* roots = 0;

  /* TODO: A better way to do this, I believe, would be to have the root
   *       finder set up as an iterator.  That way we'd get the first root,
   *       try to find a curve, and probably we'd be done.  Only if we tried
   *       10+ points on that root would we get another root.  This would
   *       probably be set up as a stack (array) of polynomials plus one
   *       saved root (for when we solve a degree 2 poly).
   */
  /* Step 1: Get the roots of the Hilbert class polynomial. */
  nroots = find_roots(D, poly_index, N, &roots, maxroots);
  if (nroots == 0)
    return 1;

  /* Step 2: Loop selecting curves and trying points.
   *         On average it takes about 3 points, but we'll try 100+. */

  mpz_init(g);  mpz_init(t);  mpz_init(t2);
  npoints = 0;
  result = 1;
  for (rooti = 0; result == 1 && rooti < 50*nroots; rooti++) {
    /* Given this D and root, select curve a,b */
    select_curve_params(a, b, g,  D, roots, rooti % nroots, N, t);
    if (mpz_sgn(g) == 0) { result = 0; break; }

    /* See Cohen 5.3.1, page 231 */
    unity = (D == -3) ? 6 : (D == -4) ? 4 : 2;
    for (i = 0; result == 1 && i < unity; i++) {
      if (i > 0)
        update_ab(a, b, D, g, N);
      npoints++;
      select_point(x, y,  a, b, N, t, t2);
      result = ecpp_check_point(x, y, m, q, a, N, t, t2);
    }
  }
  if (npoints > 10 && get_verbose_level() > 0)
    printf("  # point finding took %ld points\n", npoints);

  if (roots != 0) {
    for (rooti = 0; rooti < nroots; rooti++)
      mpz_clear(roots[rooti]);
    Safefree(roots);
  }
  mpz_clear(g);  mpz_clear(t);  mpz_clear(t2);

  return result;
}
Esempio n. 4
0
int main() {
	float a1, a2, a3, x_cube;

	printf("A cubic equation has the form x^3 + a1*x^2 + a2*x + a3 = 0.\n");
	printf("Please input the a1 value.\n");
	scanf("%f", &a1);
	printf("Please input the a2 value.\n");
	scanf("%f", &a2);
	printf("Please input the a3 value.\n");
	scanf("%f", &a3);
	printf("What is the coefficient of the x^3 term?\n");
	scanf("%f", &x_cube);
	
	find_roots(a1/x_cube, a2/x_cube, a3/x_cube); // x_cube is to account for equations with an x^3 coefficient not equal to 1.
}
Esempio n. 5
0
void
do_cc(rust_task *task) {
    LOG(task, gc, "cc; n allocs = %lu",
        (long unsigned int)task->local_allocs.size());

    irc_map ircs;
    irc::compute_ircs(task, ircs);

    std::vector<void *> roots;
    find_roots(task, ircs, roots);

    std::set<void *> marked;
    mark::do_mark(task, roots, marked);

    sweep::do_sweep(task, marked);
}
Esempio n. 6
0
/* Once we have found a D and q, this will find a curve and point.
 * Returns: 0 (composite), 1 (didn't work), 2 (success)
 * It's debatable what to do with a 1 return.
 */
static int find_curve(mpz_t a, mpz_t b, mpz_t x, mpz_t y,
                      long D, mpz_t m, mpz_t q, mpz_t N)
{
  long nroots, npoints, i, rooti, unity, result;
  mpz_t g, t, t2;
  mpz_t* roots = 0;
  int verbose = get_verbose_level();

  /* Step 1: Get the roots of the Hilbert class polynomial. */
  nroots = find_roots(D, N, &roots);
  if (nroots == 0)
    return 1;

  /* Step 2: Loop selecting curves and trying points.
   *         On average it takes about 3 points, but we'll try 100+. */

  mpz_init(g);  mpz_init(t);  mpz_init(t2);
  npoints = 0;
  result = 1;
  for (rooti = 0; result == 1 && rooti < 50*nroots; rooti++) {
    /* Given this D and root, select curve a,b */
    select_curve_params(a, b, g,  D, roots, rooti % nroots, N, t);
    if (mpz_sgn(g) == 0) { result = 0; break; }

    /* See Cohen 5.3.1, page 231 */
    unity = (D == -3) ? 6 : (D == -4) ? 4 : 2;
    for (i = 0; result == 1 && i < unity; i++) {
      if (i > 0)
        update_ab(a, b, D, g, N);
      npoints++;
      select_point(x, y,  a, b, N, t, t2);
      result = ecpp_check_point(x, y, m, q, a, N, t, t2);
    }
  }
  if (verbose && npoints > 10)
    printf("  # point finding took %ld points\n", npoints);

  if (roots != 0) {
    for (rooti = 0; rooti < nroots; rooti++)
      mpz_clear(roots[rooti]);
    Safefree(roots);
  }
  mpz_clear(g);  mpz_clear(t);  mpz_clear(t2);

  return result;
}
Esempio n. 7
0
t_intersectInfo			*project_2d_cylinder(t_cylinder *cylinder, t_ray r,
	t_intersectInfo *i)
{
	double		a;
	double		b;
	double		c;

	a = SQR(r.direction);
	b = 2 * (DOT_PROD(r.direction, r.origin) -
			DOT_PROD(r.direction, cylinder->origin));
	c = SQR(r.origin) + SQR(cylinder->origin) - 2 *
		(DOT_PROD(r.origin, cylinder->origin)) -
		(cylinder->radius * cylinder->radius);
	if (!find_roots(a, b, c, &(i->t)))
		return (NULL);
	return (i);
}
Esempio n. 8
0
int find_fiducialsX( FiducialX *fiducials, int max_count,
        FidtrackerX *ft, Segmenter *segments, int width, int height)
{
    int i = 0;
    Region *next;

    initialize_head_region( &ft->root_regions_head );

    find_roots( segments, ft);

    next = ft->root_regions_head.next;
    while( next != &ft->root_regions_head ){

        compute_fiducial_statistics( ft, &fiducials[i], next, width, height );

        next = next->next;
        ++i;
        if( i >= max_count )
            return i;
    }

    return i;
}
Esempio n. 9
0
void iir_coeff::pz_to_ap() {
  int m = 2 * order - 1;
  typedef std::vector<float_type> Array;
  typedef std::vector<std::complex<float_type> > CArray;
  Array fa;
  Array d2(m);
  Array p2(m);
  Array r(m);
  Array q(m);
  CArray rq;
  CArray h1(m);
  CArray h2(m);
  float_type divtmp;
  float_type tmp;
  int np, nq;
  int i, j;

  // Convert from poles and zeros to 2nd order section coefficients
  //  root_to_ab(zeros);
  //  root_to_ab(poles);

  // Get overall A and B transfer functions
  //  p2_to_poly(zeros, b_tf, n2);
  //  p2_to_poly(poles, a_tf, n2);

  // Convert from poles and zeros to polynomial transfer functions
  b_tf = pz_to_poly(zeros);
  a_tf = pz_to_poly(poles);

  // Now start real work
  p2 = convolve(b_tf, b_tf);
  fa = fliplr(a_tf);
  d2 = convolve(fa, a_tf);

  // B*B - A*fliplr(A)
  for (j = 0; j < m; j++) { r[j] = p2[j] - d2[j]; }

  // Appendix IEEE assp-34, no 2, april 1986, page 360
  q[0] = std::sqrt(r[0]);
  q[1] = r[1] / (2 * q[0]);

  divtmp = 0.5 / q[0];
  for (j = 2; j < m; j++) {
    for (tmp = 0, i = 2; i < j; i++) tmp += q[i] * q[j - i];
    q[j] = (r[j] - tmp) * divtmp;
  }

  for (j = 0; j < m; j++) q[j] += b_tf[j];

  rq = find_roots(q, m);

  np = nq = 0;
  for (j = 0; j < m; j++) {
    if (std::norm(rq[j]) >= (float_type)1.0) {
      h1[nq++] = rq[j];
    } else {
      h2[np++] = rq[j];
    }
  }
  // We now roots for H1 sections in h1 and
  //              for H2 sections in h2 and

  // We convert from each root pair to an allpass section
  // with coefficients

  // Save these coefficients for transfer to IIR implemented as
  // allpass sections

  // ap_state = 1;
  state = filter_state::s4;
}
Esempio n. 10
0
File: elim.c Progetto: IEDMS/BNT-SM
/*
    if can find adj_list[i] that is a clique
      remove i, all edges from i;
      ordering[o++] = i;
      cliques[c++] = adj_list[i];
    else find adj_list[i] with smallest clique weight
      remove i, all edges from i;
      ordering[o++] = i;
      make adj_list[i] a clique;
      cliques[c++] = adj_list[i];
*/
Elimination elim(int size, Map * adj_list, Neighborhood * partial_order,
    Map node_map){

  Map ordering, cliques, max_cliques, trashcan;
  int i, j, clique_exists, min_node, subset, index1, index2;
  float min_weight, weight;
  word w, w2, child, child2;
  Iterator iter, iter2;
  Map nodes = create_Map(size, compare, hash_int, empty(), 1);
  Map roots = create_Map(size, compare, hash_int, empty(), 1);
  int ** fill_ins;

  fill_ins = (int **) malloc(sizeof(int *) * size);
  fill_ins[0] = (int *) malloc(sizeof(int) * size * size);

  for(i = 1; i < size; i++){
    fill_ins[i] = fill_ins[i - 1] + size;
  }
  for(i = 0; i < size; i++){
    for(j = 0; j < size; j++){
      fill_ins[i][j] = 0;
    }
  }

  for(i = 0; i < size; i++){
    w.i = i;
    put(nodes, w, w);
  }
  find_roots(partial_order, nodes, roots);

  ordering = create_Map(size + 1, compare, hash_int, empty(), 1);
  cliques = create_Map(size + 1, set_compare, hash_set, empty(), 1);

  while(get_size_Map(nodes) > 0){
    clique_exists = 0;
    iter = get_Iterator(roots);
    while(!is_empty(iter)){
      w = next_key(iter);
      if(is_clique_heuristic(w.i, adj_list) && is_clique(w.i, adj_list, size)){
        clique_exists = 1;
        break;
      }
    }
    if(!clique_exists){
      min_weight = LONG_MAX;
      iter = get_Iterator(roots);
      while(!is_empty(iter)){
        w = next_value(iter);
        weight = 0;
        iter2 = get_Iterator(adj_list[w.i]);
        while(!is_empty(iter2)){
          weight += ((Node) next_value(iter2).v)->weight;
        }
        if(weight < min_weight){
          min_weight = weight;
          min_node = w.i;
        }
      }
      w.i = min_node;
    }
    min_node = w.i;
    rem(nodes, w);
    remove_node(partial_order, w.i);
    empty_Map(roots);
    find_roots(partial_order, nodes, roots);
    put(ordering, w, w);
    child.v = adj_list[w.i];

    if(!find((Map) child.v, w)){
      child2.v = create_Node(w.i, 0);
      put(node_map, child2, child2);
      put((Map) child.v, w, child2);
    }
    child.v = copy_Map((Map) child.v);
    put(cliques, child, child);
    iter = get_Iterator(adj_list[min_node]);
    i = 0;
    while(!is_empty(iter)){
      child = next_value(iter);
      rem(adj_list[((Node) child.v)->index], w);
    }
    iter = create_Iterator(adj_list[min_node]);
    while(!is_empty(iter)){
      child = next_value(iter);
      index1 = ((Node) child.v)->index;
      w.i = index1;
      iter2 = get_Iterator(adj_list[min_node]);
      while(!is_empty(iter2)){
        child2 = next_value(iter2);
	index2 = ((Node) child2.v)->index;
	if(index1 != index2){
          w2.i = index2;
          if(index1 < index2 && !find(adj_list[index1], w2)){
            fill_ins[index1][index2] = 1;
	  }
          put(adj_list[index1], w2, child2);
        }
      }
    }
    destroy_Iterator(iter);
  }
  destroy_Map(nodes);
  destroy_Map(roots);

  max_cliques = create_Map(size, set_compare, hash_set, empty(), 2);
  trashcan = create_Map(size, set_compare, hash_set, empty(), 2);
  while(get_size_Map(cliques) > 0){
    iter = get_Iterator(cliques);
    child = next_key(iter);
    rem(cliques, child);
    subset = 0;
    while(!is_empty(iter)){
      child2 = next_key(iter);
      if(is_subset_of((Map) child2.v, (Map) child.v)){
        rem(cliques, child2);
	put(trashcan, child2, child2);
      } else if(is_subset_of((Map) child.v, (Map) child2.v)){
         subset = 1;
	 break;
      }
    }
    if(!subset){
      put(max_cliques, child, child);
    } else {
      put(trashcan, child, child);
    }
  }

  destroy_Map(cliques);
  iter = get_Iterator(trashcan);
  while(!is_empty(iter)){
    child = next_key(iter);
    destroy_Map((Map) child.v);
  }
  destroy_Map(trashcan);
  return create_Elimination(ordering, max_cliques, fill_ins, node_map);
}