This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |