⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 min.texi

📁 该文件为c++的数学函数库!是一个非常有用的编程工具.它含有各种数学函数,为科学计算、工程应用等程序编写提供方便!
💻 TEXI
字号:
@cindex optimization, see minimization@cindex maximization, see minimization@cindex minimization, one-dimensional@cindex finding minima@cindex non-linear functions, minimizationThis chapter describes routines for finding minima of arbitraryone-dimensional functions.  The library provides low level componentsfor a variety of iterative minimizers and convergence tests.  These can becombined by the user to achieve the desired solution, with full accessto the intermediate steps of the algorithms.  Each class of methods usesthe same framework, so that you can switch between minimizers at runtimewithout needing to recompile your program.  Each instance of a minimizerkeeps track of its own state, allowing the minimizers to be used inmulti-threaded programs.The header file @file{gsl_min.h} contains prototypes for theminimization functions and related declarations.  To use the minimizationalgorithms to find the maximum of a function simply invert its sign.@menu* Minimization Overview::       * Minimization Caveats::        * Initializing the Minimizer::  * Providing the function to minimize::  * Minimization Iteration::      * Minimization Stopping Parameters::  * Minimization Algorithms::     * Minimization Examples::       * Minimization References and Further Reading::  @end menu@node Minimization Overview@section Overview@cindex minimization, overviewThe minimization algorithms begin with a bounded region known to containa minimum.  The region is described by a lower bound @math{a} and anupper bound @math{b}, with an estimate of the location of the minimum@math{x}.@iftex@sp 1@center @image{min-interval,3.4in}@end iftex@noindentThe value of the function at @math{x} must be less than the value of thefunction at the ends of the interval,@iftex@tex$$f(a) > f(x) < f(b)$$@end tex@end iftex@ifinfo@examplef(a) > f(x) < f(b)@end example@end ifinfo@noindentThis condition guarantees that a minimum is contained somewhere withinthe interval.  On each iteration a new point @math{x'} is selected usingone of the available algorithms.  If the new point is a better estimateof the minimum, @math{f(x') < f(x)}, then the current estimate of theminimum @math{x} is updated.  The new point also allows the size of thebounded interval to be reduced, by choosing the most compact set ofpoints which satisfies the constraint @math{f(a) > f(x) < f(b)}.  Theinterval is reduced until it encloses the true minimum to a desiredtolerance.  This provides a best estimate of the location of the minimumand a rigorous error estimate.Several bracketing algorithms are available within a single framework.The user provides a high-level driver for the algorithm, and thelibrary provides the individual functions necessary for each of thesteps.  There are three main phases of the iteration.  The steps are,@itemize @bullet@iteminitialize minimizer state, @var{s}, for algorithm @var{T}@itemupdate @var{s} using the iteration @var{T}@itemtest @var{s} for convergence, and repeat iteration if necessary@end itemize@noindentThe state for the minimizers is held in a @code{gsl_min_fminimizer}struct.  The updating procedure uses only function evaluations (notderivatives).@node Minimization Caveats@section Caveats@cindex Minimization, caveatsNote that minimization functions can only search for one minimum at atime.  When there are several minima in the search area, the firstminimum to be found will be returned; however it is difficult to predictwhich of the minima this will be. @emph{In most cases, no error will bereported if you try to find a minimum in an area where there is morethan one.}With all minimization algorithms it can be difficult to determine thelocation of the minimum to full numerical precision.  The behavior of thefunction in the region of the minimum @math{x^*} can be approximated bya Taylor expansion,@iftex@tex$$y = f(x^*) + {1 \over 2} f''(x^*) (x - x^*)^2$$@end tex@end iftex@ifinfo@exampley = f(x^*) + (1/2) f''(x^*) (x - x^*)^2@end example@end ifinfo@noindentand the second term of this expansion can be lost when added to thefirst term at finite precision.  This magnifies the error in locating@math{x^*}, making it proportional to @math{\sqrt \epsilon} (where@math{\epsilon} is the relative accuracy of the floating point numbers).For functions with higher order minima, such as @math{x^4}, themagnification of the error is correspondingly worse.  The best that canbe achieved is to converge to the limit of numerical accuracy in thefunction values, rather than the location of the minimum itself.@node Initializing the Minimizer@section Initializing the Minimizer@deftypefun {gsl_min_fminimizer *} gsl_min_fminimizer_alloc (const gsl_min_fminimizer_type * @var{T})This function returns a pointer to a newly allocated instance of aminimizer of type @var{T}.  For example, the following codecreates an instance of a golden section minimizer,@exampleconst gsl_min_fminimizer_type * T   = gsl_min_fminimizer_goldensection;gsl_min_fminimizer * s   = gsl_min_fminimizer_alloc (T);@end exampleIf there is insufficient memory to create the minimizer then the functionreturns a null pointer and the error handler is invoked with an errorcode of @code{GSL_ENOMEM}.@end deftypefun@deftypefun int gsl_min_fminimizer_set (gsl_min_fminimizer * @var{s}, gsl_function * @var{f}, double @var{x_minimum}, double @var{x_lower}, double @var{x_upper})This function sets, or resets, an existing minimizer @var{s} to use thefunction @var{f} and the initial search interval [@var{x_lower},@var{x_upper}], with a guess for the location of the minimum@var{x_minimum}.If the interval given does not contain a minimum, then the functionreturns an error code of @code{GSL_FAILURE}.@end deftypefun@deftypefun int gsl_min_fminimizer_set_with_values (gsl_min_fminimizer * @var{s}, gsl_function * @var{f}, double @var{x_minimum}, double @var{f_minimum}, double @var{x_lower}, double @var{f_lower}, double @var{x_upper}, double @var{f_upper})This function is equivalent to @code{gsl_min_fminimizer_set} but usesthe values @var{f_minimum}, @var{f_lower} and @var{f_upper} instead ofcomputing @code{f(x_minimum)}, @code{f(x_lower)} and @code{f(x_upper)}.@end deftypefun@deftypefun void gsl_min_fminimizer_free (gsl_min_fminimizer * @var{s})This function frees all the memory associated with the minimizer@var{s}.@end deftypefun@deftypefun {const char *} gsl_min_fminimizer_name (const gsl_min_fminimizer * @var{s})This function returns a pointer to the name of the minimizer.  For example,@exampleprintf ("s is a '%s' minimizer\n",        gsl_min_fminimizer_name (s));@end example@noindentwould print something like @code{s is a 'brent' minimizer}.@end deftypefun@node Providing the function to minimize@section Providing the function to minimize@cindex minimization, providing a function to minimizeYou must provide a continuous function of one variable for theminimizers to operate on.  In order to allow for general parameters thefunctions are defined by a @code{gsl_function} data type(@pxref{Providing the function to solve}).@node Minimization Iteration@section IterationThe following functions drive the iteration of each algorithm.  Eachfunction performs one iteration to update the state of any minimizer of thecorresponding type.  The same functions work for all minimizers so thatdifferent methods can be substituted at runtime without modifications tothe code.@deftypefun int gsl_min_fminimizer_iterate (gsl_min_fminimizer * @var{s})This function performs a single iteration of the minimizer @var{s}.  If theiteration encounters an unexpected problem then an error code will bereturned,@table @code@item GSL_EBADFUNCthe iteration encountered a singular point where the function evaluatedto @code{Inf} or @code{NaN}.@item GSL_FAILUREthe algorithm could not improve the current best approximation orbounding interval.@end table@end deftypefunThe minimizer maintains a current best estimate of the position of theminimum at all times, and the current interval bounding the minimum.This information can be accessed with the following auxiliary functions,@deftypefun double gsl_min_fminimizer_x_minimum (const gsl_min_fminimizer * @var{s})This function returns the current estimate of the position of theminimum for the minimizer @var{s}.@end deftypefun@deftypefun double gsl_min_fminimizer_x_upper (const gsl_min_fminimizer * @var{s})@deftypefunx double gsl_min_fminimizer_x_lower (const gsl_min_fminimizer * @var{s})These functions return the current upper and lower bound of the intervalfor the minimizer @var{s}.@end deftypefun@deftypefun double gsl_min_fminimizer_f_minimum (const gsl_min_fminimizer *@var{s})@deftypefunx double gsl_min_fminimizer_f_upper (const gsl_min_fminimizer *@var{s})@deftypefunx double gsl_min_fminimizer_f_lower (const gsl_min_fminimizer *@var{s})These functions return the value of the function at the current estimateof the minimum and at the upper and lower bounds of interval for theminimizer @var{s}.@end deftypefun@node Minimization Stopping Parameters@section Stopping Parameters@cindex minimization, stopping parametersA minimization procedure should stop when one of the followingconditions is true:@itemize @bullet@itemA minimum has been found to within the user-specified precision.@itemA user-specified maximum number of iterations has been reached.@itemAn error has occurred.@end itemize@noindentThe handling of these conditions is under user control.  The functionbelow allows the user to test the precision of the current result.@deftypefun int gsl_min_test_interval (double @var{x_lower}, double @var{x_upper},  double @var{epsabs}, double @var{epsrel})This function tests for the convergence of the interval [@var{x_lower},@var{x_upper}] with absolute error @var{epsabs} and relative error@var{epsrel}.  The test returns @code{GSL_SUCCESS} if the followingcondition is achieved,@tex\beforedisplay$$|a - b| < \hbox{\it epsabs} + \hbox{\it epsrel\/}\, \min(|a|,|b|)$$\afterdisplay@end tex@ifinfo@example|a - b| < epsabs + epsrel min(|a|,|b|) @end example@end ifinfo@noindentwhen the interval @math{x = [a,b]} does not include the origin.  If theinterval includes the origin then @math{\min(|a|,|b|)} is replaced byzero (which is the minimum value of @math{|x|} over the interval).  Thisensures that the relative error is accurately estimated for minima closeto the origin.This condition on the interval also implies that any estimate of theminimum @math{x_m} in the interval satisfies the same condition with respectto the true minimum @math{x_m^*},@tex\beforedisplay$$|x_m - x_m^*| < \hbox{\it epsabs} + \hbox{\it epsrel\/}\, x_m^*$$\afterdisplay@end tex@ifinfo@example|x_m - x_m^*| < epsabs + epsrel x_m^*@end example@end ifinfo@noindentassuming that the true minimum @math{x_m^*} is contained within the interval.@end deftypefun@comment ============================================================@node Minimization Algorithms@section Minimization AlgorithmsThe minimization algorithms described in this section require an initialinterval which is guaranteed to contain a minimum --- if @math{a} and@math{b} are the endpoints of the interval and @math{x} is an estimateof the minimum then @math{f(a) > f(x) < f(b)}.  This ensures that thefunction has at least one minimum somewhere in the interval.  If a validinitial interval is used then these algorithm cannot fail, provided thefunction is well-behaved.@deffn {Minimizer} gsl_min_fminimizer_goldensection@cindex golden section algorithm for finding minima@cindex minimum finding, golden section algorithmThe @dfn{golden section algorithm} is the simplest method of bracketingthe minimum of a function.  It is the slowest algorithm provided by thelibrary, with linear convergence.On each iteration, the algorithm first compares the subintervals fromthe endpoints to the current minimum.  The larger subinterval is dividedin a golden section (using the famous ratio @math{(3-\sqrt 5)/2 =0.3189660}@dots{}) and the value of the function at this new point iscalculated.  The new value is used with the constraint @math{f(a') >f(x') < f(b')} to a select new interval containing the minimum, bydiscarding the least useful point.  This procedure can be continuedindefinitely until the interval is sufficiently small.  Choosing thegolden section as the bisection ratio can be shown to provide thefastest convergence for this type of algorithm.@end deffn@comment ============================================================@deffn {Minimizer} gsl_min_fminimizer_brent@cindex brent's method for finding minima@cindex minimum finding, brent's methodThe @dfn{Brent minimization algorithm} combines a parabolicinterpolation with the golden section algorithm.  This produces a fastalgorithm which is still robust.The outline of the algorithm can be summarized as follows: on eachiteration Brent's method approximates the function using aninterpolating parabola through three existing points.  The minimum of theparabola is taken as a guess for the minimum.  If it lies within thebounds of the current interval then the interpolating point is accepted,and used to generate a smaller interval.  If the interpolating point isnot accepted then the algorithm falls back to an ordinary golden sectionstep.  The full details of Brent's method include some additional checksto improve convergence.@end deffn@comment ============================================================@node Minimization Examples@section ExamplesThe following program uses the Brent algorithm to find the minimum ofthe function @math{f(x) = \cos(x) + 1}, which occurs at @math{x = \pi}.The starting interval is @math{(0,6)}, with an initial guess for theminimum of @math{2}.@example@verbatiminclude examples/min.c@end example@noindentHere are the results of the minimization procedure.@smallexamplebash$ ./a.out @verbatiminclude examples/min.out@end smallexample@node Minimization References and Further Reading@section References and Further Reading@noindentFurther information on Brent's algorithm is available in the followingbook,@itemize @asis@itemRichard Brent, @cite{Algorithms for minimization without derivatives},Prentice-Hall (1973), republished by Dover in paperback (2002), ISBN0-486-41998-3.@end itemize

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -