# ## MIT License

# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#

# In[1]:
import matplotlib.pyplot as pt
from math import sqrt
# In[20]:
a = 0
b = 1
#tau = .3
tau = (sqrt(5)-1)/2
m1 = a + (1-tau) * (b-a)
m2 = a + tau * (b-a)
# In[21]:
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")
# Now see if any function evaluations can be reused if we move to the "left" subinterval:
# In[23]:
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")
# Check numerically:
# In[29]:
m1 - m2**2
# In[ ]: