I have forgotten

COST (GBP)
4.00
0.00
0

# Golden

viewed 3537 times and licensed 122 times
Calculates the minimum of a one-dimensional real function using the golden section search method.
Controller: CodeCogs
Contents

C++

## Golden

 doublegolden( double (*f)(double)[function pointer] double a double b double c double eps = 1E-10 )
Given a user-defined function f and a bracketing triplet of abscissas $\inline&space;(a,&space;b,&space;c)$ (such that a < b < c and $\inline&space;f(a)&space;>&space;f(b)&space;<&space;f(c)$) this routine performs a golden section search for the minimum, isolating it to a fractional precision ofabout eps . Finally it returns the abscissa corresponding to the minimum of the function.

This method involves evaluating the function at some point x in the larger of the two intervals $\inline&space;(a,&space;b)$ or $\inline&space;(b,&space;c)$. If $\inline&space;f(x)&space;<&space;f(b)$ then x replaces the midpoint b, and b becomes an end point. If $\inline&space;f(x)&space;>&space;f(b)$ then b remains the midpoint with x replacing one of the end points. Either way the width of the bracketing interval will reduce and the position of the minima will be better defined. The procedure is then repeated until the width achieves a desired tolerance. It can be shown that if the new test point x is chosen to be a proportion $\inline&space;\phi&space;=&space;\left(&space;3&space;-&space;\sqrt(5)&space;\right)&space;/&space;2$ (the golden section) along the larger sub-interval, measured from the mid-point b, then the width of the full interval will reduce at an optimal rate.

Below you will find a diagram describing the evolution of the golden section search algorithm. The triples at consecutive steps are
$(1,&space;3,&space;2)&space;\qquad&space;(5,&space;3,&space;2)&space;\qquad&space;(5,&space;3,&space;4)&space;\qquad&space;(5,&space;3,&space;6)$

### Example 1

#include <codecogs/maths/optimization/golden.h>

#include <iostream>
#include <iomanip>
#include <cmath>

// user-defined function
double f(double x) {
return x * sin(x) - 2 * cos(x);
}

int main()
{
double x = Maths::Optimization::golden(f, 5, 6, 7);
std::cout << "Function minimum is Y = " << std::setprecision(13) << f(x);
std::cout << std::endl;
std::cout << "for X = " << x << std::endl;
return 0;
}
Output:
Function minimum is Y = -4.794621373204
for X = 5.000000000244

## References:

• N.A.Thacker, T.F.Cootes, "Vision Through Optimization", http://homepages.inf.ed.ac.uk/rbf/CVonline/LOCAL_COPIES/BMVA96Tut/node17.html

### Parameters

 f the user-defined function a the first point of the bracketing triplet b the second point of the triplet c the third point of the triplet eps Default value = 1E-10

### Returns

The approximated abscissa coresponding to the minimum of the function.

### Authors

Lucian Bentea (August 2005)
##### Source Code

Source code is available when you agree to a GP Licence or buy a Commercial Licence.

Not a member, then Register with CodeCogs. Already a Member, then Login.
{"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 8, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0}