/*
 * Finds the midpoints of the function values for each estimate at the breakpoints. The function
 * result at the end of the interval before the breakpoint and the function result at the
 * start of the interval after the breakpoint are checked, and the point directly between them is found.
 * The first and last breakpoints are the start and end of the interval, and as such do not have
 * another point to compare against, and so are returned as is.
 */
double* get_breakpoint_midpoints(double* breakpoint_vector, double* func_vals, int len)
{
    double* midpoints = malloc((len + 1) * sizeof(double));

    midpoints[0] = func_vals[0];
    int i, j;
    
    for (i = 1, j = 1; i < len; i++, j += 2){
	/* printf("i %d, j %d\n", i, j); */
	/* printf("breakpoint %lf\n", breakpoint_vector[i]); */
	/* printf("midpoint of [%lf, %lf] is midpoint: %lf\n", func_vals[j], func_vals[j+1], get_midpoint(func_vals[j], func_vals[j+1])); */
	midpoints[i] = get_midpoint(func_vals[j], func_vals[j+1]);
    }

    midpoints[i] = func_vals[j];

    return midpoints;
}
Exemplo n.º 2
0
static Scrd
mbetween(Mcrd a, Mcrd b, int i){
  return(  get_midpoint(map2scr(a), map2scr(b), i)  );
}