[Scipy-svn] r5130 - in trunk/doc/source/tutorial: . examples

scipy-svn@scip... scipy-svn@scip...
Sun Nov 16 06:50:43 CST 2008


Author: ptvirtan
Date: 2008-11-16 06:50:11 -0600 (Sun, 16 Nov 2008)
New Revision: 5130

Removed:
   trunk/doc/source/tutorial/examples/3-1
   trunk/doc/source/tutorial/examples/3-2
Modified:
   trunk/doc/source/tutorial/examples/1-1
   trunk/doc/source/tutorial/examples/10-2-1
   trunk/doc/source/tutorial/examples/10-2-2
   trunk/doc/source/tutorial/examples/10-3-1
   trunk/doc/source/tutorial/examples/10-3-2
   trunk/doc/source/tutorial/examples/10-3-6
   trunk/doc/source/tutorial/examples/10-4-4
   trunk/doc/source/tutorial/examples/4-1
   trunk/doc/source/tutorial/examples/4-2
   trunk/doc/source/tutorial/examples/4-3
   trunk/doc/source/tutorial/examples/4-4
   trunk/doc/source/tutorial/examples/4-5
   trunk/doc/source/tutorial/examples/4-6
   trunk/doc/source/tutorial/examples/5-1
   trunk/doc/source/tutorial/examples/5-2
   trunk/doc/source/tutorial/examples/5-3
   trunk/doc/source/tutorial/examples/5-4
   trunk/doc/source/tutorial/examples/5-5
   trunk/doc/source/tutorial/examples/5-6
   trunk/doc/source/tutorial/examples/5-9
   trunk/doc/source/tutorial/index.rst
Log:
docs: Ensure that examples in the tutorial run with current Scipy

Modified: trunk/doc/source/tutorial/examples/1-1
===================================================================
--- trunk/doc/source/tutorial/examples/1-1	2008-11-16 11:53:13 UTC (rev 5129)
+++ trunk/doc/source/tutorial/examples/1-1	2008-11-16 12:50:11 UTC (rev 5130)
@@ -1,37 +1,55 @@
 >>> info(optimize.fmin)
  fmin(func, x0, args=(), xtol=0.0001, ftol=0.0001, maxiter=None, maxfun=None,
-      full_output=0, printmessg=1)
+      full_output=0, disp=1, retall=0, callback=None)
 
-Minimize a function using the simplex algorithm.
+Minimize a function using the downhill simplex algorithm.
 
-Description:
+:Parameters:
 
-  Uses a Nelder-Mead simplex algorithm to find the minimum of function
-  of one or more variables.
+  func : callable func(x,*args)
+      The objective function to be minimized.
+  x0 : ndarray
+      Initial guess.
+  args : tuple
+      Extra arguments passed to func, i.e. ``f(x,*args)``.
+  callback : callable
+      Called after each iteration, as callback(xk), where xk is the
+      current parameter vector.
 
-Inputs:
+:Returns: (xopt, {fopt, iter, funcalls, warnflag})
 
-  func -- the Python function or method to be minimized.
-  x0 -- the initial guess.
-  args -- extra arguments for func.
-  xtol -- relative tolerance
+  xopt : ndarray
+      Parameter that minimizes function.
+  fopt : float
+      Value of function at minimum: ``fopt = func(xopt)``.
+  iter : int
+      Number of iterations performed.
+  funcalls : int
+      Number of function calls made.
+  warnflag : int
+      1 : Maximum number of function evaluations made.
+      2 : Maximum number of iterations reached.
+  allvecs : list
+      Solution at each iteration.
 
-Outputs: (xopt, {fopt, warnflag})
+*Other Parameters*:
 
-  xopt -- minimizer of function
+  xtol : float
+      Relative error in xopt acceptable for convergence.
+  ftol : number
+      Relative error in func(xopt) acceptable for convergence.
+  maxiter : int
+      Maximum number of iterations to perform.
+  maxfun : number
+      Maximum number of function evaluations to make.
+  full_output : bool
+      Set to True if fval and warnflag outputs are desired.
+  disp : bool
+      Set to True to print convergence messages.
+  retall : bool
+      Set to True to return list of solutions at each iteration.
 
-  fopt -- value of function at minimum: fopt = func(xopt)
-  warnflag -- Integer warning flag:
-              1 : 'Maximum number of function evaluations.'
-              2 : 'Maximum number of iterations.'
+:Notes:
 
-Additional Inputs:
-
-  xtol -- acceptable relative error in xopt for convergence.
-  ftol -- acceptable relative error in func(xopt) for convergence.
-  maxiter -- the maximum number of iterations to perform.
-  maxfun -- the maximum number of function evaluations.
-  full_output -- non-zero if fval and warnflag outputs are desired.
-  printmessg -- non-zero to print convergence messages.
-  
-  
+    Uses a Nelder-Mead simplex algorithm to find the minimum of
+    function of one or more variables.

Modified: trunk/doc/source/tutorial/examples/10-2-1
===================================================================
--- trunk/doc/source/tutorial/examples/10-2-1	2008-11-16 11:53:13 UTC (rev 5129)
+++ trunk/doc/source/tutorial/examples/10-2-1	2008-11-16 12:50:11 UTC (rev 5130)
@@ -1,12 +1,13 @@
 >>> A = mat('[1 3 5; 2 5 1; 2 3 8]')
 >>> A
-Matrix([[1, 3, 5],
-       [2, 5, 1],
-       [2, 3, 8]])
+matrix([[1, 3, 5],
+        [2, 5, 1],
+        [2, 3, 8]])
 >>> A.I
-Matrix([[-1.48,  0.36,  0.88],
-       [ 0.56,  0.08, -0.36],
-       [ 0.16, -0.12,  0.04]])
+matrix([[-1.48,  0.36,  0.88],
+        [ 0.56,  0.08, -0.36],
+        [ 0.16, -0.12,  0.04]])
+>>> from scipy import linalg
 >>> linalg.inv(A)
 array([[-1.48,  0.36,  0.88],
        [ 0.56,  0.08, -0.36],

Modified: trunk/doc/source/tutorial/examples/10-2-2
===================================================================
--- trunk/doc/source/tutorial/examples/10-2-2	2008-11-16 11:53:13 UTC (rev 5129)
+++ trunk/doc/source/tutorial/examples/10-2-2	2008-11-16 12:50:11 UTC (rev 5130)
@@ -1,9 +1,9 @@
 >>> A = mat('[1 3 5; 2 5 1; 2 3 8]')
 >>> b = mat('[10;8;3]')
 >>> A.I*b
-Matrix([[-9.28],
-       [ 5.16],
-       [ 0.76]])
+matrix([[-9.28],
+        [ 5.16],
+        [ 0.76]])
 >>> linalg.solve(A,b)
 array([[-9.28],
        [ 5.16],

Modified: trunk/doc/source/tutorial/examples/10-3-1
===================================================================
--- trunk/doc/source/tutorial/examples/10-3-1	2008-11-16 11:53:13 UTC (rev 5129)
+++ trunk/doc/source/tutorial/examples/10-3-1	2008-11-16 12:50:11 UTC (rev 5130)
@@ -1,3 +1,4 @@
+>>> from scipy import linalg
 >>> A = mat('[1 5 2; 2 4 1; 3 6 2]')
 >>> la,v = linalg.eig(A)
 >>> l1,l2,l3 = la
@@ -5,14 +6,14 @@
 (7.95791620491+0j) (-1.25766470568+0j) (0.299748500767+0j)
 
 >>> print v[:,0]
-array([-0.5297, -0.4494, -0.7193])
+[-0.5297175  -0.44941741 -0.71932146]
 >>> print v[:,1]
-[-0.9073  0.2866  0.3076]
+[-0.90730751  0.28662547  0.30763439]
 >>> print v[:,2]
-[ 0.2838 -0.3901  0.8759]
+[ 0.28380519 -0.39012063  0.87593408]
 >>> print sum(abs(v**2),axis=0)
 [ 1.  1.  1.]
 
 >>> v1 = mat(v[:,0]).T
 >>> print max(ravel(abs(A*v1-l1*v1)))
-4.4408920985e-16
+8.881784197e-16

Modified: trunk/doc/source/tutorial/examples/10-3-2
===================================================================
--- trunk/doc/source/tutorial/examples/10-3-2	2008-11-16 11:53:13 UTC (rev 5129)
+++ trunk/doc/source/tutorial/examples/10-3-2	2008-11-16 12:50:11 UTC (rev 5130)
@@ -1,22 +1,22 @@
 >>> A = mat('[1 3 2; 1 2 3]')
 >>> M,N = A.shape
 >>> U,s,Vh = linalg.svd(A)
->>> Sig = mat(diagsvd(s,M,N))
+>>> Sig = mat(linalg.diagsvd(s,M,N))
 >>> U, Vh = mat(U), mat(Vh)
 >>> print U
-Matrix([[-0.7071, -0.7071],
-       [-0.7071,  0.7071]])
+[[-0.70710678 -0.70710678]
+ [-0.70710678  0.70710678]]
 >>> print Sig
-Matrix([[ 5.1962,  0.    ,  0.    ],
-       [ 0.    ,  1.    ,  0.    ]])
+[[ 5.19615242  0.          0.        ]
+ [ 0.          1.          0.        ]]
 >>> print Vh
-Matrix([[-0.2722, -0.6804, -0.6804],
-       [-0.    , -0.7071,  0.7071],
-       [-0.9623,  0.1925,  0.1925]])
+[[ -2.72165527e-01  -6.80413817e-01  -6.80413817e-01]
+ [ -6.18652536e-16  -7.07106781e-01   7.07106781e-01]
+ [ -9.62250449e-01   1.92450090e-01   1.92450090e-01]]
 
 >>> print A
-Matrix([[1, 3, 2],
-       [1, 2, 3]])
+[[1 3 2]
+ [1 2 3]]
 >>> print U*Sig*Vh
-Matrix([[ 1.,  3.,  2.],
-       [ 1.,  2.,  3.]])
+[[ 1.  3.  2.]
+ [ 1.  2.  3.]]

Modified: trunk/doc/source/tutorial/examples/10-3-6
===================================================================
--- trunk/doc/source/tutorial/examples/10-3-6	2008-11-16 11:53:13 UTC (rev 5129)
+++ trunk/doc/source/tutorial/examples/10-3-6	2008-11-16 12:50:11 UTC (rev 5130)
@@ -1,3 +1,4 @@
+>>> from scipy import linalg
 >>> A = mat('[1 3 2; 1 4 5; 2 3 6]')
 >>> T,Z = linalg.schur(A)
 >>> T1,Z1 = linalg.schur(A,'complex')
@@ -3,33 +4,33 @@
 >>> T2,Z2 = linalg.rsf2csf(T,Z)
 >>> print T
-Matrix([[ 9.9001,  1.7895, -0.655 ],
-       [ 0.    ,  0.5499, -1.5775],
-       [ 0.    ,  0.5126,  0.5499]])
+[[ 9.90012467  1.78947961 -0.65498528]
+ [ 0.          0.54993766 -1.57754789]
+ [ 0.          0.51260928  0.54993766]]
 >>> print T2
-Matrix([[ 9.9001+0.j    , -0.3244+1.5546j, -0.8862+0.569j ],
-       [ 0.    +0.j    ,  0.5499+0.8993j,  1.0649-0.j    ],
-       [ 0.    +0.j    ,  0.    +0.j    ,  0.5499-0.8993j]])
+[[ 9.90012467 +0.00000000e+00j -0.32436598 +1.55463542e+00j
+  -0.88619748 +5.69027615e-01j]
+ [ 0.00000000 +0.00000000e+00j  0.54993766 +8.99258408e-01j
+   1.06493862 +1.37016050e-17j]
+ [ 0.00000000 +0.00000000e+00j  0.00000000 +0.00000000e+00j
+   0.54993766 -8.99258408e-01j]]
 >>> print abs(T1-T2) # different
-[[ 0.      2.1184  0.1949]
- [ 0.      0.      1.2676]
- [ 0.      0.      0.    ]]
+[[  1.24357637e-14   2.09205364e+00   6.56028192e-01]
+ [  0.00000000e+00   4.00296604e-16   1.83223097e+00]
+ [  0.00000000e+00   0.00000000e+00   4.57756680e-16]]
 >>> print abs(Z1-Z2) # different
-[[ 0.0683  1.1175  0.1973]
- [ 0.1186  0.5644  0.247 ]
- [ 0.1262  0.7645  0.1916]]
+[[ 0.06833781  1.10591375  0.23662249]
+ [ 0.11857169  0.5585604   0.29617525]
+ [ 0.12624999  0.75656818  0.22975038]]
 >>> T,Z,T1,Z1,T2,Z2 = map(mat,(T,Z,T1,Z1,T2,Z2))
->>> print abs(A-Z*T*Z.H)
-Matrix([[ 0.,  0.,  0.],
-       [ 0.,  0.,  0.],
-       [ 0.,  0.,  0.]])
->>> print abs(A-Z1*T1*Z1.H)
-Matrix([[ 0.,  0.,  0.],
-       [ 0.,  0.,  0.],
-       [ 0.,  0.,  0.]])
->>> print abs(A-Z2*T2*Z2.H)
-Matrix([[ 0.,  0.,  0.],
-       [ 0.,  0.,  0.],
-       [ 0.,  0.,  0.]])
-
-
-
+>>> print abs(A-Z*T*Z.H) # same
+[[  1.11022302e-16   4.44089210e-16   4.44089210e-16]
+ [  4.44089210e-16   1.33226763e-15   8.88178420e-16]
+ [  8.88178420e-16   4.44089210e-16   2.66453526e-15]]
+>>> print abs(A-Z1*T1*Z1.H) # same
+[[  1.00043248e-15   2.22301403e-15   5.55749485e-15]
+ [  2.88899660e-15   8.44927041e-15   9.77322008e-15]
+ [  3.11291538e-15   1.15463228e-14   1.15464861e-14]]
+>>> print abs(A-Z2*T2*Z2.H) # same
+[[  3.34058710e-16   8.88611201e-16   4.18773089e-18]
+ [  1.48694940e-16   8.95109973e-16   8.92966151e-16]
+ [  1.33228956e-15   1.33582317e-15   3.55373104e-15]]

Modified: trunk/doc/source/tutorial/examples/10-4-4
===================================================================
--- trunk/doc/source/tutorial/examples/10-4-4	2008-11-16 11:53:13 UTC (rev 5129)
+++ trunk/doc/source/tutorial/examples/10-4-4	2008-11-16 12:50:11 UTC (rev 5130)
@@ -1,10 +1,17 @@
->>> A = rand(3,3)
+>>> from scipy import special, random, linalg
+>>> A = random.rand(3,3)
 >>> B = linalg.funm(A,lambda x: special.jv(0,real(x)))
 >>> print A
-[[ 0.0593  0.5612  0.4403]
- [ 0.8797  0.2556  0.1452]
- [ 0.964   0.9666  0.1243]]
+[[ 0.72578091  0.34105276  0.79570345]
+ [ 0.65767207  0.73855618  0.541453  ]
+ [ 0.78397086  0.68043507  0.4837898 ]]
 >>> print B
-[[ 0.8206 -0.1212 -0.0612]
- [-0.1323  0.8256 -0.0627]
- [-0.2073 -0.1946  0.8516]]
+[[ 0.72599893 -0.20545711 -0.22721101]
+ [-0.27426769  0.77255139 -0.23422637]
+ [-0.27612103 -0.21754832  0.7556849 ]]
+>>> print linalg.eigvals(A)
+[ 1.91262611+0.j  0.21846476+0.j -0.18296399+0.j]
+>>> print special.jv(0, linalg.eigvals(A))
+[ 0.27448286+0.j  0.98810383+0.j  0.99164854+0.j]
+>>> print linalg.eigvals(B)
+[ 0.27448286+0.j  0.98810383+0.j  0.99164854+0.j]

Deleted: trunk/doc/source/tutorial/examples/3-1
===================================================================
--- trunk/doc/source/tutorial/examples/3-1	2008-11-16 11:53:13 UTC (rev 5129)
+++ trunk/doc/source/tutorial/examples/3-1	2008-11-16 12:50:11 UTC (rev 5130)
@@ -1,5 +0,0 @@
->>> def addsubtract(a,b):
-    if a > b:
-        return a - b
-    else:
-        return a + b

Deleted: trunk/doc/source/tutorial/examples/3-2
===================================================================
--- trunk/doc/source/tutorial/examples/3-2	2008-11-16 11:53:13 UTC (rev 5129)
+++ trunk/doc/source/tutorial/examples/3-2	2008-11-16 12:50:11 UTC (rev 5130)
@@ -1,2 +0,0 @@
->>> vec_addsubtract([0,3,6,9],[1,3,5,7])
-array([1, 6, 1, 2])

Modified: trunk/doc/source/tutorial/examples/4-1
===================================================================
--- trunk/doc/source/tutorial/examples/4-1	2008-11-16 11:53:13 UTC (rev 5129)
+++ trunk/doc/source/tutorial/examples/4-1	2008-11-16 12:50:11 UTC (rev 5130)
@@ -1,13 +1,25 @@
 >>> help(integrate)
-Methods for Integrating Functions
+ Methods for Integrating Functions given function object.
 
-  odeint        -- Integrate ordinary differential equations.
-  quad          -- General purpose integration.
-  dblquad       -- General purpose double integration.
-  tplquad       -- General purpose triple integration.
-  gauss_quad    -- Integrate func(x) using Gaussian quadrature of order n.
-  gauss_quadtol -- Integrate with given tolerance using Gaussian quadrature.
+   quad          -- General purpose integration.
+   dblquad       -- General purpose double integration.
+   tplquad       -- General purpose triple integration.
+   fixed_quad    -- Integrate func(x) using Gaussian quadrature of order n.
+   quadrature    -- Integrate with given tolerance using Gaussian quadrature.
+   romberg       -- Integrate func using Romberg integration.
 
-  See the orthogonal module (integrate.orthogonal) for Gaussian
-     quadrature roots and weights.
+ Methods for Integrating Functions given fixed samples.
 
+   trapz         -- Use trapezoidal rule to compute integral from samples.
+   cumtrapz      -- Use trapezoidal rule to cumulatively compute integral.
+   simps         -- Use Simpson's rule to compute integral from samples.
+   romb          -- Use Romberg Integration to compute integral from
+                    (2**k + 1) evenly-spaced samples.
+
+   See the special module's orthogonal polynomials (special) for Gaussian
+      quadrature roots and weights for other weighting factors and regions.
+
+ Interface to numerical integrators of ODE systems.
+
+   odeint        -- General integration of ordinary differential equations.
+   ode           -- Integrate ODE using VODE and ZVODE routines.

Modified: trunk/doc/source/tutorial/examples/4-2
===================================================================
--- trunk/doc/source/tutorial/examples/4-2	2008-11-16 11:53:13 UTC (rev 5129)
+++ trunk/doc/source/tutorial/examples/4-2	2008-11-16 12:50:11 UTC (rev 5130)
@@ -3,7 +3,7 @@
 (1.1178179380783249, 7.8663172481899801e-09)
 
 >>> I = sqrt(2/pi)*(18.0/27*sqrt(2)*cos(4.5)-4.0/27*sqrt(2)*sin(4.5)+
-    sqrt(2*pi)*special.fresnl(3/sqrt(pi))[0])
+    sqrt(2*pi)*special.fresnel(3/sqrt(pi))[0])
 >>> print I
 1.117817938088701
 

Modified: trunk/doc/source/tutorial/examples/4-3
===================================================================
--- trunk/doc/source/tutorial/examples/4-3	2008-11-16 11:53:13 UTC (rev 5129)
+++ trunk/doc/source/tutorial/examples/4-3	2008-11-16 12:50:11 UTC (rev 5130)
@@ -1,9 +1,9 @@
->>> from integrate import quad, Inf
+>>> from scipy.integrate import quad
 >>> def integrand(t,n,x):
-        return exp(-x*t) / t**n
+...     return exp(-x*t) / t**n
 
 >>> def expint(n,x): 
-        return quad(integrand, 1, Inf, args=(n, x))[0]
+...     return quad(integrand, 1, Inf, args=(n, x))[0]
 
 >>> vec_expint = vectorize(expint)
 

Modified: trunk/doc/source/tutorial/examples/4-4
===================================================================
--- trunk/doc/source/tutorial/examples/4-4	2008-11-16 11:53:13 UTC (rev 5129)
+++ trunk/doc/source/tutorial/examples/4-4	2008-11-16 12:50:11 UTC (rev 5130)
@@ -1,4 +1,4 @@
->>> result = quad(lambda x: expint(3, x), 0, Inf)
+>>> result = quad(lambda x: expint(3, x), 0, inf)
 >>> print result
 (0.33333333324560266, 2.8548934485373678e-09)  
 

Modified: trunk/doc/source/tutorial/examples/4-5
===================================================================
--- trunk/doc/source/tutorial/examples/4-5	2008-11-16 11:53:13 UTC (rev 5129)
+++ trunk/doc/source/tutorial/examples/4-5	2008-11-16 12:50:11 UTC (rev 5130)
@@ -1,7 +1,6 @@
->>> from __future__ import nested_scopes
->>> from integrate import quad, dblquad, Inf
+>>> from scipy.integrate import quad, dblquad
 >>> def I(n):
-    return dblquad(lambda t, x: exp(-x*t)/t**n, 0, Inf, lambda x: 1, lambda x: Inf) 
+...     return dblquad(lambda t, x: exp(-x*t)/t**n, 0, Inf, lambda x: 1, lambda x: Inf) 
 
 >>> print I(4)
 (0.25000000000435768, 1.0518245707751597e-09)

Modified: trunk/doc/source/tutorial/examples/4-6
===================================================================
--- trunk/doc/source/tutorial/examples/4-6	2008-11-16 11:53:13 UTC (rev 5129)
+++ trunk/doc/source/tutorial/examples/4-6	2008-11-16 12:50:11 UTC (rev 5130)
@@ -1,13 +1,13 @@
->>> from integrate import odeint
->>> from special import gamma, airy
+>>> from scipy.integrate import odeint
+>>> from scipy.special import gamma, airy
 >>> y1_0 = 1.0/3**(2.0/3.0)/gamma(2.0/3.0)
 >>> y0_0 = -1.0/3**(1.0/3.0)/gamma(1.0/3.0)
 >>> y0 = [y0_0, y1_0]
 >>> def func(y, t):
-        return [t*y[1],y[0]]
+...     return [t*y[1],y[0]]
 
 >>> def gradient(y,t):
-        return [[0,t],[1,0]]
+...     return [[0,t],[1,0]]
 
 >>> x = arange(0,4.0, 0.01)
 >>> t = x
@@ -15,8 +15,6 @@
 >>> y = odeint(func, y0, t)
 >>> y2 = odeint(func, y0, t, Dfun=gradient)
 
->>> import sys
->>> sys.float_output_precision = 6
 >>> print ychk[:36:6]
 [ 0.355028  0.339511  0.324068  0.308763  0.293658  0.278806]
 

Modified: trunk/doc/source/tutorial/examples/5-1
===================================================================
--- trunk/doc/source/tutorial/examples/5-1	2008-11-16 11:53:13 UTC (rev 5129)
+++ trunk/doc/source/tutorial/examples/5-1	2008-11-16 12:50:11 UTC (rev 5130)
@@ -1,37 +1,91 @@
+from scipy import optimize
 >>> info(optimize)
- Optimization Tools
+Optimization Tools
+==================
 
-A collection of general-purpose optimization routines.
+ A collection of general-purpose optimization routines.
 
-  fmin        --  Nelder-Mead Simplex algorithm
-                    (uses only function calls)
-  fmin_powell --  Powell's (modified) level set method (uses only 
-                    function calls)
-  fmin_bfgs   --  Quasi-Newton method (can use function and gradient)
-  fmin_ncg    --  Line-search Newton Conjugate Gradient (can use
-                    function, gradient and hessian).
-  leastsq     --  Minimize the sum of squares of M equations in
-                    N unknowns given a starting estimate.
+   fmin        --  Nelder-Mead Simplex algorithm
+                     (uses only function calls)
+   fmin_powell --  Powell's (modified) level set method (uses only
+                     function calls)
+   fmin_cg     --  Non-linear (Polak-Ribiere) conjugate gradient algorithm
+                     (can use function and gradient).
+   fmin_bfgs   --  Quasi-Newton method (Broydon-Fletcher-Goldfarb-Shanno);
+                     (can use function and gradient)
+   fmin_ncg    --  Line-search Newton Conjugate Gradient (can use
+                     function, gradient and Hessian).
+   leastsq     --  Minimize the sum of squares of M equations in
+                     N unknowns given a starting estimate.
 
- Scalar function minimizers
 
-  fminbound   --  Bounded minimization of a scalar function.
-  brent       --  1-D function minimization using Brent method.
-  golden      --  1-D function minimization using Golden Section method
-  bracket     --  Bracket a minimum (given two starting points)
- 
-Also a collection of general_purpose root-finding routines.
+  Constrained Optimizers (multivariate)
 
-  fsolve      --  Non-linear multi-variable equation solver.
+   fmin_l_bfgs_b -- Zhu, Byrd, and Nocedal's L-BFGS-B constrained optimizer
+                      (if you use this please quote their papers -- see help)
 
- Scalar function solvers
+   fmin_tnc      -- Truncated Newton Code originally written by Stephen Nash and
+                      adapted to C by Jean-Sebastien Roy.
 
-  brentq      --  quadratic interpolation Brent method
-  brenth      --  Brent method (modified by Harris with
-                    hyperbolic extrapolation)
-  ridder      --  Ridder's method
-  bisect      --  Bisection method
-  newton      --  Secant method or Newton's method
+   fmin_cobyla   -- Constrained Optimization BY Linear Approximation
 
-  fixed_point -- Single-variable fixed-point solver.
 
+  Global Optimizers
+
+   anneal      --  Simulated Annealing
+   brute       --  Brute force searching optimizer
+
+
+  Scalar function minimizers
+
+   fminbound   --  Bounded minimization of a scalar function.
+   brent       --  1-D function minimization using Brent method.
+   golden      --  1-D function minimization using Golden Section method
+   bracket     --  Bracket a minimum (given two starting points)
+
+
+ Also a collection of general-purpose root-finding routines.
+
+   fsolve      --  Non-linear multi-variable equation solver.
+
+
+  Scalar function solvers
+
+   brentq      --  quadratic interpolation Brent method
+   brenth      --  Brent method (modified by Harris with hyperbolic
+                     extrapolation)
+   ridder      --  Ridder's method
+   bisect      --  Bisection method
+   newton      --  Secant method or Newton's method
+
+   fixed_point --  Single-variable fixed-point solver.
+
+ A collection of general-purpose nonlinear multidimensional solvers.
+
+   broyden1            --  Broyden's first method - is a quasi-Newton-Raphson
+                           method for updating an approximate Jacobian and then
+                           inverting it
+   broyden2            --  Broyden's second method - the same as broyden1, but
+                           updates the inverse Jacobian directly
+   broyden3            --  Broyden's second method - the same as broyden2, but
+                           instead of directly computing the inverse Jacobian,
+                           it remembers how to construct it using vectors, and
+                           when computing inv(J)*F, it uses those vectors to
+                           compute this product, thus avoding the expensive NxN
+                           matrix multiplication.
+   broyden_generalized --  Generalized Broyden's method, the same as broyden2,
+                           but instead of approximating the full NxN Jacobian,
+                           it construct it at every iteration in a way that
+                           avoids the NxN matrix multiplication.  This is not
+                           as precise as broyden3.
+   anderson            --  extended Anderson method, the same as the
+                           broyden_generalized, but added w_0^2*I to before
+                           taking inversion to improve the stability
+   anderson2           --  the Anderson method, the same as anderson, but
+                           formulated differently
+
+ Utility Functions
+
+   line_search --  Return a step that satisfies the strong Wolfe conditions.
+   check_grad  --  Check the supplied derivative using finite difference
+                     techniques.

Modified: trunk/doc/source/tutorial/examples/5-2
===================================================================
--- trunk/doc/source/tutorial/examples/5-2	2008-11-16 11:53:13 UTC (rev 5129)
+++ trunk/doc/source/tutorial/examples/5-2	2008-11-16 12:50:11 UTC (rev 5130)
@@ -1,13 +1,14 @@
 >>> from scipy.optimize import fmin
->>> def rosen(x):  # The Rosenbrock function
-        return sum(100.0*(x[1:]-x[:-1]**2.0)**2.0 + (1-x[:-1])**2.0)
+>>> def rosen(x):
+...     """The Rosenbrock function"""
+...     return sum(100.0*(x[1:]-x[:-1]**2.0)**2.0 + (1-x[:-1])**2.0)
 
 >>> x0 = [1.3, 0.7, 0.8, 1.9, 1.2]
->>> xopt = fmin(rosen, x0)
+>>> xopt = fmin(rosen, x0, xtol=1e-8)
 Optimization terminated successfully.
          Current function value: 0.000000
-         Iterations: 516
-         Function evaluations: 825
+         Iterations: 339
+         Function evaluations: 571
 
 >>> print xopt
 [ 1.  1.  1.  1.  1.]

Modified: trunk/doc/source/tutorial/examples/5-3
===================================================================
--- trunk/doc/source/tutorial/examples/5-3	2008-11-16 11:53:13 UTC (rev 5129)
+++ trunk/doc/source/tutorial/examples/5-3	2008-11-16 12:50:11 UTC (rev 5130)
@@ -1,10 +1,10 @@
 >>> def rosen_der(x):
-        xm = x[1:-1]
-        xm_m1 = x[:-2]
-        xm_p1 = x[2:]
-        der = zeros(x.shape,x.typecode())
-        der[1:-1] = 200*(xm-xm_m1**2) - 400*(xm_p1 - xm**2)*xm - 2*(1-xm)
-        der[0] = -400*x[0]*(x[1]-x[0]**2) - 2*(1-x[0])
-        der[-1] = 200*(x[-1]-x[-2]**2)
-        return der
+...     xm = x[1:-1]
+...     xm_m1 = x[:-2]
+...     xm_p1 = x[2:]
+...     der = zeros_like(x)
+...     der[1:-1] = 200*(xm-xm_m1**2) - 400*(xm_p1 - xm**2)*xm - 2*(1-xm)
+...     der[0] = -400*x[0]*(x[1]-x[0]**2) - 2*(1-x[0])
+...     der[-1] = 200*(x[-1]-x[-2]**2)
+...     return der
 

Modified: trunk/doc/source/tutorial/examples/5-4
===================================================================
--- trunk/doc/source/tutorial/examples/5-4	2008-11-16 11:53:13 UTC (rev 5129)
+++ trunk/doc/source/tutorial/examples/5-4	2008-11-16 12:50:11 UTC (rev 5130)
@@ -4,8 +4,8 @@
 >>> xopt = fmin_bfgs(rosen, x0, fprime=rosen_der)
 Optimization terminated successfully.
          Current function value: 0.000000
-         Iterations: 109
-         Function evaluations: 262
-         Gradient evaluations: 110
+         Iterations: 53
+         Function evaluations: 65
+         Gradient evaluations: 65
 >>> print xopt
-[ 1.  1.  1.  1.  1.]                                                                       
+[ 1.  1.  1.  1.  1.]

Modified: trunk/doc/source/tutorial/examples/5-5
===================================================================
--- trunk/doc/source/tutorial/examples/5-5	2008-11-16 11:53:13 UTC (rev 5129)
+++ trunk/doc/source/tutorial/examples/5-5	2008-11-16 12:50:11 UTC (rev 5130)
@@ -1,21 +1,21 @@
 >>> from scipy.optimize import fmin_ncg
 >>> def rosen_hess(x):
-        x = asarray(x)
-        H = diag(-400*x[:-1],1) - diag(400*x[:-1],-1)
-        diagonal = zeros(len(x),x.typecode())
-        diagonal[0] = 1200*x[0]-400*x[1]+2
-        diagonal[-1] = 200
-        diagonal[1:-1] = 202 + 1200*x[1:-1]**2 - 400*x[2:]
-        H = H + diag(diagonal)
-        return H
+...     x = asarray(x)
+...     H = diag(-400*x[:-1],1) - diag(400*x[:-1],-1)
+...     diagonal = zeros_like(x)
+...     diagonal[0] = 1200*x[0]-400*x[1]+2
+...     diagonal[-1] = 200
+...     diagonal[1:-1] = 202 + 1200*x[1:-1]**2 - 400*x[2:]
+...     H = H + diag(diagonal)
+...     return H
 
 >>> x0 = [1.3, 0.7, 0.8, 1.9, 1.2]
->>> xopt = fmin_ncg(rosen, x0, rosen_der, fhess=rosen_hess)
+>>> xopt = fmin_ncg(rosen, x0, rosen_der, fhess=rosen_hess, avextol=1e-8)
 Optimization terminated successfully.
          Current function value: 0.000000
-         Iterations: 19
-         Function evaluations: 40
-         Gradient evaluations: 19
-         Hessian evaluations: 19
+         Iterations: 23
+         Function evaluations: 26
+         Gradient evaluations: 23
+         Hessian evaluations: 23
 >>> print xopt
-[ 0.9999  0.9999  0.9998  0.9996  0.9991]
+[ 1.  1.  1.  1.  1.]

Modified: trunk/doc/source/tutorial/examples/5-6
===================================================================
--- trunk/doc/source/tutorial/examples/5-6	2008-11-16 11:53:13 UTC (rev 5129)
+++ trunk/doc/source/tutorial/examples/5-6	2008-11-16 12:50:11 UTC (rev 5130)
@@ -1,20 +1,20 @@
 >>> from scipy.optimize import fmin_ncg
 >>> def rosen_hess_p(x,p):
-        x = asarray(x)
-        Hp = zeros(len(x),x.typecode())
-        Hp[0] = (1200*x[0]**2 - 400*x[1] + 2)*p[0] - 400*x[0]*p[1]
-        Hp[1:-1] = -400*x[:-2]*p[:-2]+(202+1200*x[1:-1]**2-400*x[2:])*p[1:-1] \
-                   -400*x[1:-1]*p[2:]
-        Hp[-1] = -400*x[-2]*p[-2] + 200*p[-1]
-        return Hp
+...     x = asarray(x)
+...     Hp = zeros_like(x)
+...     Hp[0] = (1200*x[0]**2 - 400*x[1] + 2)*p[0] - 400*x[0]*p[1]
+...     Hp[1:-1] = -400*x[:-2]*p[:-2]+(202+1200*x[1:-1]**2-400*x[2:])*p[1:-1] \
+...                -400*x[1:-1]*p[2:]
+...     Hp[-1] = -400*x[-2]*p[-2] + 200*p[-1]
+...     return Hp
 
 >>> x0 = [1.3, 0.7, 0.8, 1.9, 1.2]
->>> xopt = fmin_ncg(rosen, x0, rosen_der, fhess_p=rosen_hess_p)
+>>> xopt = fmin_ncg(rosen, x0, rosen_der, fhess_p=rosen_hess_p, avextol=1e-8)
 Optimization terminated successfully.
          Current function value: 0.000000
-         Iterations: 20
-         Function evaluations: 42
-         Gradient evaluations: 20
-         Hessian evaluations: 44
+         Iterations: 22
+         Function evaluations: 25
+         Gradient evaluations: 22
+         Hessian evaluations: 54
 >>> print xopt
-[ 1.      1.      1.      0.9999  0.9999]
+[ 1.  1.  1.  1.  1.]

Modified: trunk/doc/source/tutorial/examples/5-9
===================================================================
--- trunk/doc/source/tutorial/examples/5-9	2008-11-16 11:53:13 UTC (rev 5129)
+++ trunk/doc/source/tutorial/examples/5-9	2008-11-16 12:50:11 UTC (rev 5130)
@@ -6,11 +6,11 @@
         out.append(x[1]*x[0] - x[1] - 5)
         return out
 
->>> from optimize import fsolve
+>>> from scipy.optimize import fsolve
 >>> x0 = fsolve(func, 0.3)
 >>> print x0
 -1.02986652932
 
 >>> x02 = fsolve(func2, [1, 1])
 >>> print x02
-[ 6.5041  0.9084]
+[ 6.50409711  0.90841421]

Modified: trunk/doc/source/tutorial/index.rst
===================================================================
--- trunk/doc/source/tutorial/index.rst	2008-11-16 11:53:13 UTC (rev 5129)
+++ trunk/doc/source/tutorial/index.rst	2008-11-16 12:50:11 UTC (rev 5130)
@@ -40,11 +40,15 @@
 acquired by working through the Tutorial in the Python distribution.
 For further introductory help the user is directed to the Numpy
 documentation. Throughout this tutorial it is assumed that the user
-has imported all of the names defined in the SciPy namespace using the
-command
+has imported all of the names defined in the SciPy top-level namespace
+using the command
 
     >>> from scipy import *
 
+Scipy sub-packages need to be imported separately, for example
+
+    >>> from scipy import linalg, optimize
+
 General Help
 ------------
 
@@ -226,7 +230,15 @@
 for example that one wants to construct an array that begins with 3
 followed by 5 zeros and then contains 10 numbers spanning the range -1
 to 1 (inclusive on both ends). Before SciPy, you would need to enter
-something like the following ``>>> concatenate(([3],[0]*5,arange(-1,1.002,2/9.0))`` . With the :obj:`r_` command one can enter this as ``>>> r_[3,[0]*5,-1:1:10j]`` which can ease typing and make for more readable code. Notice how
+something like the following
+
+    >>> concatenate(([3],[0]*5,arange(-1,1.002,2/9.0)))
+
+With the :obj:`r_` command one can enter this as 
+
+    >>> r_[3,[0]*5,-1:1:10j]
+
+which can ease typing and make for more readable code. Notice how
 objects are concatenated, and the slicing syntax is (ab)used to
 construct ranges. The other term that deserves a little explanation is
 the use of the complex number 10j as the step size in the slicing
@@ -239,29 +251,33 @@
 fashion. When the number of points is specified in this way, the end-
 point is inclusive. 
 
-The "r "stands for row concatenation because if the objects between commas are
-2 dimensional arrays, they are stacked by rows (and thus must have
-commensurate columns). There is an equivalent command :obj:`c_` that stacks 2d arrays by columns but works identically to :obj:`r_` for 1d arrays. 
+The "r" stands for row concatenation because if the objects between
+commas are 2 dimensional arrays, they are stacked by rows (and thus
+must have commensurate columns). There is an equivalent command
+:obj:`c_` that stacks 2d arrays by columns but works identically to
+:obj:`r_` for 1d arrays.
 
 Another very useful class instance which makes use of extended slicing
-notation is the function :obj:`mgrid` . In the simplest case, this function can be used to construct 1d
-ranges as a convenient substitute for arange. It also allows the use
-of complex-numbers in the step-size to indicate the number of points
-to place between the (inclusive) end-points. The real purpose of this
-function however is to produce N, N-d arrays which provide coordinate
-arrays for an N-dimensional volume. The easiest way to understand this
-is with an example of its usage: 
+notation is the function :obj:`mgrid`. In the simplest case, this
+function can be used to construct 1d ranges as a convenient substitute
+for arange. It also allows the use of complex-numbers in the step-size
+to indicate the number of points to place between the (inclusive)
+end-points. The real purpose of this function however is to produce N,
+N-d arrays which provide coordinate arrays for an N-dimensional
+volume. The easiest way to understand this is with an example of its
+usage:
 
 .. literalinclude:: examples/2-1
 
 Having meshed arrays like this is sometimes very useful. However, it
 is not always needed just to evaluate some N-dimensional function over
-a grid due to the array-broadcasting rules of Numpy and SciPy. If
-this is the only purpose for generating a meshgrid, you should instead
-use the function :obj:`ogrid` which generates an "open "grid using NewAxis judiciously to create N, N-d arrays where only one-
-dimension in each array has length greater than 1. This will save
-memory and create the same result if the only purpose for the meshgrid
-is to generate sample points for evaluation of an N-d function. 
+a grid due to the array-broadcasting rules of Numpy and SciPy. If this
+is the only purpose for generating a meshgrid, you should instead use
+the function :obj:`ogrid` which generates an "open "grid using NewAxis
+judiciously to create N, N-d arrays where only one dimension in each
+array has length greater than 1. This will save memory and create the
+same result if the only purpose for the meshgrid is to generate sample
+points for evaluation of an N-d function.
 
 
 Shape manipulation
@@ -270,8 +286,9 @@
 In this category of functions are routines for squeezing out length-
 one dimensions from N-dimensional arrays, ensuring that an array is at
 least 1-, 2-, or 3-dimensional, and stacking (concatenating) arrays by
-rows, columns, and "pages "(in the third dimension). Routines for splitting arrays (roughly the
-opposite of stacking arrays) are also available. 
+rows, columns, and "pages "(in the third dimension). Routines for
+splitting arrays (roughly the opposite of stacking arrays) are also
+available.
 
 
 Matrix manipulations
@@ -311,7 +328,11 @@
 ufuncs). For example, suppose you have a Python function named
 :obj:`addsubtract` defined as:
 
-.. literalinclude:: examples/3-1
+    >>> def addsubtract(a,b):
+    ...    if a > b:
+    ...        return a - b
+    ...    else:
+    ...        return a + b
 
 which defines a function of two scalar variables and returns a scalar
 result. The class vectorize can be used to "vectorize "this function so that ::
@@ -321,7 +342,8 @@
 returns a function which takes array arguments and returns an array
 result: 
 
-.. literalinclude:: examples/3-2
+    >>> vec_addsubtract([0,3,6,9],[1,3,5,7])
+    array([1, 6, 1, 2])
 
 This particular function could have been written in vector form
 without the use of :obj:`vectorize` . But, what if the function you have written is the result of some
@@ -337,8 +359,9 @@
 Numpy package. The reason for duplicating these functions is to
 allow SciPy to potentially alter their original interface and make it
 easier for users to know how to get access to functions
-``>>> from scipy import \*.`` 
 
+    >>> from scipy import *
+
 New functions which should be mentioned are :obj:`mod(x,y)` which can
 replace ``x % y`` when it is desired that the result take the sign of
 *y* instead of *x* . Also included is :obj:`fix` which always rounds
@@ -400,7 +423,7 @@
 broadcasting rules as other math functions in Numerical Python. Many
 of these functions also accept complex-numbers as input. For a
 complete list of the available functions with a one-line description
-type ``>>>info(special).`` Each function also has it's own
+type ``>>> info(special).`` Each function also has it's own
 documentation accessible using help.  If you don't see a function you
 need, consider writing it and contributing it to the library. You can
 write the function in either C, Fortran, or Python. Look in the source
@@ -785,7 +808,8 @@
 
     \[ \mathbf{H}\left(\mathbf{x}\right)\mathbf{p}=\left[\begin{array}{c} \left(1200x_{0}^{2}-400x_{1}+2\right)p_{0}-400x_{0}p_{1}\\ \vdots\\ -400x_{i-1}p_{i-1}+\left(202+1200x_{i}^{2}-400x_{i+1}\right)p_{i}-400x_{i}p_{i+1}\\ \vdots\\ -400x_{N-2}p_{N-2}+200p_{N-1}\end{array}\right].\]
 
-Code which makes use of the *fhess_p* keyword to minimize the Rosenbrock function using :obj:`fmin_ncg` follows: 
+Code which makes use of the *fhess_p* keyword to minimize the
+Rosenbrock function using :obj:`fmin_ncg` follows:
 
 .. literalinclude:: examples/5-6
 
@@ -1595,11 +1619,11 @@
 ^^^^^^^^^^^^^^^^^^^^^
 
 Solving linear systems of equations is straightforward using the scipy
-command :obj:`linalg.solve`. This command expects an input matrix and a right-hand-side vector. The
-solution vector is then computed. An option for entering a symmetrix
-matrix is offered which can speed up the processing when applicable.
-As an example, suppose it is desired to solve the following
-simultaneous equations: 
+command :obj:`linalg.solve`. This command expects an input matrix and
+a right-hand-side vector. The solution vector is then computed. An
+option for entering a symmetrix matrix is offered which can speed up
+the processing when applicable.  As an example, suppose it is desired
+to solve the following simultaneous equations:
 
 .. math::
    :nowrap:
@@ -1614,8 +1638,8 @@
     \[ \left[\begin{array}{c} x\\ y\\ z\end{array}\right]=\left[\begin{array}{ccc} 1 & 3 & 5\\ 2 & 5 & 1\\ 2 & 3 & 8\end{array}\right]^{-1}\left[\begin{array}{c} 10\\ 8\\ 3\end{array}\right]=\frac{1}{25}\left[\begin{array}{c} -232\\ 129\\ 19\end{array}\right]=\left[\begin{array}{c} -9.28\\ 5.16\\ 0.76\end{array}\right].\]
 
 However, it is better to use the linalg.solve command which can be
-faster and more numerically stable. In this case it gives the same
-answer as shown in the following example: 
+faster and more numerically stable. In this case it however gives the
+same answer as shown in the following example:
 
 .. literalinclude:: examples/10-2-2
 



More information about the Scipy-svn mailing list