gftool.hermpade.pade
- gftool.hermpade.pade(an, num_deg: int, den_deg: int, fast=False) RatPol [source]
Return the [num_deg/den_deg] Padé approximant to the polynomial an.
- Parameters:
- an(L,) array_like
Taylor series coefficients representing polynomial of order
L-1
.- num_deg, den_degint
The order of the return approximating numerator/denominator polynomial. The sum must be at most
L
:L >= num_deg + den_deg + 1
.- fastbool, optional
If fast, use faster
solve_toeplitz
algorithm. Else use QR and calculate null-vector (default: False).
- Returns:
- RatPol
The rational polynomial with numerator
RatPol.numer
, and denominatorRatPol.denom
.
Examples
Let’s approximate the cubic root
f(z) = (1 + z)**(1/3)
by the[8/8]
Padé approximant:>>> from scipy.special import binom >>> an = binom(1/3, np.arange(8+8+1)) # Taylor of (1+x)**(1/3) >>> x = np.linspace(-1, 3, num=500) >>> fx = np.emath.power(1+x, 1/3)
>>> pade = gt.hermpade.pade(an, num_deg=8, den_deg=8)
>>> import matplotlib.pyplot as plt >>> __ = plt.plot(x, fx, label='exact', color='black') >>> __ = plt.plot(x, np.polynomial.Polynomial(an)(x), '--', label='Taylor') >>> __ = plt.plot(x, pade.eval(x), ':', label='Pade') >>> __ = plt.ylim(ymin=0, ymax=2) >>> __ = plt.legend(loc='upper left') >>> plt.show()
The Padé approximation is able to approximate the function even for larger
x
.Using
fast=True
, the Toeplitz structure is used to evaluate thepade
faster using Levinson recursion. This might, however, be less accurate in some cases.>>> padef = gt.hermpade.pade(an, num_deg=8, den_deg=8, fast=True) >>> __ = plt.plot(x, abs(np.polynomial.Polynomial(an)(x) - fx), label='Taylor') >>> __ = plt.plot(x, abs(pade.eval(x) - fx), label='QR') >>> __ = plt.plot(x, abs(padef.eval(x) - fx), label='Levinson') >>> __ = plt.legend() >>> plt.yscale('log') >>> plt.show()