
    (phl                     l    S SK r S SKrS SKrS SKrSS/r " S S5      r " S S\5      r " S S\5      rg)    NAAAFloaterHormannInterpolatorc                   B    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
rg)_BarycentricRational$   zABase class for Barycentric representation of a rational function.c                 <   [         R                  " U5      n[         R                  " U5      nU R                  " XE40 UD6  [         R                  R	                  [         R
                  " U5      [         R                  " U5      ) -  R                  UR                  S   S5      SS9nXVS4   nXF   n[         R                  " USS9u  pGXWS4   nUR                  SS  U l
        U R                  " XE40 UD6u  U l        U l        U l        S U l        S U l        S U l        g )Nr   axis.T)return_index   )npasarray_input_validationlogical_andreduceisfiniteisnanreshapeshapeunique_shape_compute_weights_support_points_support_valuesweights_poles	_residues_roots)selfxykwargszfto_keepunis           S/var/www/html/venv/lib/python3.13/site-packages/scipy/interpolate/_bary_rational.py__init___BarycentricRational.__init__&   s    JJqMJJqMq.v. ..''kk!n"((1+.77
BG ( 
 slOJ1403hKggabk!!!1&1 	Ad2DL
     c                 4   UR                   S:w  a  [        S5      eUR                   S:  d  [        S5      eUR                  UR                  S   :w  a  [        S5      e[        R
                  " [        R                  " U5      5      (       d  [        S5      eg )Nr   z`x` must be 1-D.z`y` must be at least 1-D.r   z3`x` be the same size as the first dimension of `y`.z`x` must be finite.)ndim
ValueErrorsizer   r   allr   )r    r!   r"   r#   s       r(   r   &_BarycentricRational._input_validationA   sx    66Q;/00vv{89966QWWQZRSSvvbkk!n%%233 &r+   c                     [         eN)NotImplementedError)r$   r%   r#   s      r(   r   %_BarycentricRational._compute_weightsN   s    !!r+   c                 Z   [         R                  " U5      n[         R                  " U5      nU R                  R	                  U R                  R
                  S   S45      nU R                  S[         R                  4   n[         R                  " SSS9   S[         R                  R                  X R                  5      -  nXTU-  -  XT-  -  nSSS5        [         R                  " [         R                  " U5      5      (       aF  [         R                  " XC-  5      [         R                  " U5      -  W[         R                  " U5      '   [         R                  " [         R                   " W5      5      S   nU Hp  n[         R                   " X(   5      (       d*  [         R                  " X(   U R                  :H  5      (       d  ML  X2U   U R                  :H     R#                  5       Xh'   Mr     [         R                  " XaR
                  U R$                  -   5      $ ! , (       d  f       GNT= f)zmEvaluate the rational approximation at given values.

Parameters
----------
z : array_like
    Input values.
r   r	   .ignore)invaliddivider   N)r   r   ravelr   r   r   r   newaxiserrstatesubtractouterr   anyisinfsumnonzeror   squeezer   )	r    r$   zvsupport_valuesr   CCriijjs	            r(   __call___BarycentricRational.__call__Q   s    JJqMXXa[--55!!''*B/
 ,,sBJJ/ [[(;R[[&&r+?+?@@B./2<@A < 66"((2,!vvg&>?!# 1AbhhrlO ZZ$Q'Bxxrvvbf8L8L.L'M'M  '"v1E1E'EFNNP  zz!WWt{{233- <;s   9H
H*c                 F   U R                   Gc  U R                  R                  n[        R                  " US-   U R                  R
                  S9nSUS'   [        R                  " U[        R                  " U R                  U R                  5      S9nU R                  USSS24'   SUSS2S4'   [        R                  " USS2SS24   U R                  5        [        R                  R                  X25      nU[        R                  " U5         U l         U R                   $ )zCompute the poles of the rational approximation.

Returns
-------
poles : array
    Poles of the AAA approximation, repeated according to their multiplicity
    but not in any specific order.
Nr   dtyper   r   r   )r   r   r/   r   eyerN   
zeros_likeresult_typer   fill_diagonalscipylinalgeigvalsr   )r    mBEpols        r(   poles_BarycentricRational.poles|   s     ;;!!Aq1uDLL$6$67AAdGar~~dll6:6J6J(L MA||AaeHAab!eHQqr12vY(<(<=,,&&q,Cbkk#./DK{{r+   c                    U R                   c  [        R                  " SSS9   S[        R                  R	                  U R                  5       U R                  5      -  U R                  U R                  -  -  nS[        R                  R	                  U R                  5       U R                  5      -  S-  * U R                  -  nX-  U l         SSS5        U R                   $ U R                   $ ! , (       d  f       U R                   $ = f)zCompute the residues of the poles of the approximation.

Returns
-------
residues : array
    Residues associated with the `poles` of the approximation
Nr7   r9   r8   r      )	r   r   r<   r=   r>   r[   r   r   r   )r    NDdiffs      r(   residues_BarycentricRational.residues   s     >>!Hh?))$**,8L8LMN((4<<7 **4::<9M9MNNQRRSll#  "# @ ~~t~~ @? ~~s   B+C..
Dc                 v   U R                   Gc   U R                  R                  n[        R                  " US-   U R                  R
                  S9nSUS'   [        R                  " U[        R                  " U R                  U R                  U R                  5      S9nU R                  U R                  -  USSS24'   SUSS2S4'   [        R                  " USS2SS24   U R                  5        [        R                  R                  X25      nU[        R                  " U5         U l         U R                   $ )zCompute the zeros of the rational approximation.

Returns
-------
zeros : array
    Zeros of the AAA approximation, repeated according to their multiplicity
    but not in any specific order.
Nr   rM   r   rO   )r   r   r/   r   rP   rN   rQ   rR   r   r   rS   rT   rU   rV   r   )r    rW   rX   rY   zers        r(   roots_BarycentricRational.roots   s     ;;!!Aq1uDLL$6$67AAdGar~~dll6:6J6J6:6J6J(L MA ||d&:&::AaeHAab!eHQqr12vY(<(<=,,&&q,Cbkk#./DK{{r+   )r   r   r   r   r   r   r   N)__name__
__module____qualname____firstlineno____doc__r)   r   r   rJ   r[   rb   rf   __static_attributes__ r+   r(   r   r   $   s)    K64")4V2*r+   r   c                   ~   ^  \ rS rSrSrSSSSS.U 4S jjr  SU 4S	 jjr\S
 5       r\S 5       r	S r
SS jrSrU =r$ )r      uJ"  
AAA real or complex rational approximation.

As described in [1]_, the AAA algorithm is a greedy algorithm for approximation by
rational functions on a real or complex set of points. The rational approximation is
represented in a barycentric form from which the roots (zeros), poles, and residues
can be computed.

Parameters
----------
x : 1D array_like, shape (n,)
    1-D array containing values of the independent variable. Values may be real or
    complex but must be finite.
y : 1D array_like, shape (n,)
    Function values ``f(x)``. Infinite and NaN values of `values` and
    corresponding values of `points` will be discarded.
rtol : float, optional
    Relative tolerance, defaults to ``eps**0.75``. If a small subset of the entries
    in `values` are much larger than the rest the default tolerance may be too
    loose. If the tolerance is too tight then the approximation may contain
    Froissart doublets or the algorithm may fail to converge entirely.
max_terms : int, optional
    Maximum number of terms in the barycentric representation, defaults to ``100``.
    Must be greater than or equal to one.
clean_up : bool, optional
    Automatic removal of Froissart doublets, defaults to ``True``. See notes for
    more details.
clean_up_tol : float, optional
    Poles with residues less than this number times the geometric mean
    of `values` times the minimum distance to `points` are deemed spurious by the
    cleanup procedure, defaults to 1e-13. See notes for more details.

Attributes
----------
support_points : array
    Support points of the approximation. These are a subset of the provided `x` at
    which the approximation strictly interpolates `y`.
    See notes for more details.
support_values : array
    Value of the approximation at the `support_points`.
weights : array
    Weights of the barycentric approximation.
errors : array
    Error :math:`|f(z) - r(z)|_\infty` over `points` in the successive iterations
    of AAA.

Warns
-----
RuntimeWarning
    If `rtol` is not achieved in `max_terms` iterations.

See Also
--------
FloaterHormannInterpolator : Floater-Hormann barycentric rational interpolation.
pade : Padé approximation.

Notes
-----
At iteration :math:`m` (at which point there are :math:`m` terms in the both the
numerator and denominator of the approximation), the
rational approximation in the AAA algorithm takes the barycentric form

.. math::

    r(z) = n(z)/d(z) =
    \frac{\sum_{j=1}^m\ w_j f_j / (z - z_j)}{\sum_{j=1}^m w_j / (z - z_j)},

where :math:`z_1,\dots,z_m` are real or complex support points selected from
`x`, :math:`f_1,\dots,f_m` are the corresponding real or complex data values
from `y`, and :math:`w_1,\dots,w_m` are real or complex weights.

Each iteration of the algorithm has two parts: the greedy selection the next support
point and the computation of the weights. The first part of each iteration is to
select the next support point to be added :math:`z_{m+1}` from the remaining
unselected `x`, such that the nonlinear residual
:math:`|f(z_{m+1}) - n(z_{m+1})/d(z_{m+1})|` is maximised. The algorithm terminates
when this maximum is less than ``rtol * np.linalg.norm(f, ord=np.inf)``. This means
the interpolation property is only satisfied up to a tolerance, except at the
support points where approximation exactly interpolates the supplied data.

In the second part of each iteration, the weights :math:`w_j` are selected to solve
the least-squares problem

.. math::

    \text{minimise}_{w_j}|fd - n| \quad \text{subject to} \quad
    \sum_{j=1}^{m+1} w_j = 1,

over the unselected elements of `x`.

One of the challenges with working with rational approximations is the presence of
Froissart doublets, which are either poles with vanishingly small residues or
pole-zero pairs that are close enough together to nearly cancel, see [2]_. The
greedy nature of the AAA algorithm means Froissart doublets are rare. However, if
`rtol` is set too tight then the approximation will stagnate and many Froissart
doublets will appear. Froissart doublets can usually be removed by removing support
points and then resolving the least squares problem. The support point :math:`z_j`,
which is the closest support point to the pole :math:`a` with residue
:math:`\alpha`, is removed if the following is satisfied

.. math::

    |\alpha| / |z_j - a| < \verb|clean_up_tol| \cdot \tilde{f},

where :math:`\tilde{f}` is the geometric mean of `support_values`.


References
----------
.. [1] Y. Nakatsukasa, O. Sete, and L. N. Trefethen, "The AAA algorithm for
        rational approximation", SIAM J. Sci. Comp. 40 (2018), A1494-A1522.
        :doi:`10.1137/16M1106122`
.. [2] J. Gilewicz and M. Pindor, Pade approximants and noise: rational functions,
       J. Comp. Appl. Math. 105 (1999), pp. 285-297.
       :doi:`10.1016/S0377-0427(02)00674-X`

Examples
--------

Here we reproduce a number of the numerical examples from [1]_ as a demonstration
of the functionality offered by this method.

>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> from scipy.interpolate import AAA
>>> import warnings

For the first example we approximate the gamma function on ``[-3.5, 4.5]`` by
extrapolating from 100 samples in ``[-1.5, 1.5]``.

>>> from scipy.special import gamma
>>> sample_points = np.linspace(-1.5, 1.5, num=100)
>>> r = AAA(sample_points, gamma(sample_points))
>>> z = np.linspace(-3.5, 4.5, num=1000)
>>> fig, ax = plt.subplots()
>>> ax.plot(z, gamma(z), label="Gamma")
>>> ax.plot(sample_points, gamma(sample_points), label="Sample points")
>>> ax.plot(z, r(z).real, '--', label="AAA approximation")
>>> ax.set(xlabel="z", ylabel="r(z)", ylim=[-8, 8], xlim=[-3.5, 4.5])
>>> ax.legend()
>>> plt.show()

We can also view the poles of the rational approximation and their residues:

>>> order = np.argsort(r.poles())
>>> r.poles()[order]
array([-3.81591039e+00+0.j        , -3.00269049e+00+0.j        ,
       -1.99999988e+00+0.j        , -1.00000000e+00+0.j        ,
        5.85842812e-17+0.j        ,  4.77485458e+00-3.06919376j,
        4.77485458e+00+3.06919376j,  5.29095868e+00-0.97373072j,
        5.29095868e+00+0.97373072j])
>>> r.residues()[order]
array([ 0.03658074 +0.j        , -0.16915426 -0.j        ,
        0.49999915 +0.j        , -1.         +0.j        ,
        1.         +0.j        , -0.81132013 -2.30193429j,
       -0.81132013 +2.30193429j,  0.87326839+10.70148546j,
        0.87326839-10.70148546j])

For the second example, we call `AAA` with a spiral of 1000 points that wind 7.5
times around the origin in the complex plane.

>>> z = np.exp(np.linspace(-0.5, 0.5 + 15j*np.pi, 1000))
>>> r = AAA(z, np.tan(np.pi*z/2), rtol=1e-13)

We see that AAA takes 12 steps to converge with the following errors:

>>> r.errors.size
12
>>> r.errors
array([2.49261500e+01, 4.28045609e+01, 1.71346935e+01, 8.65055336e-02,
       1.27106444e-02, 9.90889874e-04, 5.86910543e-05, 1.28735561e-06,
       3.57007424e-08, 6.37007837e-10, 1.67103357e-11, 1.17112299e-13])

We can also plot the computed poles:

>>> fig, ax = plt.subplots()
>>> ax.plot(z.real, z.imag, '.', markersize=2, label="Sample points")
>>> ax.plot(r.poles().real, r.poles().imag, '.', markersize=5,
...         label="Computed poles")
>>> ax.set(xlim=[-3.5, 3.5], ylim=[-3.5, 3.5], aspect="equal")
>>> ax.legend()
>>> plt.show()

We now demonstrate the removal of Froissart doublets using the `clean_up` method
using an example from [1]_. Here we approximate the function
:math:`f(z)=\log(2 + z^4)/(1 + 16z^4)` by sampling it at 1000 roots of unity. The
algorithm is run with ``rtol=0`` and ``clean_up=False`` to deliberately cause
Froissart doublets to appear.

>>> z = np.exp(1j*2*np.pi*np.linspace(0,1, num=1000))
>>> def f(z):
...     return np.log(2 + z**4)/(1 - 16*z**4)
>>> with warnings.catch_warnings():  # filter convergence warning due to rtol=0
...     warnings.simplefilter('ignore', RuntimeWarning)
...     r = AAA(z, f(z), rtol=0, max_terms=50, clean_up=False)
>>> mask = np.abs(r.residues()) < 1e-13
>>> fig, axs = plt.subplots(ncols=2)
>>> axs[0].plot(r.poles().real[~mask], r.poles().imag[~mask], '.')
>>> axs[0].plot(r.poles().real[mask], r.poles().imag[mask], 'r.')

Now we call the `clean_up` method to remove Froissart doublets.

>>> with warnings.catch_warnings():
...     warnings.simplefilter('ignore', RuntimeWarning)
...     r.clean_up()
4
>>> mask = np.abs(r.residues()) < 1e-13
>>> axs[1].plot(r.poles().real[~mask], r.poles().imag[~mask], '.')
>>> axs[1].plot(r.poles().real[mask], r.poles().imag[mask], 'r.')
>>> plt.show()

The left image shows the poles prior of the approximation ``clean_up=False`` with
poles with residue less than ``10^-13`` in absolute value shown in red. The right
image then shows the poles after the `clean_up` method has been called.
Nd   TvIh%<=)rtol	max_termsclean_upclean_up_tolc                T   > [         TU ]  XX4S9  U(       a  U R                  U5        g g )N)rs   rt   )superr)   ru   r    r!   r"   rs   rt   ru   rv   	__class__s          r(   r)   AAA.__init__  s)    D>MM,' r+   c                    > [         R                  " U5      nUS:  a  [        S5      eUR                  S:w  a  [        S5      e[        TU ]  X5        g )Nr   zB`max_terms` must be an integer value greater than or equal to one.z`y` must be 1-D.)operatorindexr.   r-   rx   r   ry   s          r(   r   AAA._input_validation  sP    NN9-	q= - . . 66Q;/00!!'r+   c                     U R                   $ r3   )r   r    s    r(   support_pointsAAA.support_points      ###r+   c                     U R                   $ r3   )r   r   s    r(   rE   AAA.support_values  r   r+   c                 j	   [         R                  " U5      n[         R                  " U[         R                  S9n[         R                  " XS5      nUc#  [         R
                  " U5      R                  S-  OUnU[         R                  R                  U[         R                  S9-  n[         R                  " XGS9n	[         R                  " XGS9n
[         R                  " XT4US9n[         R                  " XT4US9n[         R                  " XLR                  R                  S9n[         R                  " [         R                  " U5      U5      n[        U5       GH  n[         R                   " [         R"                  " X&   X   -
  5      5      nX   U   X'   X&   U   X'   [         R$                  " SSS9   SXU   U   -
  -  US S 2U4'   S S S 5        SU[         R&                  " U5      S	   U   '   [         R$                  " SS
9   X*U   -
  US S 2U4   -  US S 2U4'   S S S 5        UR)                  5       nUUS-   :  a  [*        R                  R-                  XS US-   24   SSS9u  nnnU[         R.                  " U5      :H  nUR1                  5       US S 24   R)                  S	S9[         R2                  " UR)                  5       5      -  R5                  U5      nO\[*        R                  R7                  XS US-   24   SS9nUR8                  S   nUR)                  SS9[         R2                  " U5      -  nUS	:g  n[         R$                  " SS
9   US S 2S US-   24   S S 2U4   UU   U
S US-    U   -  -  nUS S 2S US-   24   S S 2U4   UU   -  nS S S 5        [         R:                  " W5      [         R<                  " U5      -  nSUU'   UU   WU'   UU-  n[         R                  R                  X.-
  [         R                  S9nUX'   UU::  d  GM    O   WUS-
  :X  a  [>        R@                  " SU S3[B        SS9  U	S US-    n	U
S US-    n
WS	:g  nUS US-    U l"        Xl#        X l$        U	U   U
U   UU   4$ ! , (       d  f       GN= f! , (       d  f       GNy= f! , (       d  f       GN= f)NrM         ?g      ?)ordr7   r^   r   Fr   )r8   )full_matricescheck_finiter
   r   r	   zAAA failed to converge within z iterations.r_   
stacklevel)%r   r/   onesbool_rR   finfoepsrU   norminfemptyrealrN   repeatmeanrangeargmaxabsr<   rB   rA   rT   svdminconjsqrtastype
null_spacer   r@   r   warningswarnRuntimeWarningerrors_points_values)r    r$   r%   rs   rt   MmaskrN   atolzjfjCAr   RrW   rI   rows_sVmmwjnmi0r`   DD_inf	max_error
i_non_zeros                                 r(   r   AAA._compute_weights  s3   GGAJwwq)qS),0Lrxx""D(dbiinnQBFFn33XXi-XXi-HHa^51HHa^51)66<<8IIbggaj!$ y!A 266!'AG"345BGBKBEGBKBE Hh?qT72;/!Q$ @ -2DD!!$R() X.!u9!Q$/!Q$ / 88:Dq1u},,**Ga!eGm$E + 1a "&&)^ffhr1uo))q)1BGGBFFH4EEMMeT LL++AGa!eGm,<5+QWWR[UUU^bggbk1 qBX.a1q5jM!R%(BrFR!a%[_,DEa1q5jM!R%(2b61	 / HHQK"((1+-EAeHxAeHAA 		qu"&&9I!FID q "t 	AMM:9+\R(Q8 !a%[!a%[ 1W
Wq1uo*~r*~r*~=={ @? /.2 /.s%   6Q?RAR#?
R	
R 	#
R2	c           	      H   [         R                  R                  [        R                  " U R
                  5      5      n[        R                  " [        R                  " [        R                  R                  U R                  5       U R                  5      5      SS9n[        R                  " SSS9   [        R                  " [        R                  " U R                  5       5      U-  X-  :  5      nSSS5        WS   R                  nUS:X  a  U$ [        R                   " U S3["        SS	9  [        R$                  " [        R                  " [        R                  R                  U R&                  U R                  5       U   5      5      SS9n[        R(                  " U R&                  U5      U l        [        R(                  " U R*                  U5      U l        [        R,                  R/                  [        R0                  R                  U R                  U R&                  5      SS9nU R
                  U   nU R                  U   n	U R&                  R                  n
S[        R                  R                  XR&                  5      -  nUSS2[        R2                  4   U-  XR*                  -  -
  n[         R4                  R7                  US
S9u    p[        R8                  " XS-
  SS24   5      U l        SU l        SU l        SU l         U$ ! , (       d  f       GN&= f)a`  Automatic removal of Froissart doublets.

Parameters
----------
cleanup_tol : float, optional
    Poles with residues less than this number times the geometric mean
    of `values` times the minimum distance to `points` are deemed spurious by
    the cleanup procedure, defaults to 1e-13.

Returns
-------
int
    Number of Froissart doublets detected
r   r
   r7   r^   Nr   z Froissart doublets detected.r_   r   Fr   )!rT   statsgmeanr   r   r   r   r=   r>   r[   r   r<   rB   rb   r/   r   r   r   argminr   deleter   r   r   	not_equalr;   rU   r   r   r   r   r   r   )r    cleanup_tolgeom_mean_abs_fZ_distancesrH   niclosest_spt_pointr   r%   r$   rW   r   r   r   r   s                  r(   ru   AAA.clean_up  s]      ++++BFF4<<,@AffFF2;;$$TZZ\4<<@A
 [[(;t}}'+58UUB <
 UZZ7I9:N#$	& IIFF2;;$$T%9%94::<;KLMTU
  "yy)=)=?PQ!yy)=)=?PQ ~~$$LLt||T-A-AB % 
 LLLL
   %% !!!%9%9::amq 1';';#;; ,,""15"91wwqQqz* 	[ <;s   2AL
L!)	r   r   r   r   r   r   r   r   r   )Nrq   Trr   )rr   )rh   ri   rj   rk   rl   r)   r   propertyr   rE   r   ru   rm   __classcell__rz   s   @r(   r   r      sj    Vn &*S4#( ( JN',
( $ $ $ $X>tC Cr+   c                   F   ^  \ rS rSrSrSS.U 4S jjrU 4S jrS rSrU =r	$ )	r   iW  u  
Floater-Hormann barycentric rational interpolation.

As described in [1]_, the method of Floater and Hormann computes weights for a
Barycentric rational interpolant with no poles on the real axis.

Parameters
----------
x : 1D array_like, shape (n,)
    1-D array containing values of the independent variable. Values may be real or
    complex but must be finite.
y : array_like, shape (n, ...)
    Array containing values of the dependent variable. Infinite and NaN values
    of `values` and corresponding values of `x` will be discarded.
d : int, optional
    Blends ``n - d`` degree `d` polynomials together. For ``d = n - 1`` it is
    equivalent to polynomial interpolation. Must satisfy ``0 <= d < n``,
    defaults to 3.

Attributes
----------
weights : array
    Weights of the barycentric approximation.

See Also
--------
AAA : Barycentric rational approximation of real and complex functions.
pade : Padé approximation.

Notes
-----
The Floater-Hormann interpolant is a rational function that interpolates the data
with approximation order :math:`O(h^{d+1})`. The rational function blends ``n - d``
polynomials of degree `d` together to produce a rational interpolant that contains
no poles on the real axis, unlike `AAA`. The interpolant is given
by

.. math::

    r(x) = \frac{\sum_{i=0}^{n-d} \lambda_i(x) p_i(x)}
    {\sum_{i=0}^{n-d} \lambda_i(x)},

where :math:`p_i(x)` is an interpolating polynomials of at most degree `d` through
the points :math:`(x_i,y_i),\dots,(x_{i+d},y_{i+d}), and :math:`\lambda_i(z)` are
blending functions defined by

.. math::

    \lambda_i(x) = \frac{(-1)^i}{(x - x_i)\cdots(x - x_{i+d})}.

When ``d = n - 1`` this reduces to polynomial interpolation.

Due to its stability following barycentric representation of the above equation
is used instead for computation

.. math::

    r(z) = \frac{\sum_{k=1}^m\ w_k f_k / (x - x_k)}{\sum_{k=1}^m w_k / (x - x_k)},

where the weights :math:`w_j` are computed as

.. math::

    w_k &= (-1)^{k - d} \sum_{i \in J_k} \prod_{j = i, j \neq k}^{i + d}
    1/|x_k - x_j|, \\
    J_k &= \{ i \in I: k - d \leq i \leq k\},\\
    I &= \{0, 1, \dots, n - d\}.

References
----------
.. [1] M.S. Floater and K. Hormann, "Barycentric rational interpolation with no
       poles and high rates of approximation", Numer. Math. 107, 315 (2007).
       :doi:`10.1007/s00211-007-0093-y`

Examples
--------

Here we compare the method against polynomial interpolation for an example where
the polynomial interpolation fails due to Runge's phenomenon.

>>> import numpy as np
>>> from scipy.interpolate import (FloaterHormannInterpolator,
...                                BarycentricInterpolator)
>>> def f(z):
...     return 1/(1 + z**2)
>>> z = np.linspace(-5, 5, num=15)
>>> r = FloaterHormannInterpolator(z, f(z))
>>> p = BarycentricInterpolator(z, f(z))
>>> zz = np.linspace(-5, 5, num=1000)
>>> import matplotlib.pyplot as plt
>>> fig, ax = plt.subplots()
>>> ax.plot(zz, r(zz), label="Floater=Hormann")
>>> ax.plot(zz, p(zz), label="Polynomial")
>>> ax.legend()
>>> plt.show()
   dc                "   > [         TU ]  XUS9  g )Nr   )rx   r)   )r    pointsvaluesr   rz   s       r(   r)   #FloaterHormannInterpolator.__init__  s    1-r+   c                    > [         R                  " U5      nSUs=::  a  [        U5      :  d  O  [        S5      e[        TU ]  X5        g )Nr   z`d` must satisfy 0 <= d < n)r}   r~   lenr.   rx   r   )r    r!   r"   r   rz   s       r(   r   ,FloaterHormannInterpolator._input_validation  s9    NN1QQ:;;!!'r+   c                    [         R                  " U[         R                  " US5      S9nUR                  n[	        U5       H  n[	        [        Xc-
  S5      [        US-   XS-
  5      5       H]  nXF==   S[         R                  " [         R                  " [         R                  " X   XXs-   S-    -
  Xg-
  5      5      5      -  -  ss'   M_     M     US[         R                  " U5      U-
  -  -  nXU4$ )Nr   rM   r   r   g      )r   rQ   rR   r/   r   maxr   prodr   r   arange)r    r$   r%   r   wnkis           r(   r   +FloaterHormannInterpolator._compute_weights  s    MM!2>>!S#9:FFqA3qsA;AaC6"''"&&14!	:J3JAE)R"STTT 7  	
cRYYq\A%&&Qwr+   rn   )
rh   ri   rj   rk   rl   r)   r   r   rm   r   r   s   @r(   r   r   W  s(    _@ -. . .(	 	r+   )	r   r}   numpyr   rT   __all__r   r   r   rn   r+   r(   <module>r      sL   4     .
/] ]@P
 Pft!5 tr+   