Copyright (C) 2020 Andreas Kloeckner
import matplotlib.pyplot as pt
from math import sqrt
a = 0
b = 1
#tau = .3
tau = (sqrt(5)-1)/2
m1 = a + (1-tau) * (b-a)
m2 = a + tau * (b-a)
pt.xlim([a-0.5, b+0.5])
pt.ylim([-0.1, 0.2])
pt.grid()
pt.plot([a,b], [0,0], "ob")
pt.plot([m1, m2], [0,0], "or")
[<matplotlib.lines.Line2D at 0x7f4072f19ca0>]
Now see if any function evaluations can be reused if we move to the "left" subinterval:
pt.xlim([a-0.5, b+0.5])
pt.ylim([-0.1, 0.2])
pt.grid()
pt.plot([a,b], [0,0], "ob")
pt.plot([m1, m2], [0,0], "or")
# Same as above up to this point
pt.plot([0, m2*m1, m2*m2, m2*b], [0.1]*4, "og")
[<matplotlib.lines.Line2D at 0x7f4072b23b20>]
Check numerically:
m1 - m2**2
-1.1102230246251565e-16