/*************************************************************************\ * Copyright (c) 2002 The University of Chicago, as Operator of Argonne * National Laboratory. * Copyright (c) 2002 The Regents of the University of California, as * Operator of Los Alamos National Laboratory. * This file is distributed subject to a Software License Agreement found * in the file LICENSE that is included with this distribution. \*************************************************************************/ /* $Log: ming.c,v $ Revision 1.3 2002/08/14 16:18:58 soliday Added Open License Revision 1.2 1995/09/05 21:20:37 saunders First test release of the SDDS1.5 package. */ /* routine: ming() * purpose: find minimum of a multi-parameter function, using a grid * search * * Michael Borland, 1989 */ #include "mdb.h" double ming( double (*fn)(), /* pointer to fn to be minimize */ double *x, /* array to return location of minimum in */ double *xlo, /* array of lower limits */ double *xhi, /* array of upper limits */ long *n_steps, /* array of numbers of steps */ long np /* number of parameters */ ) { register double f0; double *dx, *xbest, min_val; long i, *counter; xbest = tmalloc(sizeof(double)*np); dx = tmalloc(sizeof(double)*np); counter = tmalloc(sizeof(long)*np); for (i=0; i