TheAlgorithms/Python · error · ArithmeticError
No converging solution found, iteration limit reached
Error message
No converging solution found, iteration limit reached
What it means
Error "No converging solution found, iteration limit reached" thrown in TheAlgorithms/Python.
Source
Thrown at maths/numerical_analysis/newton_raphson.py:98
"""
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
- Increase the maximum iteration limit.
- Relax the tolerance or choose a better initial guess closer to the root.
When it happens
Trigger: Thrown at maths/numerical_analysis/newton_raphson.py:98 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/77ac06144c893cf6.
Report an issue: GitHub.