Skip to main content

Find all the roots (zeros) of a complex analytic function within a given contour in the complex plane.

Project description

pkg_img doi tests coverage sonarcloud

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 for a more details and a tutorial.

With Python installed you can install cxroots by entering in the terminal/command line

pip install cxroots

Example

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()
https://github.com/rparini/cxroots/blob/master/README_resources/readme_example.png?raw=true
print(roots)
 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 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 https://doi.org/10.5281/zenodo.7013117

BibTex:

@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.7013116},
  url = {https://github.com/rparini/cxroots},
  year = {2018}
}

Development

  • Install the pre-commit and then run pre-commit install. The pre-commit scripts can also be run manually with pre-commit run --all-files

  • The project uses ruff for formatting and linting. It is run as part of the pre-commit hook and is recommended to be run on save in the developer’s editor.

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] (1,2)

P. Kravanja and M. Van Barel. Computing the Zeros of Analytic Functions. Springer, Berlin, Heidelberg, 2000.

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

cxroots-3.2.0.tar.gz (47.6 MB view details)

Uploaded Source

Built Distribution

cxroots-3.2.0-py3-none-any.whl (54.1 kB view details)

Uploaded Python 3

File details

Details for the file cxroots-3.2.0.tar.gz.

File metadata

  • Download URL: cxroots-3.2.0.tar.gz
  • Upload date:
  • Size: 47.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.2

File hashes

Hashes for cxroots-3.2.0.tar.gz
Algorithm Hash digest
SHA256 c41a81db1080a65de78fa88d471ce8f4f8870b6d9016f3c2607208d027117e39
MD5 c1d5554b5979b5856052a5fe61a58727
BLAKE2b-256 ce56e3e75edbcb1818a52a14de87aef4159f298941becc43c1f057c6edd59cd4

See more details on using hashes here.

File details

Details for the file cxroots-3.2.0-py3-none-any.whl.

File metadata

  • Download URL: cxroots-3.2.0-py3-none-any.whl
  • Upload date:
  • Size: 54.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.2

File hashes

Hashes for cxroots-3.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4b1625919c155da38225147ceeb6042d7bbb22f7f44dfdddb251ab7fa7710373
MD5 41828de9862a370731056a1010b0ca17
BLAKE2b-256 d526e5524ef2591d524d430e80df51eb6520eff964c8b2ae0064c4ab724cdcbc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page