Exemple #1
0
/** Extended trapezoid rule.
 *
 * This algorithm was adapted from function trapzd in
 * "Numerical Recipes in C", 2nd edition,
 * Press, Teukolsky, Vetterling, Flannery, chapter 4.2
 */
dvariable function_minimizer::trapzd(
  dvariable (model_parameters::*func)(const dvariable&),
  double a, const dvariable& b, int n)
{
  double num_interval;
  dvariable sum,hn,x;
  static dvariable s;

  static int interval;
  int j;

  model_parameters * ptr= (model_parameters *) mycast();
  if (n == 1) {
    interval=1;
    return (s=0.5*(b-a)*((ptr->*func)(a)+(ptr->*func)(b)));
  } else {
    num_interval=interval;
    hn=(b-a)/num_interval;
    x=a+0.5*hn;
    for (sum=0.0,j=1;j<=interval;j++,x+=hn) sum += (ptr->*func)(x);
    interval *= 2;
    s=0.5*(s+(b-a)*sum/num_interval);
    return s;
  }
}
Exemple #2
0
// This function force the compilator to do push and pop with the good 
static DWORD CastFloatToDW(float f)
{
	return mycast(f);
}