Statistics
| Revision:

root / trunk / src / linad99 / minim.cpp @ 1060

History | View | Annotate | Download (869 Bytes)

1
/*
2
 * $Id: minim.cpp 1060 2013-06-18 02:43:33Z jsibert $
3
 *
4
 * Author: David Fournier
5
 * Copyright (c) 2008-2012 Regents of the University of California 
6
 */
7
/**
8
  \file minim.pp
9
  Minimize artibrary user-supplied function.
10
 */
11
#include <fvar.hpp>
12

    
13
/**
14
  Minimize artibrary user-supplied function.
15
  \param x Vector of independent variables
16
  \param pf Pointer to function to be minmized with prototype
17
  double pf(const dvar_vector&); 
18
  \returns double containing value of the function at the minimum.
19
 */
20
double fmm::minimize(const independent_variables & x, double (*pf)(const dvar_vector&))
21
{  
22
  int nvar=x.size();
23
  double f;
24
  dvector g(1,nvar);
25
#ifndef SAFE_INITIALIZE
26
  g.initialize();
27
#endif
28
  {
29
    gradient_structure gs;
30
    while (ireturn >= 0)
31
    {
32
      fmin(f,x,g);
33
      if(ireturn > 0)
34
      {
35
        {
36
          f=(*pf)(x);
37
        }
38
        gradcalc(nvar,g);
39
      }
40
    }
41
  }
42
  return(f);
43
}