This is an archival dump of old wiki content --- see scipy.org for current material.
Please see http://scipy-cookbook.readthedocs.org/

SciPy's optimization package is scipy.optimize. The most basic non-linear optimization functions are:

See the scipy.optimze documentation for details.

This is a quick demonstration of generating data from several Bessel functions and finding some local maxima using fminbound. This uses ipython with the -pylab switch.

   1 from scipy import optimize, special
   2 from numpy import *
   3 from pylab import *
   4 
   5 x = arange(0,10,0.01)
   6 
   7 for k in arange(0.5,5.5):
   8      y = special.jv(k,x)
   9      plot(x,y)
  10      f = lambda x: -special.jv(k,x)
  11      x_max = optimize.fminbound(f,0,6)
  12      plot([x_max], [special.jv(k,x_max)],'ro')
  13 
  14 title('Different Bessel functions and their local maxima')
  15 show()

#class left
inline:NumPyOptimizationSmall.png

Optimization Example


CategoryCookbook

SciPy: Cookbook/OptimizationDemo1 (last edited 2015-10-24 17:48:24 by anonymous)