numerical_methods.roots package¶
Submodules¶
numerical_methods.roots.dichotomie module¶
- numerical_methods.roots.dichotomie.dichotomy(start, end, tolerance, func, verbose=True)[source]¶
Bisection method to find a root of a continuous function in [start, end].
- Parameters:
start (float) – Lower bound of the interval.
end (float) – Upper bound of the interval.
tolerance (float) – Accepted error margin for the root.
func (callable) – Continuous function f(x) such that f(start) * f(end) < 0.
verbose (bool) – If True, prints each iteration step.
- Returns:
Approximate root and list of iterations (a, b, midpoint).
- Return type:
tuple[float, list[tuple[float, float, float]]]
- Raises:
ValueError – If f(start) * f(end) >= 0.
numerical_methods.roots.newton module¶
- numerical_methods.roots.newton.newton(tolerance, func, func_derivative, initial_guess=1.0, max_iterations=1000, verbose=True)[source]¶
Newton-Raphson method to find a root of a function.
- Parameters:
tolerance (float) – Accepted error margin.
func (callable) – Function f(x).
func_derivative (callable) – Derivative f’(x).
initial_guess (float) – Starting value.
max_iterations (int) – Maximum number of iterations.
verbose (bool) – If True, prints each iteration step.
- Returns:
Approximate root and list of iterations (i, x0, x).
- Return type:
tuple[float, list[tuple[int, float, float]]]
- Raises:
ZeroDivisionError – If f’(x) = 0 during an iteration.
RuntimeError – If the max number of iterations is reached.
numerical_methods.roots.point_fixe module¶
- numerical_methods.roots.point_fixe.fixed_point(tolerance, g_func, initial_guess=1.0, max_iterations=1000, verbose=True)[source]¶
Fixed-point iteration method to find a solution of x = g(x).
- Parameters:
tolerance (float) – Accepted error margin.
g_func (callable) – Function g(x) such that x = g(x).
initial_guess (float) – Starting value.
max_iterations (int) – Maximum number of iterations.
verbose (bool) – If True, prints each iteration step.
- Returns:
Approximate fixed point and list of iterations (i, x0, x).
- Return type:
tuple[float, list[tuple[int, float, float]]]
- Raises:
RuntimeError – If the max number of iterations is reached.