Перейти до основного вмісту

raygeo.geo.algo.rootfind

Bisection, secant, and Illinois on $x^3 - 2x - 5$.

Bisection, secant, and Illinois on $x^3 - 2x - 5$. 1D root-finding methods: bisection, 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: secant fastest, bisection slowest.

Error vs iteration count: secant fastest, bisection slowest.

Iterations to reach a given tolerance for sqrt(2): secant needs far fewer than bisection.

Iterations to reach a given tolerance for sqrt(2): 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 angular grid search with linear interpolation: samples f(x) on a fan around heading and interpolates across adjacent sign changes.

7-sample angular grid search with linear interpolation: samples f(x) on a fan around heading and interpolates across adjacent sign changes.

illinois()

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).

illinois_tracked()

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).

secant()

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).

secant_tracked()

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

Tracked 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).