@@ -81,7 +81,7 @@ def _results_select(full_output, r):
81
81
82
82
83
83
def newton (func , x0 , fprime = None , args = (), tol = 1.48e-8 , maxiter = 50 ,
84
- fprime2 = None , full_output = False , disp = True , converged = False ):
84
+ fprime2 = None , full_output = False , disp = True ):
85
85
"""
86
86
Find a zero using the Newton-Raphson or secant method.
87
87
@@ -93,14 +93,7 @@ def newton(func, x0, fprime=None, args=(), tol=1.48e-8, maxiter=50,
93
93
94
94
If `x0` is a sequence, then `newton` returns an array, and `func` must be
95
95
vectorized and return a sequence or array of the same shape as its first
96
- argument. If an optional argument, `converged`, is `True`, then the
97
- return is a named tuple `(root, converged, zero_der)` in which `root` is an
98
- array of the locations where `func` is zero, `converged` is an array, same
99
- size as `root`, of booleans that are `True` where `func` converged, and
100
- `zero_der` is another boolean array of the same size where `func` had a
101
- zero derivative.
102
-
103
- If `x0` is a sequence, then arguments `full_output` and `disp` are ignored.
96
+ argument.
104
97
105
98
Parameters
106
99
----------
@@ -128,28 +121,31 @@ def newton(func, x0, fprime=None, args=(), tol=1.48e-8, maxiter=50,
128
121
is used.
129
122
full_output : bool, optional
130
123
If `full_output` is False (default), the root is returned.
131
- If True, the return value is ``(x, r)``, where ``x`` is the root, and
132
- ``r`` is a `RootResults` object.
124
+ If True and `x0` is scalar, the return value is ``(x, r)``, where ``x``
125
+ is the root and ``r`` is a `RootResults` object.
126
+ If True and `x0` is non-scalar, the return value is ``(x, converged,
127
+ zero_der)`` (see Returns section for details).
133
128
disp : bool, optional
134
129
If True, raise a RuntimeError if the algorithm didn't converge, with
135
130
the error message containing the number of iterations and current
136
- function value. *Note: this has little to do with displaying, however
131
+ function value. Ignored if `x0` is not scalar.
132
+ *Note: this has little to do with displaying, however
137
133
the `disp` keyword cannot be renamed for backwards compatibility.*
138
- converged : bool, optional
139
- Only used if `x0` is a sequence. If True, two extras boolean arrays of
140
- converged and zero derivatives are appended to the return.
134
+
141
135
142
136
Returns
143
137
-------
144
138
root : float, sequence, or ndarray
145
139
Estimated location where function is zero.
146
- r : RootResults
147
- Present if ``full_output=True``. Object containing information about
148
- the convergence. In particular, ``r.converged`` is True if the routine
149
- converged.
140
+ r : RootResults, optional
141
+ Present if ``full_output=True`` and `x0` is scalar.
142
+ Object containing information about the convergence. In particular,
143
+ ``r.converged`` is True if the routine converged.
150
144
converged : ndarray of bool, optional
145
+ Present if ``full_output=True`` and `x0` is non-scalar.
151
146
For vector functions, indicates which elements converged successfully.
152
147
zero_der : ndarray of bool, optional
148
+ Present if ``full_output=True`` and `x0` is non-scalar.
153
149
For vector functions, indicates which elements had a zero derivative.
154
150
155
151
See Also
@@ -184,7 +180,6 @@ class of similar problems can be solved together.
184
180
185
181
Examples
186
182
--------
187
-
188
183
>>> from scipy import optimize
189
184
>>> import matplotlib.pyplot as plt
190
185
@@ -248,7 +243,7 @@ class of similar problems can be solved together.
248
243
raise ValueError ("maxiter must be greater than 0" )
249
244
if not np .isscalar (x0 ):
250
245
return _array_newton (func , x0 , fprime , args , tol , maxiter , fprime2 ,
251
- converged )
246
+ full_output )
252
247
253
248
# Convert to float (don't use float(x0); this works also for complex x0)
254
249
p0 = 1.0 * x0
@@ -314,8 +309,7 @@ class of similar problems can be solved together.
314
309
return _results_select (full_output , (p , funcalls , itr + 1 , _ECONVERR ))
315
310
316
311
317
- def _array_newton (func , x0 , fprime , args , tol , maxiter , fprime2 ,
318
- converged = False ):
312
+ def _array_newton (func , x0 , fprime , args , tol , maxiter , fprime2 , full_output ):
319
313
"""
320
314
A vectorized version of Newton, Halley, and secant methods for arrays.
321
315
@@ -409,7 +403,7 @@ def _array_newton(func, x0, fprime, args, tol, maxiter, fprime2,
409
403
raise RuntimeError (msg )
410
404
warnings .warn (msg , RuntimeWarning )
411
405
412
- if converged :
406
+ if full_output :
413
407
result = namedtuple ('result' , ('root' , 'converged' , 'zero_der' ))
414
408
p = result (p , ~ failures , zero_der )
415
409
0 commit comments