|pkg_img| |doi| |tests| |coverage| |lgtm_grade| |lgtm_alerts|
.. |tests| image:: https://github.com/rparini/cxroots/workflows/tests/badge.svg
:target: https://github.com/rparini/cxroots/actions
.. |doi| image:: https://zenodo.org/badge/79802240.svg
:target: https://zenodo.org/badge/latestdoi/79802240
.. |pkg_img| image:: https://badge.fury.io/py/cxroots.svg
:target: https://badge.fury.io/py/cxroots
.. |lgtm_grade| image:: https://img.shields.io/lgtm/grade/python/g/rparini/cxroots.svg?logo=lgtm&logoWidth=18
:target: https://lgtm.com/projects/g/rparini/cxroots/context:python
.. |lgtm_alerts| image:: https://img.shields.io/lgtm/alerts/g/rparini/cxroots.svg?logo=lgtm&logoWidth=18
:target: https://lgtm.com/projects/g/rparini/cxroots/alerts/
.. |coverage| image:: https://coveralls.io/repos/github/rparini/cxroots/badge.svg
:target: https://coveralls.io/github/rparini/cxroots
cxroots
=======
cxroots is a Python package for finding all the roots of a function, *f(z)*, of a single complex variable within a given contour, *C*, in the complex plane. It requires only that both:
- *f(z)* has no roots or poles on *C*
- *f(z)* is analytic in the interior of *C*
The implementation is primarily based on [KB]_ and evaluates contour integrals involving *f(z)* and its derivative *f'(z)* to determine the roots. If *f'(z)* is not provided then it is approximated using a finite difference method. The roots are further refined using Newton-Raphson if *f'(z)* is given or Muller's method if not. See the `documentation <https://rparini.github.io/cxroots/>`_ for a more details and a tutorial.
With `Python <http://www.python.org/>`_ installed you can install cxroots by entering in the terminal/command line
.. code:: bash
pip install cxroots
Example
-------
.. code:: python
from numpy import exp, cos, sin
f = lambda z: (exp(2*z)*cos(z)-1-sin(z)+z**5)*(z*(z+2))**2
from cxroots import Circle
C = Circle(0,3)
roots = C.roots(f)
roots.show()
.. Relative images do not display on pypi
.. image:: https://github.com/rparini/cxroots/blob/master/README_resources/readme_example.png?raw=true
.. code:: python
print(roots)
.. literalinclude readme_example.txt doesn't work on github
.. code::
Multiplicity | Root
------------------------------------------------
2 | -2.000000000000 +0.000000000000i
1 | -0.651114070264 -0.390425719088i
1 | -0.651114070264 +0.390425719088i
3 | 0.000000000000 +0.000000000000i
1 | 0.648578080954 -1.356622683988i
1 | 0.648578080954 +1.356622683988i
1 | 2.237557782467 +0.000000000000i
See also
--------
The Fortran 90 package `ZEAL <http://cpc.cs.qub.ac.uk/summaries/ADKW>`_ is a direct implementation of [KB]_.
Citing cxroots
--------------
\R. Parini. *cxroots: A Python module to find all the roots of a complex analytic function within a given contour* (2018), https://github.com/rparini/cxroots
BibTex:
.. code::
@misc{cxroots,
author = {Robert Parini},
title = {{cxroots: A Python module to find all the roots of a complex analytic function within a given contour}},
doi = {10.5281/zenodo.7013117},
url = {https://github.com/rparini/cxroots},
year = {2018--}
}
----------
Development
-----------
- Install the `pre-commit <https://pre-commit.com/>`_ and then run :code:`pre-commit install`. The pre-commit scripts can also be run manually with :code:`pre-commit run --all-files`
- The project uses:
- `Black <https://github.com/psf/black/>`_ to maintain consistent formatting. It is run as part of the pre-commit hook and is recommended to be run on save in the developer's editor.
- `isort <https://pycqa.github.io/isort/>`_ to sensibly order import statements in Python files. It is also run as part of the pre-commit hook.
Release Procedure
-----------------
Making a release on GitHub with the tag vX.Y.Z will update the documentation on `master` and push cxroots at the tagged commit to PyPI.
The documentation can be manually generated by running `./create_docs` in the `docs_src` directory.
References
----------
.. [KB] \P. Kravanja and M. Van Barel. *Computing the Zeros of Analytic Functions*. Springer, Berlin, Heidelberg, 2000.