Exemplo n.º 1
0
void Bisection(T* str, int l, int r, int level){
	if (level == 0) {
		return;
	}
	int middle = (l + r) / 2;
	str[middle] = '|';
	Bisection(str, l, middle, level - 1);
	Bisection(str, middle, r, level - 1);
}
Exemplo n.º 2
0
static double Bisection(int n, double x1, double x2, double y1, double y2)
{
    double x, y;
    x = (x1+x2)/2;
    if((x2 - x1) < TOLERANCE)
	return x;
    else
    {
	y = BessJn(n, x);
	if(SameSign(y1, y))
	    return Bisection(n, x, x2, y, y2);
	else
	    return Bisection(n, x1, x, y1, y);
    }
}
void fzeroCubicTest() {
    std::cout << "Bisection cubic ... ";
    double tol = 1e-7;
    auto f = [] (double x) { return x*x*(x-1); };
    double x = Bisection(f, 0.5,1.7,tol).zero();
    bool pass = true;
    pass &= fabs(1.0 - x) <  tol;
    if(pass) std::cout << "PASS" << std::endl;
    else std::cout << "FAIL" << std::endl;
  }
void fzeroLinearTest() {
    std::cout << "Bisection linear ... ";
    double tol = 1e-7;
    auto f = [] (double x) { return x; };
    double x = Bisection(f, -11.0,8.0,tol).zero();
    bool pass = fabs(0.0 - f(x)) <  tol;
    pass &= fabs(0.0 - x) <  tol;
    if(pass) std::cout << "PASS" << std::endl;
    else std::cout << "FAIL" << std::endl;
  }
Exemplo n.º 5
0
//Complete procedure to get the best estimate of the residual energy
Double_t CsICalib::GetResidualEnergyCsI(Double_t chsi, Double_t chcsi){		//UShort_t chsi, UShort_t chcsi
  Int_t A;
  A=2*eZ;
  CalculateESi(chsi); 
  
  LightCsI=chcsi - ePied;		// 
  //L->Log<<"LightCsI = "<<LightCsI<<endl;
  
  Bisection(A,double(LightCsI));		//Call the bisection method 	
  Interpolate();			//Interpolation of ECsI and A values
  
  return sRefECsI; 
}
Exemplo n.º 6
0
static double FindRoot(int n, double *x)
{
    double y1, y2, curr_x, result;     
    
    curr_x = *x;
    do  {
	curr_x += STEP_ROOT;
	y1 = BessJn(n, curr_x);
	y2 = BessJn(n, curr_x + STEP_ROOT);
    } while SameSign(y1, y2);	    /* Find interval containing root */
    result =  Bisection(n, curr_x, curr_x + STEP_ROOT, y1, y2);
    *x = curr_x + STEP_ROOT;
    return result;
}
Exemplo n.º 7
0
//Complete procedure to get the best estimate of the residual energy
Double_t CsICalib::GetResidualEnergyCsI(Double_t esi, Double_t chcsi)
{
   assert((esi >= 0.) && (esi < 3000.));
   assert(chcsi >= 0.);

   Int_t A;
   A = 2 * eZ;
   eEnergySi = esi;

   LightCsI = chcsi - ePied;

   bisector_iterations_ = 0;
   Bisection(A, static_cast<Double_t>(LightCsI)); //Call the bisection method
   Interpolate(); //Interpolation of ECsI and A values

   return sRefECsI;
}
Exemplo n.º 8
0
int main()
{
	char str[66];
	str[65] = '\0';

	int min = 0;
	int max = 64;
	str[min] = str[max] = '|';

	for (int i(1); i < max; i++) {
		str[i] = ' ';
	}

	for (int i(0); i <= 6; i++){
		Bisection(str, min, max, i);
		std::cout << str << std::endl;
	}

	_getch();
	return 0;
}
Exemplo n.º 9
0
int main()
{
      double x,y,c,d,e,ab;
      while(scanf("%lf %lf %lf",&x,&y,&c)!=EOF) printf("%.3lf\n",Bisection(x,y,c));
	return 0;
}