Polynomials¶
Implemented in abel.tools.polynomial
.
Abel transform¶
The Abel transform of a polynomial
defined on a domain \([r_\text{min}, r_\text{max}]\) (and zero elsewhere) is calculated as
where \(r = \sqrt{x^2 + y^2}\), and the Abel integral is taken over the domain where \(r_\text{min} \le r \le r_\text{max}\). Namely,
These integrals for any power \(k\) are easily obtained from the recursive relation
For even \(k\) this yields a polynomial in \(y\) and powers of \(x\) and \(r\):
For odd \(k\), the recursion terminates at
so
with the same expressions for \(C_m\).
These sums are computed using Horner’s method in \(x\), which requires only \(x^2\), \(y\) (see above), \(\ln (y + r)\) (for polynomials with odd degrees), and powers of \(r\) up to \(K\).
The sum of the integrals, however, is computed by direct addition. In particular, this means that an attempt to use this method for high-degree polynomials (for example, approximating some function with a 100-degree Taylor polynomial) will most likely fail due to loss of significance in floating-point operations. Splines are a much better choice in this respect, although at sufficiently large \(r\) and \(x\) (≳10 000) these numerical problems might become significant even for cubic polynomials.
Affine transformation¶
It is sometimes convenient to define a polynomial in some canonical form and adapt it to the particular case by an affine transformation (translation and scaling) of the independent variable, like in the example below.
The scaling around \(r = 0\) is
which applies an \(s\)-fold stretching to the function. The coefficients of the transformed polynomial are thus
The translation is
which shifts the origin to \(r_0\). The coefficients of the transformed polynomial can be obtained by expanding all powers of the binomial \(r - r_0\) and collecting the powers of \(r\). This is implemented in a matrix form
where the coefficients are represented by a column vector \(\mathbf{c} = (c_0, c_1, \dots, c_K)^\mathrm{T}\), and the matrix \(\mathrm{M}\) is the Hadamard product of the upper-triangular Pascal matrix and the Toeplitz matrix of \(r_0^k\):
Example¶
Consider a two-sided step function with soft edges:
The edges can be represented by the cubic smoothstep function
which smoothly rises from \(0\) at \(r = 0\) to \(1\) at \(r = 1\). The left edge requires stretching it by \(2w\) and shifting the origin to \(r_\text{min} - w\). The right edge is \(S(r)\) stretched by \(-2w\) (the negative sign mirrors it horizontally) and shifted to \(r_\text{max} + w\). The shelf is just a constant (zeroth-degree polynomial). It can be set to \(1\), and then the desired function with the amplitude \(A\) is obtained by multiplying the resulting piecewise polynomial by \(A\):
import matplotlib.pyplot as plt
import numpy as np
from abel.tools.polynomial import PiecewisePolynomial as PP
r = np.arange(51.0)
rmin = 10
rmax = 40
w = 5
A = 3
c = [0, 0, 3, -2]
smoothstep = A * PP(r, [(rmin - w, rmin + w, c, rmin - w, 2 * w),
(rmin + w, rmax - w, [1]),
(rmax - w, rmax + w, c, rmax + w, -2 * w)])
fig, axs = plt.subplots(2, 1)
axs[0].set_title('func')
axs[0].set_xlabel('$r$')
axs[0].plot(r, smoothstep.func)
axs[1].set_title('abel')
axs[1].set_xlabel('$x$')
axs[1].plot(r, smoothstep.abel)
plt.tight_layout()
plt.show()
Polynomial
and PiecewisePolynomial
are also accessible through the
abel.tools.analytical
module. Amplitude scaling by multiplying the
“function” (a Python object actually) is not supported there, but it can be
achieved simply by scaling all the coefficients:
from abel.tools.analytical import PiecewisePolynomial as PP
c = A * np.array([0, 0, 3, -2])
smoothstep = PP(..., [(rmin - w, rmin + w, c, rmin - w, 2 * w),
(rmin + w, rmax - w, [A]),
(rmax - w, rmax + w, c, rmax + w, -2 * w)], ...)