Golden-section search to find the positive minimum of the Gamma function.
#!/usr/bin/env python3
from scipy.special import gamma
a,b=.1,2
n=25
p=(5**.5-1)/2
c=b-p*(b-a)
d=a+p*(b-a)
fc,fd=gamma(c),gamma(d)
print(f'{"Iter":>4} {"x":>12} {"gamma(x)":>12}')
for i in range(1,n+1):
if fc<fd:
b,d,fd=d,c,fc
c=b-p*(b-a)
fc=gamma(c)
x,f=c,fc
else:
a,c,fc=c,d,fd
d=a+p*(b-a)
fd=gamma(d)
x,f=d,fd
print(f"{i:4d} {x:12.8f} {f:12.8f}")
print(f"\nLocal minimum approx: x = {x:.10f}, gamma(x) = {f:.10f}")
