pyroots
raw JSON → 0.5.0 verified Fri May 01 auth: no python
Pure Python single-variable function solvers. Provides root-finding algorithms such as bisection, Newton-Raphson, secant, and others. Current version: 0.5.0. Release cadence is low (last release 2021).
pip install pyroots Common errors
error ModuleNotFoundError: No module named 'pyroots.methods' ↓
cause The submodule 'methods' was removed in version 0.5.0.
fix
Use 'from pyroots import bisection' instead.
error TypeError: only length-1 arrays can be converted to Python scalars ↓
cause Passing a numpy array or list as the function argument where a scalar is expected.
fix
Ensure your function f(x) returns a single float, not an array.
error ValueError: f(a) and f(b) must have opposite signs ↓
cause Bisection and bracket-based methods require the function to change sign over the interval.
fix
Choose an interval [a, b] such that f(a)*f(b) < 0.
Warnings
deprecated The 'methods' submodule (e.g., from pyroots.methods import bisection) is deprecated; use top-level imports (from pyroots import bisection). ↓
fix Use 'from pyroots import bisection' instead.
gotcha All solvers require a function that returns a scalar; they do not support vectorized functions or arrays. Passing a vector will fail. ↓
fix Ensure your function f(x) returns a single float, not a list or numpy array.
gotcha Flexible tolerance 'xtol' behavior: bisection uses 'xtol' as absolute tolerance; newton uses 'xtol' for step size. Inconsistent across methods – check source if expecting identical semantics. ↓
fix Read docstring of each solver to confirm tolerance behavior.
deprecated Support for Python 2.7 and 3.5 is deprecated; future releases may drop it. ↓
fix Use Python >=3.6.
Imports
- bisection
from pyroots import bisection - newton
from pyroots import newton - secant
from pyroots import secant - ridders
from pyroots import ridders - brent
from pyroots import brent
Quickstart
from pyroots import bisection
def f(x):
return x**3 - 2*x - 5
root = bisection(f, 2, 3)
print(f"Root: {root:.6f}")