Python optimize fmin gives A value in x_new is above the interpolation range error
Question: I am trying to interpolate the minimum of a quadratic function of which I have
three samples. The first test in the code snippet below works. It gives:
[![test
1](http://i.stack.imgur.com/tzTYq.png)](http://i.stack.imgur.com/tzTYq.png)

In the second test there are two similar values. The minimum of my quadratic
function should lie in between. However, I get the following error

    
    
    "A value in x_new is above the interpolation range."
    

Does anybody know a way how to solve this.

    
    
    from matplotlib import pyplot as plt
    from scipy import interpolate
    from scipy import optimize
    
    def test(x, y):
        xmin, ymin = getMin(x, y)
        plt.figure()
        plt.plot(x, y, 'o-r', xmin, ymin, 'bx')
    
    def getMin(x, y):
        f = interpolate.interp1d(x, y, kind="quadratic")
        xmin = optimize.fmin(lambda x: f(x), x[1])
        ymin = f(xmin)
        return xmin[0], ymin[0]
    
    test([18, 19, 20], [-34.3, -74.3, -7.3])
    test([18, 19, 20], [-34.3, -74.3, -74.2])
    


Answer: Analytically works like a charm

    
    
    def getMinFit(x, y):
        p = np.polyfit(x, y, 2)
        xmin = -p[1]/(2*p[0])
        ymin = np.polyval(p, xmin)
        return xmin, ymin
    

[![enter image description
here](http://i.stack.imgur.com/PfyQq.png)](http://i.stack.imgur.com/PfyQq.png)

