Cython implementations of multiple root-finding methods.
Project description
cy-root
(Not this root)
A simple root-finding package written in Cython. Many of the implemented methods can't be found in common Python libraries. Not a serious one so please only use these codes as learning materials.
Context:
I had to find root of this beast of a function, which has no known bound.
$$ f(x) = \frac{1}{\sum\limits_{j=1}^{\infty} \left(\prod\limits_{k=j}^{\infty} \frac{1}{k \cdot x + 1} \right) } - p $$
Fortunately, Sidi's method came to the rescue.
Requirements
- Python 3.6+
- Cython (if you want to build from
.pyx
files) - numpy
- sympy
- A C/C++ compiler
Installation
Make sure you have all the dependencies installed, then clone this repo and run:
git clone git://github.com/inspiros/cy-root.git
cd cy-root
pip install .
For uninstalling:
pip uninstall cy-root
Supported algorithms
Note: For more information about the listed algorithms, please use Google until I update the references.
Scalar root:
- Bracketing methods: (methods that require lower and upper bounds)
- Bisect
- Regula Falsi (False Position)
- Illinois
- Pegasus
- Anderson–Björck
- Dekker
- Brent
- Chandrupatla
- Ridders
- TOMS748
- Wu
- ITP
- Newton-like methods: (methods that require derivative and higher order derivatives)
- Newton-Raphson
- Halley
- Householder
- Quasi-Newton methods: (methods that approximate derivative or use interpolation)
- Secant
- Sidi
- Steffensen
- Inverse Quadratic Interpolation
- Hyperbolic Interpolation
- Muller (for complex root)
Vector root:
Not yet.
Usage
Some examples:
Use find_root_scalar
and pass method name as first argument.
from cyroot import find_root_scalar
f = lambda x: x ** 2 - 612
result = find_root_scalar(method='itp', f=f, a=-10, b=50)
print(result)
Output:
RootResults(root=24.73863375370596, f_root=-1.1368683772161603e-13, iters=8, f_calls=11, a=24.73863375370596, b=24.73863375370596, f_a=-1.1368683772161603e-13, f_b=-1.1368683772161603e-13, precision=6.353294779160024e-08, error=1.1368683772161603e-13, converged=True, optimal=True)
Alternatively, import the function directly. You can also see the full input arguments of by using help()
on them.
from cyroot import muller
# This function has no real root
f = lambda x: x ** 4 + 4 * x ** 2 + 5
# But Muller's method can be used to find complex root
result = muller(f, x0=0, x1=10, x2=20)
print(result)
Output:
RootResults(root=(0.34356074972251255+1.4553466902253551j), f_root=(-8.881784197001252e-16-1.7763568394002505e-15j), iters=43, f_calls=43, precision=3.177770418807502e-08, error=1.9860273225978185e-15, converged=True, optimal=True)
The returned result
is a namedtuple whose elements depend on the type of the method:
- Common:
root
: the solved rootf_root
: value evaluated at rootiters
: number of iterationsf_calls
: number of function callsprecision
: width of final bracket (for bracketing methods) or absolute difference of root with the last estimationerror
: absolute value of f_rootconverged
:True
if the stopping criterion is met,False
if the procedure terminated early.optimal
:True
only if the error tolerance is satisfied.
- Exclusive to bracketing methods:
a
: final lower boundb
: final upper boundf_a
: value evaluated at final lower boundf_b
: value evaluated at final upper bound
- Exclusive to Newton-like methods:
df_root
: derivative or tuple of derivatives (of increasing orders) evaluated at root
Note: converged
might sometimes be True
even if the solution is not optimal, which means the routine
stopped because the precision tolerance is satisfied.
For more examples, please refer to the examples
folder.
License
The code is released under the MIT license. See LICENSE.txt
for details.
References
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 Distributions
Hashes for cy_root-0.1.4-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 43c00f127f3a181ee7dcc58695571f552e651aff9c1c8d21390c45054a6a4959 |
|
MD5 | ab7049fe52881f45421d74cb4c3344fa |
|
BLAKE2b-256 | f9202e6f4451fd64105c6e2e13381c7c7e33bcdc66c85cb414346f1345ca6876 |
Hashes for cy_root-0.1.4-cp310-cp310-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9248a0e1b21def189640e92a58438ed2769cabd78c5a4610ea580ba23385232b |
|
MD5 | 6255ee436af0204870c7abd6d0b8666e |
|
BLAKE2b-256 | b6b5dee2767a7cac23d4242b0edf41253b28e66188ee28e7a884b81043f0909a |
Hashes for cy_root-0.1.4-cp310-cp310-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 89e53e0f41397a37bbbd9cdea46da1a0d8ec2394dbfb0d7ba1ec7b3c46591f95 |
|
MD5 | 6e955e940740e4e53f563a1c8e52bcb7 |
|
BLAKE2b-256 | bd76f87bd923621c3f4f75982abe708b28b11f88a75a240e0284daf79915cfd9 |
Hashes for cy_root-0.1.4-cp310-cp310-musllinux_1_1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b2f835ec1c3ed03ccfaf65eea05e4c02431ca12847169549a9a916c2826864f |
|
MD5 | d63e5689ceef75de01b9cd323ca4cb4d |
|
BLAKE2b-256 | 023381aaa9153d5e172165c00b3a6f48f02f695587057cf3619c539705e734db |
Hashes for cy_root-0.1.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5bf629d2fc387616512563c5eff56c1fc7fcc2d838f4b444a557f7e3fac53081 |
|
MD5 | 80cb9b7bd3a6c9a9048d73c16ea09c9d |
|
BLAKE2b-256 | 77d2b3c37ee3c40a39146967c088a233b0a457c61802037c48b86873adf4603f |
Hashes for cy_root-0.1.4-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c87c91507818851d6a88a41c87d16a680bed7991d10673b342a664b3c05576f0 |
|
MD5 | 81b3c194e387f66dc7f74880a56abaea |
|
BLAKE2b-256 | 5c8905d8ad20b442cf3e78d7f380f973d044c2c7ee9dd99d226450f071ed428c |
Hashes for cy_root-0.1.4-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aef43255d0d7d5bcdaee417d7b8b2cb2360a6eec65ec3a0601ae245efef6675c |
|
MD5 | a81bef7906c72d0963944cea9efa6d41 |
|
BLAKE2b-256 | bf027ee7b34c60e4c49cb342bd44f880331890f15ca05d83a365bf8abec08447 |
Hashes for cy_root-0.1.4-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ce73cb90059aa2018ccab78b15ed4aedcdaf7b998e10801d660ebdce45779a7 |
|
MD5 | 6f55514e19f3199cab8edf4bdc4854d2 |
|
BLAKE2b-256 | a5f983bc03e8f533aaba75c38da9afec435c39c13e99b27f9f75e7413b848f68 |
Hashes for cy_root-0.1.4-cp39-cp39-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | abac70bfb4fded13ebd8736d1d1b4560cc6190d7b455640ea9f68a9a623e2e68 |
|
MD5 | f85f7f7e51f170761b21d1d43cbba28f |
|
BLAKE2b-256 | dd483e07f7215f5b195b767ad359f39bda934743fde9c5138205967114923353 |
Hashes for cy_root-0.1.4-cp39-cp39-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c1ba4660ad39d58c590d82f6c31a05dca565252a764a1319303678fd08018de |
|
MD5 | d51eb4fa9c0768dc747803a42e91fcfa |
|
BLAKE2b-256 | a30c10d5c7b1112333eebae73319e689c19b5afe12f56d105fd2d228010c6e6b |
Hashes for cy_root-0.1.4-cp39-cp39-musllinux_1_1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 94fda31a026ce07d372aaf564af2e77c66f72458b002b9e2c58285efb8b49b43 |
|
MD5 | 85c500c1a94354baa3f3ee2152196a57 |
|
BLAKE2b-256 | 0a47b258fdf79e1c86ccf3ddca6ad3410319b0d0b7b38620e23a482aa873f320 |
Hashes for cy_root-0.1.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a21026c3189a1fa5c5faa04675153352a8137e76387fcef8f4e37bca5cba3b44 |
|
MD5 | 9a8508d8d0fe94cab88a041d7079e833 |
|
BLAKE2b-256 | 833e5295636611d0f2911b76f24d5b32bb24b4670774de298c1a1f41c14dbf92 |
Hashes for cy_root-0.1.4-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6931ba988cb5ef6844e4c88f1df24feac9a0e60d1e1f0f9fcfc8285517504375 |
|
MD5 | d914f5632e1ef8de312d813119ab2e32 |
|
BLAKE2b-256 | 2f689a92c1024ea3e7ba5d72e953f102d4c79f3bf5d1ab9f576bd4dd4634471f |
Hashes for cy_root-0.1.4-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 86f43a9c9f63c58189ed58bdc3fa1f67892c9f6a5f772de4de93a1c29972dc90 |
|
MD5 | 5b325579c3fe1d4c3ca90f53d7fdde52 |
|
BLAKE2b-256 | cc69a26e11edc07c9a339badc6a52b7af076fe17c6f1d01077eb35da6ef0943a |
Hashes for cy_root-0.1.4-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a9cc6060e3958c655f8fc7f8308f0fa3b8d93e4d4941e8a53a66ca742fa546c |
|
MD5 | 1520ad251db18e454d0d1082e69eb566 |
|
BLAKE2b-256 | 97eac068e59958163edef8b7fd9529a384756d4ddcaba518327f243ba068f5ac |
Hashes for cy_root-0.1.4-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2da6c7bdbde6c029d6ea8e0efad306a09a57942326f2ad7c5c45212e6c39bb5a |
|
MD5 | 1ff05dfb3f36a4bbb589e10f52926c0c |
|
BLAKE2b-256 | def5e5ebb24b382aafd9decbd09ea5ca868c933491184b46d19017961fe06694 |
Hashes for cy_root-0.1.4-cp38-cp38-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8daf9ae4ac365d016df71173babee30789847495a9e92c8a37152ed51c0765c3 |
|
MD5 | e3b8fc16e56ff650335914c914f58338 |
|
BLAKE2b-256 | 2b375f2407a4bb02951bb927f120f0c4b495b7eaed5b21d0aed6c492478fb87d |
Hashes for cy_root-0.1.4-cp38-cp38-musllinux_1_1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e350bb1d1a7830eb0cb869b8992f9d4ca578aebe19512c28667c7a38dac7c7f2 |
|
MD5 | 93d59e628afba05aa51aa3fe05765d78 |
|
BLAKE2b-256 | 137a1a5e9facbdf03f77aca9460f71808a557b7d53f71c1623be444820fcc2a9 |
Hashes for cy_root-0.1.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 29c537c252af0a9ff02ee775dc3cbd17d3f16580629bc1d35e05b6b803a6f38a |
|
MD5 | 2e966a8b146b533c83f0013931d1a5df |
|
BLAKE2b-256 | af1c3160e139f12d152f8ec803d7527aa39f718006b68e806bf47437f8cca9ba |
Hashes for cy_root-0.1.4-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1eec467880f685261a313e3010c0ed36043f634f242fb090f217074e382c4045 |
|
MD5 | c4f3b5dc89b15b72cf7161b843432035 |
|
BLAKE2b-256 | 9bcb8e971b7f77cd51620023aaf5cda04d4f16d5b3b72b0d3fa1a01a6e7b8e96 |
Hashes for cy_root-0.1.4-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c1cc8f9dcf05f819e9045c0a32e5f25f6ea8161e23ea42bc0f9e3d7fabfef3a2 |
|
MD5 | da807625ddf991745c28f1cec69bde99 |
|
BLAKE2b-256 | 9d1df6cd82fb0c1dcdf8f1dd4e80c03288576229e4638d66b4549dca39280857 |
Hashes for cy_root-0.1.4-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0423cfe70370a49b7ecefd3cf0337645bbcfe0cbac3e8e87d09bc617d121057e |
|
MD5 | 7dfc8d60492536db8474449511a7687e |
|
BLAKE2b-256 | ee07b74191af4dc07814b20fa8af7ddfce38fa20abafbbced4c07cf1c9fed7f0 |
Hashes for cy_root-0.1.4-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 06bc94b60af51b5afb7ada3d0b49fe4c0addaf72e4e8ac4ff88e671e8b3258de |
|
MD5 | 9b28ae4b653ecef2f892f089092b9ab6 |
|
BLAKE2b-256 | 23e26300954bec5e309e47b50b7f37b511e9867a1ece5ac67b76db34eba24ca5 |
Hashes for cy_root-0.1.4-cp37-cp37m-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ed89f2343fd908929d6c158748cd59d09da245586963a1106eceb0a0fe189c9 |
|
MD5 | 88c7225c47a2765a668361a6e59699a9 |
|
BLAKE2b-256 | 596fb9d5e83c16ff309f5036878ed8324c881b0c471c3a54a19de4c93f93f6cd |
Hashes for cy_root-0.1.4-cp37-cp37m-musllinux_1_1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 889be69638c80de7124bd4f642794eec858c321bff6a822c8679899d200bc781 |
|
MD5 | 34fbb5f3e1ca7df5b6f08760bc4e7eb7 |
|
BLAKE2b-256 | 6bbdca7c82055430fd7ee82dcadd6d839b674be2f31e74c28de9f0e20c25a200 |
Hashes for cy_root-0.1.4-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3fd472a28698d7fe1caadf3cc016ca583885e3fa9ba5cac0ec8e5e28ee4e61a5 |
|
MD5 | 2d8cbe7966b5803622dd84f249843654 |
|
BLAKE2b-256 | 1709f36ffe36990b7b945b8a8f911e611f0291c3bb4142128640f2e56e9bab10 |
Hashes for cy_root-0.1.4-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4346631c72332818aa4992454ee67b04b6537b60e4dbe2a5b723a6d493be0f6a |
|
MD5 | 697a78c915e874e3383875028b44a84c |
|
BLAKE2b-256 | e68b7ce9bf188c60953d74a97444d119650bc050c68160bbbb56cdf172cf15e3 |
Hashes for cy_root-0.1.4-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fd03fb77b2c8c29b16ca0145d3bd8ca77a5a37308ce2d788195e50ee4c9e216a |
|
MD5 | 7dbac7de3dd3186b4b1061e70c989708 |
|
BLAKE2b-256 | d6c43b8d39ef53cc23197c1f9000a2c038e92455c87f7220a58fac7de200590d |
Hashes for cy_root-0.1.4-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf34816b5747e22cd00e6821546aa8d8fa5653750956bf445e1f6e3044cc0480 |
|
MD5 | db11e28d1f5caaf2e516801fbaac0ae8 |
|
BLAKE2b-256 | db02a9ee5b38cd8ea82e03a22b382947ef5415d30df4951f1e3b7f1f98148524 |
Hashes for cy_root-0.1.4-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64a4d0f7d965c0af32e4f020c27818141a27d713406b46958fca9f49e4d1ac1d |
|
MD5 | dd83ee8ebd86ed69ade98d974e984f93 |
|
BLAKE2b-256 | 869e50e7491f8fedea99d4c6cbe0f646fe6c46ea764be48a49105b94dc542cae |
Hashes for cy_root-0.1.4-cp36-cp36m-musllinux_1_1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 135d33833b257ffdd5a458bbdcb928205e63826097ed4efc5c63a454ab37881d |
|
MD5 | 4a05b483ca3aed44f68790f9e425ceaf |
|
BLAKE2b-256 | 74838891ccbe85187269d485aaaaab3547c4c9079af647932560fefba8bd98e1 |
Hashes for cy_root-0.1.4-cp36-cp36m-musllinux_1_1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d06c48bb4d25498b2ae5bc1191e2cbc4b3e328d78ca0297b9a70c2cd9ab10079 |
|
MD5 | 026d9af72551331e1e305d66a7640c91 |
|
BLAKE2b-256 | 96224d9a4e5c6e48a33730b1b45cc64111ecdd33a5ca8a4991be605b02cad183 |
Hashes for cy_root-0.1.4-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9d1d5777fe8d14022229bcc5960809453058febc81845075c031c0c00c34e9e7 |
|
MD5 | fe8506ff49e9b765c95d730601aa47ca |
|
BLAKE2b-256 | 75ba407bd6794d2914c596e06c79641197bf1f44c8b700475991de6381ff8b89 |
Hashes for cy_root-0.1.4-cp36-cp36m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 793501ec9b97859218c1fad226a2c68682ad710b01c616b40b9a39514b8c2216 |
|
MD5 | 86e21116284d6bc1c14595fdca46a680 |
|
BLAKE2b-256 | 1098acaf1afed43227d78a63601593be43a0064c6f85e48345bef0d1b4be131a |
Hashes for cy_root-0.1.4-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3085fec20d77df3343d4fe558d73faf2562048078ac015850a45487484700f0d |
|
MD5 | d263e8477599b64389d54cc3722ecf19 |
|
BLAKE2b-256 | a26eeb361211013964b94637c2d261aa5d2402eab40b312fa329a13589e085de |