Skip to main content

raygeo.geo.algo.rootfind

Bisection, solve_secant, and Illinois on a cubic polynomial.

Bisection, solve_secant, and Illinois on a cubic polynomial. 1D root-finding methods: bisection, solve_secant, Illinois.

Functions

bisect()

bisect(
f: Callable[[float], float],
lo: float,
hi: float,
tol: float = 1e-10,
max_iter: int = 100,
) -> tuple[float, str, int]

Bisection root-finding.

ParameterTypeDescription
fCallable[[float], float]Function to find the root of (takes float, returns float).
lofloatLower bound of the search interval.
hifloatUpper bound of the search interval.
tolfloat = 1e-10Convergence tolerance (default 1e-10).
max_iterint = 100Maximum iterations (default 100).
Returnstuple[float, str, int](root, status_string, iteration_count).

Error vs iteration count: solve_secant fastest, bisection slowest

Error vs iteration count: solve_secant fastest, bisection slowest

Iterations to reach a given tolerance: solve_secant needs far fewer than bisection.

Iterations to reach a given tolerance: solve_secant needs far fewer than bisection.

bisect_tracked()

bisect_tracked(
f: Any,
lo: float,
hi: float,
tol: float = 1e-10,
max_iter: int = 100,
) -> tuple[float, str, int, list[float]]

Tracked bisection root-finding.

ParameterTypeDescription
fAnyFunction to find the root of.
lofloatLower bound of the search interval.
hifloatUpper bound of the search interval.
tolfloat = 1e-10Convergence tolerance.
max_iterint = 100Maximum number of iterations.
Returnstuple[float, str, int, list[float]](root, status_string, iteration_count, history).

bracket_grid()

bracket_grid(
f: Callable[[float], float],
heading: float,
max_deflection: float,
) -> tuple[float, str, int]

7-sample angular grid search with linear interpolation.

Samples f at heading + max_deflection * ratio for 7 ratios evenly spaced across [-1, -0.6, -0.2, 0, 0.2, 0.6, 1.0]. When a sign change is found between adjacent samples the root is linearly interpolated. Falls back to the sample with smallest absolute error.

ParameterTypeDescription
fCallable[[float], float]Error function f(angle) -> error.
headingfloatCentre angle in radians.
max_deflectionfloatMaximum angular spread in radians.
Returnstuple[float, str, int](root, status_string, sample_count).

7-sample grid search (linear interp): samples f(x) around heading and interpolates sign changes

7-sample grid search (linear interp): samples f(x) around heading and interpolates sign changes

solve_illinois()

solve_illinois(
f: Callable[[float], float],
lo: float,
hi: float,
tol: float = 1e-10,
max_iter: int = 100,
) -> tuple[float, str, int]

Illinois (safeguarded false-position) root-finding.

ParameterTypeDescription
fCallable[[float], float]Function to find the root of (takes float, returns float).
lofloatLower bound of the search interval.
hifloatUpper bound of the search interval.
tolfloat = 1e-10Convergence tolerance (default 1e-10).
max_iterint = 100Maximum iterations (default 100).
Returnstuple[float, str, int](root, status_string, iteration_count).

solve_illinois_tracked()

solve_illinois_tracked(
f: Any,
lo: float,
hi: float,
tol: float = 1e-10,
max_iter: int = 100,
) -> tuple[float, str, int, list[float]]

Tracked Illinois method root-finding.

ParameterTypeDescription
fAnyFunction to find the root of.
lofloatLower bound of the search interval.
hifloatUpper bound of the search interval.
tolfloat = 1e-10Convergence tolerance.
max_iterint = 100Maximum number of iterations.
Returnstuple[float, str, int, list[float]](root, status_string, iteration_count, history).

solve_secant()

solve_secant(
f: Callable[[float], float],
x0: float,
x1: float,
tol: float = 1e-10,
max_iter: int = 100,
) -> tuple[float, str, int]

Secant root-finding.

ParameterTypeDescription
fCallable[[float], float]Function to find the root of (takes float, returns float).
x0floatFirst initial guess.
x1floatSecond initial guess.
tolfloat = 1e-10Convergence tolerance (default 1e-10).
max_iterint = 100Maximum iterations (default 100).
Returnstuple[float, str, int](root, status_string, iteration_count).

solve_secant_tracked()

solve_secant_tracked(
f: Any,
x0: float,
x1: float,
tol: float = 1e-10,
max_iter: int = 100,
) -> tuple[float, str, int, list[float]]

Tracked solve_secant method root-finding.

ParameterTypeDescription
fAnyFunction to find the root of.
x0floatFirst initial guess.
x1floatSecond initial guess.
tolfloat = 1e-10Convergence tolerance.
max_iterint = 100Maximum number of iterations.
Returnstuple[float, str, int, list[float]](root, status_string, iteration_count, history).