Skip to content

Instantly share code, notes, and snippets.

View stevenyepes's full-sized avatar

Jhonatan Steven Yepes stevenyepes

View GitHub Profile
@stevenyepes
stevenyepes / goldensection.py
Created February 14, 2017 21:08 — forked from crankycoder/goldensection.py
A demonstration of the golden section search algorithm
from math import sqrt
phi = (1 + sqrt(5))/2
resphi = 2 - phi
# a and b are the current bounds; the minimum is between them.
# c is the center pointer pushed slightly left towards a
def goldenSectionSearch(f, a, c, b, absolutePrecision):
if abs(a - b) < absolutePrecision:
return (a + b)/2
# Create a new possible center, in the area between c and b, pushed against c