Getting ready

We focus on the search for the local minima of a function f(x) in an interval [a, b] (the search for local maxima can then be regarded as the search of the local minima of the function –f(x) in the same interval). For this task, we have the minimize_scalar routine in the scipy.optimize module. It accepts as obligatory input a univariate function f(x), together with a search method.

Most search methods are based on the idea of bracketing that we used for root finding, although the concept of a bracket is a bit different in this setting. In this case, a good bracket is a triple x < y < zwhere f(y) is less than both f(x) and f(z). If the function is continuous, its graph presents a U-shape on a bracket. This guarantees the existence of a minimum inside of the subinterval [x, z]. A successful bracketing method will look, on each successive step, for the target extremum in either [x, y] or [y, z].

Let's construct a simple bracketing method for testing purposes. Assume we have an initial bracket a < c < b. By quadratic interpolation, we construct a parabola through the points (a, f(a))(c, f(c)), and (b, f(b)). Because of the U-shape condition, there must be a minimum (easily computable) for the interpolating parabola, say (d, f(d)). It is not hard to prove that the value d lies between the midpoints of the subintervals [a, c], and [c, b]. We will use this point d for our next bracketing step. For example, if it happens that c < d, then the next bracket will be either c < d < b, or a < c < d. Easy enough! Let's implement this method.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset