Skip to main content

A Python implementation of the AAA algorithm for rational approximation

Project description

The AAA algorithm for rational approximation Build Status

This is a Python implementation of the AAA algorithm for rational approximation described in the paper "The AAA Algorithm for Rational Approximation" by Yuji Nakatsukasa, Olivier Sète, and Lloyd N. Trefethen, SIAM Journal on Scientific Computing 2018 40:3, A1494-A1522. (doi)

A MATLAB implementation of this algorithm is contained in Chebfun. The present Python version is a more or less direct port of the MATLAB version.

The "cleanup" feature for spurious poles and zeros is not currently implemented.

Installation

The implementation is in pure Python and requires only numpy and scipy as dependencies. Install it using pip:

pip install aaa-approx

Usage

Here's an example of how to approximate a function in the interval [0,1]:

import numpy as np
from aaa import aaa

Z = np.linspace(0.0, 1.0, 1000)
F = np.exp(Z) * np.sin(2*np.pi*Z)

r = aaa(F, Z, mmax=10)

Instead of the maximum number of terms mmax, it's also possible to specify the error tolerance tol. Both arguments work exactly as in the MATLAB version.

The returned object r is an instance of the class aaa.BarycentricRational and can be called like a function. For instance, you can compute the error on Z like this:

err = F - r(Z)
print(np.linalg.norm(err, np.inf))

If you are interested in the poles and residues of the computed rational function, you can query them like

pol,res = r.polres()

and the zeroes using

zer = r.zeros()

Finally, the nodes, values and weights used for interpolation (called zj, fj and wj in the original implementation) can be accessed as properties:

r.nodes
r.values
r.weights

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

aaa-approx-1.0.2.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

aaa_approx-1.0.2-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file aaa-approx-1.0.2.tar.gz.

File metadata

  • Download URL: aaa-approx-1.0.2.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.18.4 setuptools/39.2.0 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.6.5

File hashes

Hashes for aaa-approx-1.0.2.tar.gz
Algorithm Hash digest
SHA256 b3739ff6cfb1d9de6397136fcfb89c32109b634f99c5d4220b0fa759ce0276aa
MD5 5c73a49aad23c4225ee84a19b1478a8b
BLAKE2b-256 6eb3396f743df69389f1f05e5317962138c21f679457dd9b0b3e0f794fb042c0

See more details on using hashes here.

File details

Details for the file aaa_approx-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: aaa_approx-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.18.4 setuptools/39.2.0 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.6.5

File hashes

Hashes for aaa_approx-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7560f5364fa28bbbeff9a8163b9e83b2e51c89b7e95bb1ab4b81eb50935dab45
MD5 b1e069f0e94d219309db4a0c25d14724
BLAKE2b-256 48a0a0a536c51c8aaf6d29536d087a10086341048c24c206ab0104a454285204

See more details on using hashes here.

Supported by

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