TheAlgorithms/Python · error · ZeroDivisionError

No converging solution found, zero derivative

Error message

No converging solution found, zero derivative

What it means

Error "No converging solution found, zero derivative" thrown in TheAlgorithms/Python.

Source

Thrown at maths/numerical_analysis/newton_raphson.py:96

    ...
    ArithmeticError: No converging solution found, iteration limit reached
    """

    def f_derivative(x: float) -> float:
        return calc_derivative(f, x, step)

    a = x0  # Set initial guess
    steps = []
    for _ in range(max_iter):
        if log_steps:  # Log intermediate steps
            steps.append(a)

        error = abs(f(a))
        if error < max_error:
            return a, error, steps

        if f_derivative(a) == 0:
            raise ZeroDivisionError("No converging solution found, zero derivative")
        a -= f(a) / f_derivative(a)  # Calculate next estimate
    raise ArithmeticError("No converging solution found, iteration limit reached")


if __name__ == "__main__":
    import doctest
    from math import exp, tanh

    doctest.testmod()

    def func(x: float) -> float:
        return tanh(x) ** 2 - exp(3 * x)

    solution, err, steps = newton_raphson(
        func, x0=10, max_iter=100, step=1e-6, log_steps=True
    )
    print(f"{solution=}, {err=}")
    print("\n".join(str(x) for x in steps))

View on GitHub (pinned to f5988cc097)

Solutions

  1. Pick a starting point where the derivative is non-zero.
  2. Use a bracketing method (bisection) when the derivative vanishes near the root.

When it happens

Trigger: Thrown at maths/numerical_analysis/newton_raphson.py:96 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of TheAlgorithms/Python@f5988cc097 (2026-08-14). Data as JSON: /api/errors/a0f2e73990d4dbc7. Report an issue: GitHub.