Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

minimize1.h

Go to the documentation of this file.
00001 // SuperMix version 1.0  C++ source file
00002 //
00003 // Copyright (c) 1999 California Institute of Technology.
00004 // All rights reserved.
00005 //
00006 // Redistribution and use in source and binary forms for noncommercial
00007 // purposes are permitted provided that the above copyright notice and
00008 // this paragraph are duplicated in all such forms and that any
00009 // documentation and other materials related to such distribution and
00010 // use acknowledge that the software was developed by California
00011 // Institute of Technology. Redistribution and/or use in source or
00012 // binary forms is not permitted for any commercial purpose. Use of
00013 // this software does not include a permitted use of the Institute's
00014 // name or trademark for any purpose.
00015 //
00016 // DISCLAIMER:
00017 // THIS SOFTWARE AND/OR RELATED MATERIALS ARE PROVIDED "AS-IS" WITHOUT
00018 // WARRANTY OF ANY KIND INCLUDING ANY WARRANTIES OF PERFORMANCE OR
00019 // MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE OR PURPOSE (AS SET
00020 // FORTH IN UCC 23212-2313) OR FOR ANY PURPOSE WHATSOEVER, FOR THE
00021 // LICENSED PRODUCT, HOWEVER USED.  IN NO EVENT SHALL CALTECH/JPL BE
00022 // LIABLE FOR ANY DAMAGES AND/OR COSTS, INCLUDING BUT NOT LIMITED TO
00023 // INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, INCLUDING ECONOMIC
00024 // DAMAGE OR INJURY TO PROPERTY AND LOST PROFITS, REGARDLESS OF
00025 // WHETHER CALTECH/JPL SHALL BE ADVISED, HAVE REASON TO KNOW, OR IN
00026 // FACT SHALL KNOW OF THE POSSIBILITY.  THE USER BEARS ALL RISK
00027 // RELATING TO QUALITY AND PERFORMANCE OF THE SOFTWARE AND/OR RELATED
00028 // MATERIALS.
00029 //
00030 // ************************************************************************
00031 // minimize1.h
00032 //
00033 // Functions for finding local minima of a real function of 1 real variable.
00034 //
00035 // Contains:
00036 // minimize1(), bracket_minimum(), refine_minimum()
00037 
00038 
00039 #ifndef MINIMIZE1_H
00040 #define MINIMIZE1_H
00041 
00042 // ************************************************************************
00043 // Here's the main minimizer routine:
00044 // Given initial guesses x1 and x2 for the location of a minimum of f(x),
00045 // use:
00046 //      minimize(f, x1,x2, tol);  // tol is optional
00047 // 
00048 // to locate a local minimum to within a fractional tolerance of tol. The
00049 // coordinate of the minimum is returned in x1; minimize() returns f(x)
00050 // at that point. Not supplying the optional tol, or setting it < 1.0e-7
00051 // will use 1.0e-7 as the tolerance. The optional n_max sets the maximum
00052 // number of iterations to attempt; the default value is 1000.
00053 
00054 template <class F> inline
00055 double minimize1( F f, // the function
00056                  double & x1, double x2, // x values
00057                  double tol, unsigned n_max);
00058 
00059 template <class F> inline
00060 double minimize1( F f, // the function
00061                  double & x1, double x2, // x values
00062                  double tol)
00063 { return minimize1(f,x1,x2,tol,1000); }
00064 
00065 template <class F> inline
00066 double minimize1( F f, // the function
00067                  double & x1, double x2  // x values
00068                 )
00069 { return minimize1(f,x1,x2,1.0e-7,1000); }
00070 
00071 
00072 // ************************************************************************
00073 // A couple of more primitive routines used by minimize(), using algorithms
00074 // adapted from Press, et.al., Numerical Recipes in C, 2nd ed.:
00075 
00076 
00077 // bracket_minimum(f, a,b,c, fa,fb,fc):
00078 //
00079 // Given initial guesses a and b, find new a, b, and c such that
00080 // f(b) < f(a) and f(b) < f(c), that is: a and c bracket a local minimum
00081 // of f(x), and b is a point between a and c. Returns 0 if successful,
00082 // 1 if failed (no other error messages are issued if search failed).
00083 // The optional n_max sets the maximum number of iterations to attempt;
00084 // the default value is 1000.
00085 
00086 template <class F> inline
00087 int bracket_minimum( F f,  // the function
00088                      double &  a, double &  b, double &  c, // x values
00089                      double & fa, double & fb, double & fc, // f(x) values
00090                      unsigned n_max );
00091 
00092 template <class F> inline
00093 int bracket_minimum( F f,  // the function
00094                      double &  a, double &  b, double &  c, // x values
00095                      double & fa, double & fb, double & fc  // f(x) values
00096                     )
00097 { return bracket_minimum(f,a,b,c,fa,fb,fc,1000); }
00098 
00099 
00100 // refine_minimum(f, a,b,c);    // (tol defaults to 1.0e-7)
00101 //
00102 // Given a triplet of guesses a,b,c with b between a and c, and f(b) < f(a)
00103 // and f(b) < f(c) (so a local minimum of f(x) must lie between a and c),
00104 // adjusts the values of a,b,c until a <= b <= c and f(b) is the minimum of
00105 // f(x), ie: b estimates the local minimum of f(x), within +/- (tol*b).
00106 // Also, a and c will bracket the minimum, with c - a <= 2*(tol*b).
00107 // Returns f(b). Uses Brent's method. Setting the optional tol < 1.0e-7
00108 // will use 1.0e-7 as the tolerance. The optional n_max sets the maximum
00109 // number of iterations to attempt; the default value is 1000.
00110 
00111 template <class F> inline
00112 double refine_minimum( F f, // the function
00113                        double & a, double & b, double & c, // x values
00114                        double tol, unsigned n_max);
00115 
00116 template <class F> inline
00117 double refine_minimum( F f, // the function
00118                        double & a, double & b, double & c, // x values
00119                        double tol)
00120 { return refine_minimum(f,a,b,c,tol,1000); }
00121 
00122 template <class F> inline
00123 double refine_minimum( F f, // the function
00124                        double & a, double & b, double & c  // x values
00125                       )
00126 { return refine_minimum(f,a,b,c,1.0e-7,1000); }
00127 
00128 
00129 // ************************************************************************
00130 #include "numerical/num_minimize1.h"
00131 
00132 #endif  /* MINIMIZE1_H */
00133 
00134 

Please direct comments and corrections to supermix@submm.caltech.edu
Go to the supermix home page
Generated by doxygen1.2.7