Brent’s Method
- rcdesign.brent.bracket(f: Callable, xa: float, xb: float, *args, intervals: int = 10, **kwargs) tuple[float | None, float | None]
Bracket the root of the function
fin the range[xa, xb]atintervalequal intervals.- Parameters:
f (Callable) – Function whose root is to be determined
xa (float) – Start value of range to test for root
xb (float) – End value of range to test for root
*args (tuple) – Positional arguments to be passed to Callable
fintervals (int) – Number of equal intervals at which to test for root (default = 10)
**kwargs (dict) – Keyword arguments to be passed to Callable
f
- Returns:
(x1, x2)bracketing a root off, if found. Else returns(None, None).- Return type:
tuple (float, float)
- rcdesign.brent.search(f: Callable, xa: float, xb: float, *args, intervals: int = 10, max_intervals: int = 100, **kwargs) tuple[float | None, float | None]
Recursively search for values bracketing the roots of
f, doubling the number of equal intervals until the number of intervals exceedsmax_intervals.- Parameters:
f (Callable) – Function whose root is to be determined
xa (float) – Initial start value of range to test for root
xb (float) – Initial end value of range to test for root
*args (tuple) – Positional arguments to be passed to Callable
fintervals (int) – Initial number of equal intervals at which to test for root (default = 10)
max_intervals (int) – Maximum number of equal intervals until which to attempt to bracket the root
**kwargs (dict) – Keyword arguments to be passed to Callable
f
- Returns:
- (float, float) bracketing a root of
f, if found, else (None, None). float | None: Start bracket of root, else None
float | None: End value of bracket, else None
- (float, float) bracketing a root of
- Return type:
tuple
- rcdesign.brent.bisection(f: Callable, xa: float, xb: float, *args, abs_tol: float = 1e-06, maxiter: int = 30, **kwargs) float
Determine the roots of the function
f, givenxaandxbbracketing the root by the bisection method, to an absolute toleranceabs_tol, attempting a maximum ofmaxiteriterations.- Parameters:
f (Callable) – Function whose root is to be determined
xa (float) – Start value of value to test for root
xb (float) – End value of value to test for root
*args (tuple) – Positional arguments to be passed to Callable
fabs_tol (float) – Absolute value for tolerance for difference from zero (default = 1e-6)
maxiter (int) – Maximum number of iterations to attempt to determine a root
**kwargs (dict) – Keyword arguments to be passed to Callable
f
- Returns:
Root of the function
f, if it can be determined. Else raises an exception.- Return type:
float
- Raises:
ValueError – If the values of the function
fatxaandxbhave the same signRuntimeError – If the root cannot be determined after
maxiteriterations.
- rcdesign.brent.brent(f: Callable, xa: float, xb: float, *args, abs_tol: float = 1e-06, maxiter: int = 30, **kwargs) float
Determine the roots of the function
f, givenxaandxbbracketing the root by Brent’s method, to an absolute toleranceabs_tol, attempting a maximum ofmaxiteriterations. Ref: Jaan Kiusalaas, Numerical Methods in Engineering with Python, Cambridge University Press, 2005. pp. 150.- Parameters:
f (Callable) – Function whose root is to be determined
xa (float) – Start value of value to test for root
xb (float) – End value of value to test for root
*args (tuple) – Positional arguments to be passed to Callable
fabs_tol (float) – Absolute value for tolerance for difference from zero (default = 1e-6)
maxiter (int) – Maximum number of iterations to attempt to determine a root
**kwargs (dict) – Keyword arguments to be passed to Callable
f
- Returns:
Root of the function
f, if it can be determined. Else raises an exception.- Return type:
float
- Raises:
ValueError – If the values of the function
fatxaandxbhave the same signRuntimeError – If the root cannot be determined after
maxiteriterations.