# EETimes

## Embedded Systems December 2000 Vol13_13

Issue link: http://dc.ee.ubm-us.com/i/71850

## Contents of this Issue  ## Navigation

### Page 31 of 197

PROGRAMMER'S TOOLBOX Suppose, as I suggested earlier, we retain (at least) five successive data points, with the middle one being the best minimum to date. This means that we have two points on either side of the minimum. one. If the fun ction is indeed an absolute value, we should find the solution immediately. Consider th e two straight li ne segments: Suppose, as r suggested earli er, we reta in (at least) five successive data points, with the middle one be ing the best minimum to date. This means LISTING 2 11/2 II Local minimizer; Sets up conditions for iteration double minimize(double (*f)(double), double xO, double x2, long nH double yO, x1, y1, y2, xmin, ymin, x, y; double dx = (x2 - xO)/n; yO = f(xQ); xmin = xO; ymin = yO; x1 = xO+dx; y1 = f(x1); II wait for function to turn downwards while«x1 < x2) && (y1 > ymin»{ xO = x1; yO = y1; x1 += dx; y1 = f(x1); } if(x1 >= x2) return xmi n; II now watch for it to turn up again x = x1-+1:Jx; y = f(x); while«x < x2) && (y < y1»{ xO = x1; yO = y1; x1 = x; y1 = y; x = min(x + dx, x2); y = f(x); } i f(x >= x2) return x; else return findmin(f, xO, yO, x1, y1, x2, y2); } = Y4 - Y3 X4 -X3 (21) Where these two lines cross, their val- ues are equaL Hence, at this point: th at we have two points on either side of the minimum. And that means we can fi t straight lines through the two points o n either side of the middle I I (x) = Yo +ml(x -xo) h(X)=Y3 + 1112 (X -X3) (20) where 11!1 and nl

## Archives of this issue

view archives of EETimes - Embedded Systems December 2000 Vol13_13