Why are you numpy limited? Scipy has a package that does exactly what you want:
http://docs.scipy.org/doc/scipy/reference/optimize.nonlin.html
One lesson I learned: numerical programming is difficult, so don't do this :)
In any case, if you are configured to create the algorithm yourself, the scipy doc page that I linked (required forever to load, btw) gives you a list of algorithms to start with. One of the methods that I used earlier is to discretize the function to the extent that is necessary for your problem. (That is, tune \ delta x so that it is much smaller than the characteristic size in your problem.) This allows you to look for function functions (for example, changes in sign). And, you can easily calculate the derivative of the segment (possibly starting from kindergarten), so your discretized function has a well-defined first derivative. Since you configured dx less than typical, you are guaranteed not to miss any function features that are important to your problem.
If you want to know what the "characteristic size" means, find some parameter of your function with units of length or length 1 /. That is, for some function f (x), suppose that x has units of length and f has no units. Then look for things that multiply x. For example, if you want to sample cos (\ pi x), the parameter that multiplies x (if x has units of length) should have units of length 1 /. Thus, the characteristic size cos (\ pi x) is 1 / \ pi. If you make your sampling much smaller, you will not have any problems. Of course, this trick will not always work, so you may need to work a little.
Bendudede
source share