find maximum and minimum for any function I'm writing an optimization algorithm thats supposed to find the maximum and minimum value of any given function. Whats the fastest numerical approuch to do so?
 A: I don't know how this method is called, so IÄll describe it in full:
If $f\colon[a,b]\to\mathbb R$ has only one local maximum in $[a,b]$ one can use a search basesd on the golden ratio $\phi=\frac{\sqrt 5-1}{2}$.
Given $x_0<x_1<x_2<x_3$ with $x_2-x_0=x_3-x_1=\phi(x_3-x_1)$ and the unique local maximum in $[x_0,x_3]$, do as follows:
If $f(x_1)\ge f(x_2)$ replace $(x_0,x_1,x_2,x_3)$ with $(x_0, x_0+x_2-x_1, x_1, x_2)$, otherwise with $(x_1, x_2, x_1+x_3-x_2,x_3)$ and repeat.
Care must be taken if due to rounding errors the correct order of the $x_i$ might be destroyed.
A: It is very helpful to have an estimate for the number and distribution of local maxima, because most methods can only find a local maximum.  Without such knowledge, I would initially partition the interval into a large number of subintervals, and maximize over each one.  Within each subinterval, you could use @Hagen von Eitzen's algorithm, or the bisection method, or Newton's method to find a zero of $f'(x)$.  After maximizing over each interval, take the maximum of the maxima and (hopefully) there you go.  You can't be sure you've got the maximum, because if one of your intervals had two local maxima, you might have found the smaller one.
