All problems
Golden Section Interval Update
Problem
Given a bracket [a, b] with interior probe points, one golden section iteration keeps the subinterval around the smaller probe: keep [a, d] when f(c) < f(d) and [c, b] otherwise, where c and d are the probes.
The probe offsets are r * (b - a) with r = (sqrt(5) - 1) / 2. Given a, b, f(c), and f(d), return the new bracket [lo, hi].
Hint
The probe ordering depends on the interval orientation; use b - r*(b-a) and a + r*(b-a).
Test cases
case 1
in: [0,1,1,2]
expected: [0,0.6180339887498949]
case 2
in: [0,1,3,2]
expected: [0.3819660112501051,1]
case 3
in: [-2,2,0.5,0.5]
expected: [-0.4721359549995796,2]
Starter codePython
def golden_section_interval_update(a, b, fc, fd):
# Your code here
pass3 test cases · run your code against them in the editor