hybrid.hybrid
hybrid.hybrid(
f,
dfdx,
xmin,
xmax,
tol1,
tol2,
max_iter1=500,
max_iter2=500,
n=50,
)Find multiple roots of a scalar function using a hybrid Bisection-Newton method.
This algorithm combines a robust bisection-based root searching stage with Newton-Raphson refinement to efficiently locate all detectable roots within a given interval.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| f | callable | Function whose roots are sought. Must accept a single scalar argument. | required |
| dfdx | callable | Derivative of f. Must accept a single scalar argument. |
required |
| xmin | float | Lower bound of the search interval. | required |
| xmax | float | Upper bound of the search interval. | required |
| tol1 | float | Absolute or relative convergence tolerance used by the bisection-based root search. This tolerance controls the accuracy of the initial guesses passed to Newton’s method and must be strictly positive. | required |
| tol2 | float | Relative convergence tolerance used by the Newton-Raphson method. Must be strictly positive. | required |
| max_iter1 | int | Maximum number of iteration for bisection method, Default = 500 | 500 |
| max_iter2 | int | Maximum number of iteration for Newton’s method, Default = 500 | 500 |
| n | int | number of initial guess if bisection fails for some reason (ex: when f(x) = x^2) |
50 |
Returns
| Name | Type | Description |
|---|---|---|
| roots | Sequence[float] | A sequence of estimated roots of the function f within the interval [xmin, xmax]. Only roots for which Newton’s method converges successfully are returned. The output may be empty if no convergent roots are found. |
Notes
The hybrid algorithm proceeds in two stages:
Bisection-based root search
The interval[xmin, xmax]is subdivided and examined for sign changes off. Each detected sign change (or exact zero) produces an initial root estimate using the bisection method viabisection_find_roots.This stage is robust but may:
- Miss roots of even multiplicity
- Miss roots if the subdivision is too coarse
- Return duplicate or closely spaced root estimates
Newton-Raphson refinement
Each bisection-derived estimate is passed as an initial guess tonewton1d, which rapidly refines the root when the derivative is well-behaved.Newton’s method may fail to converge if:
- The derivative is zero or nearly zero
- The initial guess is too far from a true root
- The iterates diverge or become non-finite
Duplicate roots produced by either stage may be filtered using the Newton convergence tolerance tol2.
Convergence for Newton’s method is declared when:
|x_{n+1} - x_n| <= tol2 * max(1, |x_{n+1}|).
This hybrid approach improves robustness compared to Newton’s method alone while achieving faster convergence than pure bisection.
See Also
bisection_find_roots : Bisection-based root search for detecting multiple candidate roots. newton1d : Newton-Raphson method for fast local root refinement.
Examples
>>> f = lambda x: x**2 - 4
>>> df = lambda x: 2*x
>>> roots = hybrid(f, df, -3, 3, tol1=1e-6, tol2=1e-12)
>>> sorted(roots)
[-2.0, 2.0]>>> f = lambda x: x**3 - x
>>> df = lambda x: 3*x**2 - 1
>>> roots = hybrid(f, df, -2, 2, tol1=1e-6, tol2=1e-12)
>>> sorted(roots)
[-1.0, 0.0, 1.0]