I would like to find a local maximum of a function f(x) where x can range between two fixed values since f(x) would tend to +inf if x tends to +inf. I've been trying to use such algorithms as scipy.optimize.fmin_l_bfgs_band scipy.optimize.fmin_tnc (from scipy.ref guide) but I can't figure out how to correctly set the bounds. (I know, it must be something stupid but I'm quite a noob with Python). Let's give an easy example:
>>>import scipy.optimize as opt
>>>import scipy
>>>from numpy import *
>>>def f (x): return x**(1/2.0)
>>>max_x = opt.fmin_l_bfgs_b(lambda x: -f(x), [0,0], bounds=([0,0],[9,0])) #I want x to range between 0 and 9 and fmax be 3
The output is pretty strange, though: I get nothing at all! Not even an error! What am I missing?
>>> max_x<enter> say?max_xwill be a 3-tuple as per the docs... The 3rd element will also give some information as to progress-sqrt(x)has no local maxima?