{"record":{"id":"86ad301ad2006679","repo":"TheAlgorithms/Python","slug":"float-division-by-zero-could-not-find-root","errorCode":null,"errorMessage":"float division by zero, could not find root","messagePattern":"float division by zero, could not find root","errorType":"exception","errorClass":"ZeroDivisionError","httpStatus":null,"severity":"error","filePath":"maths/numerical_analysis/intersection.py","lineNumber":34,"sourceCode":"    1.0000000000003888\n    >>> intersection(lambda x: x ** 2 - 4 * x + 3, 0, 2)\n    0.9999999998088019\n    >>> intersection(lambda x: x ** 2 - 4 * x + 3, 2, 4)\n    2.9999999998088023\n    >>> intersection(lambda x: x ** 2 - 4 * x + 3, 4, 1000)\n    3.0000000001786042\n    >>> intersection(math.sin, -math.pi, math.pi)\n    0.0\n    >>> intersection(math.cos, -math.pi, math.pi)\n    Traceback (most recent call last):\n        ...\n    ZeroDivisionError: float division by zero, could not find root\n    \"\"\"\n    x_n: float = x0\n    x_n1: float = x1\n    while True:\n        if x_n == x_n1 or function(x_n1) == function(x_n):\n            raise ZeroDivisionError(\"float division by zero, could not find root\")\n        x_n2: float = x_n1 - (\n            function(x_n1) / ((function(x_n1) - function(x_n)) / (x_n1 - x_n))\n        )\n        if abs(x_n2 - x_n1) < 10**-5:\n            return x_n2\n        x_n = x_n1\n        x_n1 = x_n2\n\n\ndef f(x: float) -> float:\n    \"\"\"\n    function is f(x) = x^3 - 2x - 5\n    >>> f(2)\n    -1.0\n    \"\"\"\n    return math.pow(x, 3) - (2 * x) - 5\n\n","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/maths/numerical_analysis/intersection.py#L16-L52","documentation":"Error \"float division by zero, could not find root\" thrown in TheAlgorithms/Python.","triggerScenarios":"Thrown at maths/numerical_analysis/intersection.py:34 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pick initial points where the secant denominator (difference of function values) is non-zero.","Choose a different starting interval or method if the function is flat near the guesses."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}