def nonlin_solve(F, x0, jacobian='<STR_LIT>', iter=None, verbose=False,<EOL>maxiter=None, f_tol=None, f_rtol=None, x_tol=None, x_rtol=None,<EOL>tol_norm=None, line_search='<STR_LIT>', callback=None,<EOL>full_output=False, raise_exception=True):
condition = TerminationCondition(f_tol=f_tol, f_rtol=f_rtol,<EOL>x_tol=x_tol, x_rtol=x_rtol,<EOL>iter=iter, norm=tol_norm)<EOL>x0 = _as_inexact(x0)<EOL>func = lambda z: _as_inexact(F(_array_like(z, x0))).flatten()<EOL>x = x0.flatten()<EOL>dx = np.inf<EOL>Fx = func(x)<EOL>Fx_norm = norm(Fx)<EOL>jacobian = asjacobian(jacobian)<EOL>jacobian.setup(x.copy(), Fx, func)<EOL>if maxiter is None:<EOL><INDENT>if iter is not None:<EOL><INDENT>maxiter = iter + <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>maxiter = <NUM_LIT:100>*(x.size+<NUM_LIT:1>)<EOL><DEDENT><DEDENT>if line_search is True:<EOL><INDENT>line_search = '<STR_LIT>'<EOL><DEDENT>elif line_search is False:<EOL><INDENT>line_search = None<EOL><DEDENT>if line_search not in (None, '<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>gamma = <NUM_LIT><EOL>eta_max = <NUM_LIT><EOL>eta_treshold = <NUM_LIT:0.1><EOL>eta = <NUM_LIT><EOL>for n in xrange(maxiter):<EOL><INDENT>status = condition.check(Fx, x, dx)<EOL>if status:<EOL><INDENT>break<EOL><DEDENT>tol = min(eta, eta*Fx_norm)<EOL>dx = -jacobian.solve(Fx, tol=tol)<EOL>if norm(dx) == <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>if line_search:<EOL><INDENT>s, x, Fx, Fx_norm_new = _nonlin_line_search(func, x, Fx, dx,<EOL>line_search)<EOL><DEDENT>else:<EOL><INDENT>s = <NUM_LIT:1.0><EOL>x = x + dx<EOL>Fx = func(x)<EOL>Fx_norm_new = norm(Fx)<EOL><DEDENT>jacobian.update(x.copy(), Fx)<EOL>if callback:<EOL><INDENT>callback(x, Fx)<EOL><DEDENT>eta_A = gamma * Fx_norm_new**<NUM_LIT:2> / Fx_norm**<NUM_LIT:2><EOL>if gamma * eta**<NUM_LIT:2> < eta_treshold:<EOL><INDENT>eta = min(eta_max, eta_A)<EOL><DEDENT>else:<EOL><INDENT>eta = min(eta_max, max(eta_A, gamma*eta**<NUM_LIT:2>))<EOL><DEDENT>Fx_norm = Fx_norm_new<EOL>if verbose:<EOL><INDENT>sys.stdout.write("<STR_LIT>" % (<EOL>n, norm(Fx), s, eta))<EOL>sys.stdout.flush()<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if raise_exception:<EOL><INDENT>raise NoConvergence(_array_like(x, x0))<EOL><DEDENT>else:<EOL><INDENT>status = <NUM_LIT:2><EOL><DEDENT><DEDENT>if full_output:<EOL><INDENT>info = {'<STR_LIT>': condition.iteration,<EOL>'<STR_LIT>': Fx,<EOL>'<STR_LIT:status>': status,<EOL>'<STR_LIT:success>': status == <NUM_LIT:1>,<EOL>'<STR_LIT:message>': {<NUM_LIT:1>: '<STR_LIT>'<EOL>'<STR_LIT>',<EOL><NUM_LIT:2>: '<STR_LIT>'<EOL>'<STR_LIT>'<EOL>}[status]<EOL>}<EOL>return _array_like(x, x0), info<EOL><DEDENT>else:<EOL><INDENT>return _array_like(x, x0)<EOL><DEDENT>
Find a root of a function, in a way suitable for large-scale problems.

Parameters
----------
%(params_basic)s
jacobian : Jacobian
    A Jacobian approximation: `Jacobian` object or something that
    `asjacobian` can transform to one. Alternatively, a string specifying
    which of the builtin Jacobian approximations to use:

        krylov, broyden1, broyden2, anderson
        diagbroyden, linearmixing, excitingmixing

%(params_extra)s
full_output : bool
    If true, returns a dictionary `info` containing convergence
    information.
raise_exception : bool
    If True, a `NoConvergence` exception is raise if no solution is found.

See Also
--------
asjacobian, Jacobian

Notes
-----
This algorithm implements the inexact Newton method, with
backtracking or full line searches. Several Jacobian
approximations are available, including Krylov and Quasi-Newton
methods.

References
----------
.. [KIM] C. T. Kelley, \"Iterative Methods for Linear and Nonlinear
   Equations\". Society for Industrial and Applied Mathematics. (1995)
   http://www.siam.org/books/kelley/