Ejemplo n.º 1
0
int work(int y1,int z1, double m1,  
	 int y2,int z2, double m2,  
	 int y3,int z3, double m3,
	 int y4,int z4, double m4, 
	 int order, 
	 double lambda_low,  double lambda_high, 
	 int precision,
	 char *tag1, char *tag2 ){
  // The error from the approximation (the relative error is minimised
  // - if another error minimisation is requried, then line 398 in
  // alg_remez.C is where to change it)
  double error;
  
  double *res = new double[order];
  double *pole = new double[order];
  
  // The partial fraction expansion takes the form 
  // r(x) = norm + sum_{k=1}^{n} res[k] / (x + pole[k])
  double norm;

  double bulk = exp(0.5*(log(lambda_low)+log(lambda_high)));

  // Instantiate the Remez class,
  AlgRemez remez(lambda_low,lambda_high,precision);

  // Generate the required approximation
  fprintf(stderr,
	  "Generating a (%d,%d) rational function using %d digit precision.\n",
	  order,order,precision);
  error = remez.generateApprox(order,order,y1,z1,m1,y2,z2,m2,
			       y3,z3,m3,y4,z4,m4);

  // Find the partial fraction expansion of the approximation 
  // to the function x^{y/z} (this only works currently for 
  // the special case that n = d)
  remez.getPFE(res,pole,&norm);
  
  print_check_ratfunc(y1,y2,y3,y4,z1,z2,z3,z4,m1,m2,m3,m4,
		      lambda_low,order,norm,res,pole,tag1);

  // Find pfe of the inverse function
  remez.getIPFE(res,pole,&norm);

  print_check_ratfunc(-y1,-y2,-y3,-y4,z1,z2,z3,z4,m1,m2,m3,m4,
		      lambda_low,order,norm,res,pole,tag2);

  FILE *error_file = fopen("error.dat", "w");
  for (double x=lambda_low; x<lambda_high; x*=1.01) {
    double f = remez.evaluateFunc(x);
    double r = remez.evaluateApprox(x);
    fprintf(error_file,"%e %e\n", x,  (r - f)/f);
  }
  fclose(error_file);

  delete res;
  delete pole;

}
Ejemplo n.º 2
0
// -----------------------------------------------------------------
int work(int Nroot, int order, double lambda_low,  double lambda_high,
         int precision, char *tag1, char *tag2) {

  int Nroot4 = 4 * Nroot;
  double *res = new double[order];
  double *pole = new double[order];
  double error;   // The error from the approximation
                  // The relative error is minimised
                  // If another error minimisation is required,
                  // change line 398 in alg_remez.C

  // The partial fraction expansion takes the form
  // r(x) = norm + sum_{k=1}^{n} res[k] / (x + pole[k])
  double norm;
  double bulk = exp(0.5 * (log(lambda_low) + log(lambda_high)));

  // Instantiate the Remez class
  AlgRemez remez(lambda_low, lambda_high, precision);

  // Generate the required approximation
  fprintf(stderr, "Generating a (%d,%d) rational function ", order, order);
  fprintf(stderr, "using %d digit precision\n", precision);
  error = remez.generateApprox(order, order, 1, Nroot4, 0.0, 0, -1, -1.0,
                                             0, -1,    -1.0, 0, -1, -1.0);

  // Find the partial fraction approximation to the function x^{y / z}
  // This only works currently for the special case that n = d
  remez.getPFE(res, pole, &norm);

  print_check_ratfunc(1, Nroot4, lambda_low, order, norm, res, pole, tag1);

  // Find pfe of the inverse function
  remez.getIPFE(res, pole, &norm);

  print_check_ratfunc(-1, Nroot4, lambda_low, order, norm, res, pole, tag2);

  FILE *error_file = fopen("error.dat", "w");
  double x, f, r;
  for (x = lambda_low; x < lambda_high; x *= 1.01) {
    f = remez.evaluateFunc(x);
    r = remez.evaluateApprox(x);
    fprintf(error_file, "%e %e\n", x,  (r - f) / f);
  }
  fclose(error_file);

  delete res;
  delete pole;
}