3622
правки
Изменения
м
'''int''' r = x2
'''int''' l = x1
'''while''' abs(r - l) > eps '''return''' (x1 + x2) / 2
→Псевдокод
===Псевдокод===
'''int''' goldenSectionSearch(f: '''intdouble -> double''' f, l: '''intdouble''' l, r: '''intdouble''' r, eps: '''intdouble''' eps): '''double''' phi = (1 + sqrt(5)) / 2 '''double''' resphi = 2 - phi '''double''' x1 = l + resphi * (r - l) '''int''' x2 = r - resphi * (r - l) '''int''' f1 = f(x1) '''int''' f2 = f(x2)
'''do'''
'''if''' f1 < f2
x2 = x1
f2 = f1
f1 = f(x1)
'''else'''
x1 = x2
f1 = f2
x2 = r - resphi * (r - l)
f2 = f(x2)
==Время работы==