{
  "__type": "IngestedDoc",
  "__tag": 4010,
  "_content": {
    "Notes": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "The convergence rate of the Newton-Raphson method is quadratic, the Halley method is cubic, and the secant method is sub-quadratic. This means that if the function is well-behaved the actual error in the estimated root after the nth iteration is approximately the square (cube for Halley) of the error after the (n-1)th step. However, the stopping criterion used here is the step size and there is no guarantee that a root has been found. Consequently, the result should be verified. Safer algorithms are brentq, brenth, ridder, and bisect, but they all require that the root first be bracketed in an interval where the function changes sign. The brentq algorithm is recommended for general use in one dimensional problems when such an interval has been found."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "When "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "newton",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "module",
                "path": "scipy.optimize._zeros_py:newton"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is used with arrays, it is best suited for the following types of problems:"
            }
          ]
        },
        {
          "__type": "BulletList",
          "__tag": 4053,
          "ordered": false,
          "start": 1,
          "children": [
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The initial guesses, "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "x0"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", are all relatively the same distance from   the roots."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Some or all of the extra arguments, "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "args"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", are also arrays so that a   class of similar problems can be solved together."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The size of the initial guesses, "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "x0"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", is larger than O(100) elements.   Otherwise, a naive loop may perform as well or better than a vector."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Warns": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Raises": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Yields": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Methods": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Returns": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Parameters",
          "__tag": 4026,
          "children": [
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "root",
              "annotation": "float, sequence, or ndarray",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Estimated location where function is zero."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "r",
              "annotation": "`RootResults`, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Present if "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "full_output=True"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " and "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "x0"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is scalar. Object containing information about the convergence. In particular, "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "r.converged"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is True if the routine converged."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "converged",
              "annotation": "ndarray of bool, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Present if "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "full_output=True"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " and "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "x0"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is non-scalar. For vector functions, indicates which elements converged successfully."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "zero_der",
              "annotation": "ndarray of bool, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Present if "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "full_output=True"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " and "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "x0"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is non-scalar. For vector functions, indicates which elements had a zero derivative."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Find a root of a real or complex function using the Newton-Raphson (or secant or Halley's) method."
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Receives": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Warnings": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Attributes": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    },
    "Parameters": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Parameters",
          "__tag": 4026,
          "children": [
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "func",
              "annotation": "callable",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The function whose root is wanted. It must be a function of a single variable of the form "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "f(x,a,b,c,...)"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", where "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "a,b,c,..."
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " are extra arguments that can be passed in the "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "args"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " parameter."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "x0",
              "annotation": "float, sequence, or ndarray",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "An initial estimate of the root that should be somewhere near the actual root. If not scalar, then "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "func"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " must be vectorized and return a sequence or array of the same shape as its first argument."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "fprime",
              "annotation": "callable, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The derivative of the function when available and convenient. If it is None (default), then the secant method is used."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "args",
              "annotation": "tuple, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Extra arguments to be used in the function call."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "tol",
              "annotation": "float, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The allowable error of the root's value. If "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "func"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is complex-valued, a larger "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "tol"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is recommended as both the real and imaginary parts of "
                    },
                    {
                      "__type": "InlineRole",
                      "__tag": 4003,
                      "value": "x",
                      "domain": null,
                      "role": null,
                      "inventory": null
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " contribute to "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "|x - x0|"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "maxiter",
              "annotation": "int, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Maximum number of iterations."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "fprime2",
              "annotation": "callable, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "The second order derivative of the function when available and convenient. If it is None (default), then the normal Newton-Raphson or the secant method is used. If it is not None, then Halley's method is used."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "x1",
              "annotation": "float, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Another estimate of the root that should be somewhere near the actual root. Used if "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "fprime"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is not provided."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "rtol",
              "annotation": "float, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Tolerance (relative) for termination."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "full_output",
              "annotation": "bool, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "If "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "full_output"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is False (default), the root is returned. If True and "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "x0"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is scalar, the return value is "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "(x, r)"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", where "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "x"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is the root and "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "r"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is a "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "RootResults",
                      "reference": {
                        "__type": "LocalRef",
                        "__tag": 4022,
                        "kind": "module",
                        "path": "scipy.optimize._zeros_py:RootResults"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " object. If True and "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "x0"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is non-scalar, the return value is "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "(x, converged, zero_der)"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " (see Returns section for details)."
                    }
                  ]
                }
              ]
            },
            {
              "__type": "DocParam",
              "__tag": 4016,
              "name": "disp",
              "annotation": "bool, optional",
              "desc": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "If True, raise a RuntimeError if the algorithm didn't converge, with the error message containing the number of iterations and current function value. Otherwise, the convergence status is recorded in a "
                    },
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "RootResults",
                      "reference": {
                        "__type": "LocalRef",
                        "__tag": 4022,
                        "kind": "module",
                        "path": "scipy.optimize._zeros_py:RootResults"
                      },
                      "kind": "module"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " return object. Ignored if "
                    },
                    {
                      "__type": "ParamRef",
                      "__tag": 4071,
                      "name": "x0"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " is not scalar. "
                    },
                    {
                      "__type": "Emphasis",
                      "__tag": 4047,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "Note: this has little to do with displaying, however,\nthe `disp` keyword cannot be renamed for backwards compatibility."
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Extended Summary": {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Find a root of the scalar-valued function "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "func"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " given a nearby scalar starting point "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "x0"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". The Newton-Raphson method is used if the derivative "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "fprime"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " of "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "func"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is provided, otherwise the secant method is used. If the second order derivative "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "fprime2"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " of "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "func"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is also provided, then Halley's method is used."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "If "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "x0"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is a sequence with more than one item, "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "newton",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "module",
                "path": "scipy.optimize._zeros_py:newton"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " returns an array: the roots of the function from each (scalar) starting point in "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "x0"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". In this case, "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "func"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " must be vectorized to return a sequence or array of the same shape as its first argument. If "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "fprime"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " ("
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "fprime2"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ") is given, then its return must also have the same shape: each element is the first (second) derivative of "
            },
            {
              "__type": "ParamRef",
              "__tag": 4071,
              "name": "func"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " with respect to its only variable evaluated at each element of its first argument."
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "newton",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "module",
                "path": "scipy.optimize._zeros_py:newton"
              },
              "kind": "module"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " is for finding roots of a scalar-valued functions of a single variable. For problems involving several variables, see "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "root",
              "reference": {
                "__type": "RefInfo",
                "__tag": 4000,
                "module": null,
                "version": null,
                "kind": "local",
                "path": "root"
              },
              "kind": "local"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        }
      ],
      "title": [],
      "level": 0,
      "target": null
    },
    "Other Parameters": {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [],
      "level": 0,
      "target": null
    }
  },
  "_ordered_sections": [
    "Summary",
    "Extended Summary",
    "Parameters",
    "Attributes",
    "Methods",
    "Returns",
    "Yields",
    "Receives",
    "Other Parameters",
    "Raises",
    "Warns",
    "Warnings",
    "Notes"
  ],
  "item_file": "/scipy/optimize/_zeros_py.py",
  "item_line": 109,
  "item_type": "function",
  "aliases": [
    "scipy.optimize.newton"
  ],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "import numpy as np\nimport matplotlib.pyplot as plt\nfrom scipy import optimize\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "def f(x):\n    return (x**3 - 1)  # only one real root at x = 1\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\n``fprime`` is not provided, use the secant method:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "root = optimize.newton(f, 1.5)\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "root\n",
        "execution_status": "failure"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "root = optimize.newton(f, 1.5, fprime2=lambda x: 6 * x)\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "root\n",
        "execution_status": "failure"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nOnly ``fprime`` is provided, use the Newton-Raphson method:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "root = optimize.newton(f, 1.5, fprime=lambda x: 3 * x**2)\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "root\n",
        "execution_status": "failure"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nBoth ``fprime2`` and ``fprime`` are provided, use Halley's method:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "root = optimize.newton(f, 1.5, fprime=lambda x: 3 * x**2,\n                       fprime2=lambda x: 6 * x)\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "root\n",
        "execution_status": "failure"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nWhen we want to find roots for a set of related starting values and/or\nfunction parameters, we can provide both of those as an array of inputs:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "f = lambda x, a: x**3 - a\nfder = lambda x, a: 3 * x**2\nrng = np.random.default_rng()\nx = rng.standard_normal(100)\na = np.arange(-50, 50)\nvec_res = optimize.newton(f, x, fprime=fder, args=(a, ), maxiter=200)\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nThe above is the equivalent of solving for each value in ``(x, a)``\nseparately in a for-loop, just faster:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "loop_res = [optimize.newton(f, x0, fprime=fder, args=(a0,),\n                            maxiter=200)\n            for x0, a0 in zip(x, a)]\nnp.allclose(vec_res, loop_res)\n",
        "execution_status": "success"
      },
      {
        "__type": "Text",
        "__tag": 4046,
        "value": "\nPlot the results found for all values of ``a``:\n\n"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "analytical_result = np.sign(a) * np.abs(a)**(1/3)\nfig, ax = plt.subplots()\n",
        "execution_status": "success"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "ax.plot(a, analytical_result, 'o')\nax.plot(a, vec_res, '.')\nax.set_xlabel('$a$')\nax.set_ylabel('$x$ where $f(x, a)=0$')\n",
        "execution_status": "failure"
      },
      {
        "__type": "Code",
        "__tag": 4050,
        "value": "plt.show()\n",
        "execution_status": "success"
      },
      {
        "__type": "Figure",
        "__tag": 4024,
        "value": {
          "__type": "RefInfo",
          "__tag": 4000,
          "module": "scipy",
          "version": "1.17.1",
          "kind": "assets",
          "path": "fig-8829e4c36b264aad.png"
        }
      }
    ],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [
    {
      "__type": "SeeAlsoItem",
      "__tag": 4028,
      "name": {
        "__type": "CrossRef",
        "__tag": 4002,
        "value": "root",
        "reference": {
          "__type": "LocalRef",
          "__tag": 4022,
          "kind": "module",
          "path": "scipy.optimize._root:root"
        },
        "kind": "module"
      },
      "descriptions": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "interface to root solvers for multi-input, multi-output functions"
            }
          ]
        }
      ],
      "type": null
    },
    {
      "__type": "SeeAlsoItem",
      "__tag": 4028,
      "name": {
        "__type": "CrossRef",
        "__tag": 4002,
        "value": "root_scalar",
        "reference": {
          "__type": "LocalRef",
          "__tag": 4022,
          "kind": "module",
          "path": "scipy.optimize._root_scalar:root_scalar"
        },
        "kind": "module"
      },
      "descriptions": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "interface to root solvers for scalar functions"
            }
          ]
        }
      ],
      "type": null
    }
  ],
  "signature": {
    "__type": "SignatureNode",
    "__tag": 4029,
    "kind": "function",
    "parameters": [
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "func",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": {
          "__type": "Empty",
          "__tag": 4031
        }
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "x0",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": {
          "__type": "Empty",
          "__tag": 4031
        }
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "fprime",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "None"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "args",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "()"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "tol",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "1.48e-08"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "maxiter",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "50"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "fprime2",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "None"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "x1",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "None"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "rtol",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "0.0"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "full_output",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "False"
      },
      {
        "__type": "SigParam",
        "__tag": 4030,
        "name": "disp",
        "annotation": {
          "__type": "Empty",
          "__tag": 4031
        },
        "kind": "POSITIONAL_OR_KEYWORD",
        "default": "True"
      }
    ],
    "return_annotation": {
      "__type": "Empty",
      "__tag": 4031
    },
    "target_name": "newton"
  },
  "references": null,
  "qa": "scipy.optimize._zeros_py:newton",
  "arbitrary": [],
  "local_refs": [
    "args",
    "converged",
    "disp",
    "fprime",
    "fprime2",
    "full_output",
    "func",
    "maxiter",
    "r",
    "root",
    "rtol",
    "tol",
    "x0",
    "x1",
    "zero_der"
  ]
}