Fast and robust root-finding using the Modified Anderson-Bjork method
Project description
A fast and robust root-finding library using the Modified Anderson-Bjork method (Ganchovski, Traykov), written in C for Python.
Installation
pip install pymodab
Usage
import math
from pymodab import find_root, find_default, get_evaluation_count
# Find the root of cos(x) - x = 0 in [0, 1]
root = find_root(lambda x: math.cos(x) - x, 0, 1, 100)
print(f"Root: {root}") # 0.7390851332151607
# Using default tolerances
root = find_default(lambda x: x**2 - 2, 1, 2)
print(f"sqrt(2) = {root}") # 1.4142135623730951
# Get the number of function evaluations
print(f"Evaluations: {get_evaluation_count()}")
API
find_root(f, x1, x2, atol=1e-14, rtol=1e-14, max_iter=200)
Find the root of f(x) = 0 within the interval [x1, x2].
Parameters:
f: A continuous function of one variablex1,x2: Bracket interval endpoints (must satisfyf(x1) * f(x2) < 0)atol: Absolute tolerance (default: 1e-14)rtol: Relative tolerance (default: 1e-14)max_iter: Maximum iterations (default: 200)
Returns: The root, or NaN if not found.
find_default(f, x1, x2)
Convenience wrapper for find_root with default tolerances.
get_evaluation_count()
Returns the number of function evaluations from the last root-finding call.
Algorithm
Modified Anderson-Björck's method is a new robust and efficient bracketing root-finding algorithm. It combines bisection with Anderson-Björk's method to achieve both fast performance and worst-case optimality.
References:
Ganchovski N.; Traykov A. Modified Anderson-Björck's method for solving non-linear equations in structural mechanics. IOP Conference Series: Materials Science and Engineering 2023, 1276 (1) 012010, IOP Publishing. https://iopscience.iop.org/article/10.1088/1757-899X/1276/1/012010/pdf
Ganchovski, N.; Smith, O.; Rackauckas, C.; Tomov, L.; Traykov, A. Improvements of the Modified Anderson-Björck (modAB) Root-Finding Algorithm. Preprints 2026, 2026032190. https://www.preprints.org/manuscript/202603.2190
License
MIT License
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pymodab-1.0.0.tar.gz.
File metadata
- Download URL: pymodab-1.0.0.tar.gz
- Upload date:
- Size: 97.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c07204011acb225b1213eb8d2eb0714971830ab8b2550036fc7232bda4b7605b
|
|
| MD5 |
6efbd6aeaf597eac2b9bfa8672c2c479
|
|
| BLAKE2b-256 |
d93088f0fdad280351cd2992b7fd1ea447a4ca7c5319946ee788ed0d726edd20
|
File details
Details for the file pymodab-1.0.0-py3-none-any.whl.
File metadata
- Download URL: pymodab-1.0.0-py3-none-any.whl
- Upload date:
- Size: 98.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a2eafd55f6d68a0b7020fa8af182d87906e9acfef429c20a4ca55d4f0500157c
|
|
| MD5 |
29cf66112fdb948a40642ebc13ea38e2
|
|
| BLAKE2b-256 |
1ea9c94f6f743bb849d9fded37287dfeb33e9c9616c33cc5d2eb783ae374b990
|