CMP EMBEDDED.COM

Login | Register     Welcome Guest  
HOME DESIGN PRODUCTS COLUMNS E-LEARNING CONFERENCES CODE FORUMS/BLOGS NEWSLETTERS CONTACT FEATURES RSS RSS

Listing 3: Initialization and y-range

Listing 3: Initialization and y-range


// Initialize the state machine
STATE init(double (*f)(double), double X0, double X1, long steps, double eps)
{
// evaluate initial y values
x0 = X0;
x1 = X1;
y0 = f(x0);
y1 = f(x1); 
// copy points to vectors
x[0] = x0;
y[0] = y0;
x[1] = x1;
y[1] = y1;
// set x range and error criterion
x_range = x1 - x0;
dx = x_range/steps;
x_eps = x_range * sqrt(eps);
// set y range and error criterion
top_y = max(y0, y1);
bottom_y = min(y0, y1);
y_range = top_y - bottom_y;
y_eps = eps * y_range;
// identify minimum
npoints = 2;
if (y0 <= y1) {
xmin = x0;
ymin = y0;
index = 0
}
else {
xmin = x1;
ymin = y1;
index = 1;
}
return STEP;
}
// Update error criterion in y
void set_y_range(double y, double eps)
{
bottom_y = min(y, bottom_y);
top_y = max(y, top_y);
y_range = top_y - bottom_y;
y_eps = eps * y_range;
}


Embedded.com Career Center
Looking for a new job?
SEARCH JOBS

Browse all jobs

SPONSOR
RECENT JOB POSTINGS





 :