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 f in the range [xa, xb] at interval equal 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 f

  • intervals (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 of f, 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 exceeds max_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 f

  • intervals (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

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, given xa and xb bracketing the root by the bisection method, to an absolute tolerance abs_tol, attempting a maximum of maxiter iterations.

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 f

  • abs_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 f at xa and xb have the same sign

  • RuntimeError – If the root cannot be determined after maxiter iterations.

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, given xa and xb bracketing the root by Brent’s method, to an absolute tolerance abs_tol, attempting a maximum of maxiter iterations. 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 f

  • abs_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 f at xa and xb have the same sign

  • RuntimeError – If the root cannot be determined after maxiter iterations.