/ lib / numpy / polynomial / chebyshev.pyc
chebyshev.pyc
   1  o

   2  [��cT��@s�dZddlZddlmZddlmZddlm	Z
   3  ddlmZgd�Z
e
   4  jZdd	�Zd
   5  d�Zdd
�Zdd�Zdd�Zdd�Zdd�Zdd�Ze�ddg�Ze�dg�Ze�dg�Ze�ddg�Zdd�Zdd�Zdd�Zdd �Z d!d"�Z!d#d$�Z"d%d&�Z#dSd(d)�Z$dTd*d+�Z%dgdddfd,d-�Z&dUd/d0�Z'd1d2�Z(d3d4�Z)d5d6�Z*d7d8�Z+d9d:�Z,d;d<�Z-d=d>�Z.dVd@dA�Z/dBdC�Z0dDdE�Z1dWdGdH�Z2dIdJ�Z3dKdL�Z4dMdN�Z5dOdP�Z6GdQdR�dRe�Z7dS)Xa�
   6  ====================================================
   7  Chebyshev Series (:mod:`numpy.polynomial.chebyshev`)
   8  ====================================================
   9  
  10  This module provides a number of objects (mostly functions) useful for
  11  dealing with Chebyshev series, including a `Chebyshev` class that
  12  encapsulates the usual arithmetic operations.  (General information
  13  on how this module represents and works with such polynomials is in the
  14  docstring for its "parent" sub-package, `numpy.polynomial`).
  15  
  16  Classes
  17  -------
  18  
  19  .. autosummary::
  20     :toctree: generated/
  21  
  22     Chebyshev
  23  
  24  
  25  Constants
  26  ---------
  27  
  28  .. autosummary::
  29     :toctree: generated/
  30  
  31     chebdomain
  32     chebzero
  33     chebone
  34     chebx
  35  
  36  Arithmetic
  37  ----------
  38  
  39  .. autosummary::
  40     :toctree: generated/
  41  
  42     chebadd
  43     chebsub
  44     chebmulx
  45     chebmul
  46     chebdiv
  47     chebpow
  48     chebval
  49     chebval2d
  50     chebval3d
  51     chebgrid2d
  52     chebgrid3d
  53  
  54  Calculus
  55  --------
  56  
  57  .. autosummary::
  58     :toctree: generated/
  59  
  60     chebder
  61     chebint
  62  
  63  Misc Functions
  64  --------------
  65  
  66  .. autosummary::
  67     :toctree: generated/
  68  
  69     chebfromroots
  70     chebroots
  71     chebvander
  72     chebvander2d
  73     chebvander3d
  74     chebgauss
  75     chebweight
  76     chebcompanion
  77     chebfit
  78     chebpts1
  79     chebpts2
  80     chebtrim
  81     chebline
  82     cheb2poly
  83     poly2cheb
  84     chebinterpolate
  85  
  86  See also
  87  --------
  88  `numpy.polynomial`
  89  
  90  Notes
  91  -----
  92  The implementations of multiplication, division, integration, and
  93  differentiation use the algebraic identities [1]_:
  94  
  95  .. math::
  96      T_n(x) = \frac{z^n + z^{-n}}{2} \\
  97      z\frac{dx}{dz} = \frac{z - z^{-1}}{2}.
  98  
  99  where
 100  
 101  .. math:: x = \frac{z + z^{-1}}{2}.
 102  
 103  These identities allow a Chebyshev series to be expressed as a finite,
 104  symmetric Laurent series.  In this module, this sort of Laurent series
 105  is referred to as a "z-series."
 106  
 107  References
 108  ----------
 109  .. [1] A. T. Benjamin, et al., "Combinatorial Trigonometry with Chebyshev
 110    Polynomials," *Journal of Statistical Planning and Inference 14*, 2008
 111    (https://web.archive.org/web/20080221202153/https://www.math.hmc.edu/~benjamin/papers/CombTrig.pdf, pg. 4)
 112  
 113  �N)�normalize_axis_index�)�	polyutils)�ABCPolyBase)"�chebzero�chebone�chebx�
 114  chebdomain�chebline�chebadd�chebsub�chebmulx�chebmul�chebdiv�chebpow�chebval�chebder�chebint�	cheb2poly�	poly2cheb�
chebfromroots�
 115  chebvander�chebfit�chebtrim�	chebroots�chebpts1�chebpts2�	Chebyshev�	chebval2d�	chebval3d�
 116  chebgrid2d�
 117  chebgrid3d�chebvander2d�chebvander3d�
chebcompanion�	chebgauss�
 118  chebweight�chebinterpolatecCsD|j}tjd|d|jd�}|d||dd�<||ddd�S)a�Convert Chebyshev series to z-series.
 119  
 120      Convert a Chebyshev series to the equivalent z-series. The result is
 121      never an empty array. The dtype of the return is the same as that of
 122      the input. No checks are run on the arguments as this routine is for
 123      internal use.
 124  
 125      Parameters
 126      ----------
 127      c : 1-D ndarray
 128          Chebyshev coefficients, ordered from low to high
 129  
 130      Returns
 131      -------
 132      zs : 1-D ndarray
 133          Odd length symmetric z-series, ordered from  low to high.
 134  
 135      �r��dtypeN�����)�size�np�zerosr*)�c�n�zs�r2��C:\Users\Jacks.GUTTSPC\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\numpy\polynomial\chebyshev.py�_cseries_to_zseries�sr4cCs:|jdd}||dd���}|d|�d9<|S)a�Convert z-series to a Chebyshev series.
 136  
 137      Convert a z series to the equivalent Chebyshev series. The result is
 138      never an empty array. The dtype of the return is the same as that of
 139      the input. No checks are run on the arguments as this routine is for
 140      internal use.
 141  
 142      Parameters
 143      ----------
 144      zs : 1-D ndarray
 145          Odd length symmetric z-series, ordered from  low to high.
 146  
 147      Returns
 148      -------
 149      c : 1-D ndarray
 150          Chebyshev coefficients, ordered from  low to high.
 151  
 152      rr(N)r,�copy)r1r0r/r2r2r3�_zseries_to_cseries�sr6cC�t�||�S)a�Multiply two z-series.
 153  
 154      Multiply two z-series to produce a z-series.
 155  
 156      Parameters
 157      ----------
 158      z1, z2 : 1-D ndarray
 159          The arrays must be 1-D but this is not checked.
 160  
 161      Returns
 162      -------
 163      product : 1-D ndarray
 164          The product z-series.
 165  
 166      Notes
 167      -----
 168      This is simply convolution. If symmetric/anti-symmetric z-series are
 169      denoted by S/A then the following rules apply:
 170  
 171      S*S, A*A -> S
 172      S*A, A*S -> A
 173  
 174      )r-�convolve)�z1�z2r2r2r3�_zseries_mul�sr;cCsh|��}|��}t|�}t|�}|dkr"||}||dd�dfS||kr0|dd�d|fS||}|d}||}tj|d|jd�}d}|}||kr�||}	||||<|	|||<|	|}
 175  ||||�|
 176  8<||||�|
 177  8<|d7}|d8}||ksN||}	|	||<|	|}
 178  ||||�|
 179  8<||}||d|d|���}||fS)a�Divide the first z-series by the second.
 180  
 181      Divide `z1` by `z2` and return the quotient and remainder as z-series.
 182      Warning: this implementation only applies when both z1 and z2 have the
 183      same symmetry, which is sufficient for present purposes.
 184  
 185      Parameters
 186      ----------
 187      z1, z2 : 1-D ndarray
 188          The arrays must be 1-D and have the same symmetry, but this is not
 189          checked.
 190  
 191      Returns
 192      -------
 193  
 194      (quotient, remainder) : 1-D ndarrays
 195          Quotient and remainder as z-series.
 196  
 197      Notes
 198      -----
 199      This is not the same as polynomial division on account of the desired form
 200      of the remainder. If symmetric/anti-symmetric z-series are denoted by S/A
 201      then the following rules apply:
 202  
 203      S/S -> S,S
 204      A/A -> S,A
 205  
 206      The restriction to types of the same symmetry could be fixed but seems like
 207      unneeded generality. There is no natural form for the remainder in the case
 208      where there is no symmetry.
 209  
 210      rNrr))r5�lenr-�emptyr*)r9r:�lc1�lc2�dlen�scl�quo�i�j�r�tmp�remr2r2r3�_zseries_div�s@!�	rHcCsLt|�d}tjgd�|jd�}|t�||d�d9}t||�\}}|S)a�Differentiate a z-series.
 211  
 212      The derivative is with respect to x, not z. This is achieved using the
 213      chain rule and the value of dx/dz given in the module notes.
 214  
 215      Parameters
 216      ----------
 217      zs : z-series
 218          The z-series to differentiate.
 219  
 220      Returns
 221      -------
 222      derivative : z-series
 223          The derivative
 224  
 225      Notes
 226      -----
 227      The zseries for x (ns) has been multiplied by two in order to avoid
 228      using floats that are incompatible with Decimal and likely other
 229      specialized scalar types. This scaling has been compensated by
 230      multiplying the value of zs by two also so that the two cancels in the
 231      division.
 232  
 233      r(�r+rrr)r)r<r-�arrayr*�arangerH)r1r0�ns�drEr2r2r3�_zseries_ders
 234  rNcCs�dt|�d}tjgd�|jd�}t||�}t�||d�d}|d|�|d|�<||dd�||dd�<d||<|S)aMIntegrate a z-series.
 235  
 236      The integral is with respect to x, not z. This is achieved by a change
 237      of variable using dx/dz given in the module notes.
 238  
 239      Parameters
 240      ----------
 241      zs : z-series
 242          The z-series to integrate
 243  
 244      Returns
 245      -------
 246      integral : z-series
 247          The indefinite integral
 248  
 249      Notes
 250      -----
 251      The zseries for x (ns) has been multiplied by two in order to avoid
 252      using floats that are incompatible with Decimal and likely other
 253      specialized scalar types. This scaling has been compensated by
 254      dividing the resulting zs by two.
 255  
 256      rr(rIr)Nr)r<r-rJr*r;rK)r1r0rL�divr2r2r3�_zseries_int5s
 257  $rPcCsFt�|g�\}t|�d}d}t|dd�D]}tt|�||�}q|S)aa
 258      Convert a polynomial to a Chebyshev series.
 259  
 260      Convert an array representing the coefficients of a polynomial (relative
 261      to the "standard" basis) ordered from lowest degree to highest, to an
 262      array of the coefficients of the equivalent Chebyshev series, ordered
 263      from lowest to highest degree.
 264  
 265      Parameters
 266      ----------
 267      pol : array_like
 268          1-D array containing the polynomial coefficients
 269  
 270      Returns
 271      -------
 272      c : ndarray
 273          1-D array containing the coefficients of the equivalent Chebyshev
 274          series.
 275  
 276      See Also
 277      --------
 278      cheb2poly
 279  
 280      Notes
 281      -----
 282      The easy way to do conversions between polynomial basis sets
 283      is to use the convert method of a class instance.
 284  
 285      Examples
 286      --------
 287      >>> from numpy import polynomial as P
 288      >>> p = P.Polynomial(range(4))
 289      >>> p
 290      Polynomial([0., 1., 2., 3.], domain=[-1,  1], window=[-1,  1])
 291      >>> c = p.convert(kind=P.Chebyshev)
 292      >>> c
 293      Chebyshev([1.  , 3.25, 1.  , 0.75], domain=[-1.,  1.], window=[-1.,  1.])
 294      >>> P.chebyshev.poly2cheb(range(4))
 295      array([1.  , 3.25, 1.  , 0.75])
 296  
 297      rrr+)�pu�	as_seriesr<�rangerr
)�pol�deg�resrCr2r2r3r[s*rc	Cs�ddlm}m}m}t�|g�\}t|�}|dkr|S|d}|d}t|ddd�D]}|}|||d|�}||||�d�}q+||||��S)a�
 298      Convert a Chebyshev series to a polynomial.
 299  
 300      Convert an array representing the coefficients of a Chebyshev series,
 301      ordered from lowest degree to highest, to an array of the coefficients
 302      of the equivalent polynomial (relative to the "standard" basis) ordered
 303      from lowest to highest degree.
 304  
 305      Parameters
 306      ----------
 307      c : array_like
 308          1-D array containing the Chebyshev series coefficients, ordered
 309          from lowest order term to highest.
 310  
 311      Returns
 312      -------
 313      pol : ndarray
 314          1-D array containing the coefficients of the equivalent polynomial
 315          (relative to the "standard" basis) ordered from lowest order term
 316          to highest.
 317  
 318      See Also
 319      --------
 320      poly2cheb
 321  
 322      Notes
 323      -----
 324      The easy way to do conversions between polynomial basis sets
 325      is to use the convert method of a class instance.
 326  
 327      Examples
 328      --------
 329      >>> from numpy import polynomial as P
 330      >>> c = P.Chebyshev(range(4))
 331      >>> c
 332      Chebyshev([0., 1., 2., 3.], domain=[-1,  1], window=[-1,  1])
 333      >>> p = c.convert(kind=P.Polynomial)
 334      >>> p
 335      Polynomial([-2., -8.,  4., 12.], domain=[-1.,  1.], window=[-1.,  1.])
 336      >>> P.chebyshev.cheb2poly(range(4))
 337      array([-2.,  -8.,   4.,  12.])
 338  
 339      r)�polyadd�polysub�polymulx������r+r()�
 340  polynomialrWrXrYrQrRr<rS)	r/rWrXrYr0�c0�c1rCrFr2r2r3r�s,rr+cCs"|dkrt�||g�St�|g�S)a�
 341      Chebyshev series whose graph is a straight line.
 342  
 343      Parameters
 344      ----------
 345      off, scl : scalars
 346          The specified line is given by ``off + scl*x``.
 347  
 348      Returns
 349      -------
 350      y : ndarray
 351          This module's representation of the Chebyshev series for
 352          ``off + scl*x``.
 353  
 354      See Also
 355      --------
 356      numpy.polynomial.polynomial.polyline
 357      numpy.polynomial.legendre.legline
 358      numpy.polynomial.laguerre.lagline
 359      numpy.polynomial.hermite.hermline
 360      numpy.polynomial.hermite_e.hermeline
 361  
 362      Examples
 363      --------
 364      >>> import numpy.polynomial.chebyshev as C
 365      >>> C.chebline(3,2)
 366      array([3, 2])
 367      >>> C.chebval(-3, C.chebline(3,2)) # should be -3
 368      -3.0
 369  
 370      r)r-rJ)�offrAr2r2r3r
 371  �s r
 372  cCst�tt|�S)a�
 373      Generate a Chebyshev series with given roots.
 374  
 375      The function returns the coefficients of the polynomial
 376  
 377      .. math:: p(x) = (x - r_0) * (x - r_1) * ... * (x - r_n),
 378  
 379      in Chebyshev form, where the `r_n` are the roots specified in `roots`.
 380      If a zero has multiplicity n, then it must appear in `roots` n times.
 381      For instance, if 2 is a root of multiplicity three and 3 is a root of
 382      multiplicity 2, then `roots` looks something like [2, 2, 2, 3, 3]. The
 383      roots can appear in any order.
 384  
 385      If the returned coefficients are `c`, then
 386  
 387      .. math:: p(x) = c_0 + c_1 * T_1(x) + ... +  c_n * T_n(x)
 388  
 389      The coefficient of the last term is not generally 1 for monic
 390      polynomials in Chebyshev form.
 391  
 392      Parameters
 393      ----------
 394      roots : array_like
 395          Sequence containing the roots.
 396  
 397      Returns
 398      -------
 399      out : ndarray
 400          1-D array of coefficients.  If all roots are real then `out` is a
 401          real array, if some of the roots are complex, then `out` is complex
 402          even if all the coefficients in the result are real (see Examples
 403          below).
 404  
 405      See Also
 406      --------
 407      numpy.polynomial.polynomial.polyfromroots
 408      numpy.polynomial.legendre.legfromroots
 409      numpy.polynomial.laguerre.lagfromroots
 410      numpy.polynomial.hermite.hermfromroots
 411      numpy.polynomial.hermite_e.hermefromroots
 412  
 413      Examples
 414      --------
 415      >>> import numpy.polynomial.chebyshev as C
 416      >>> C.chebfromroots((-1,0,1)) # x^3 - x relative to the standard basis
 417      array([ 0.  , -0.25,  0.  ,  0.25])
 418      >>> j = complex(0,1)
 419      >>> C.chebfromroots((-j,j)) # x^2 + 1 relative to the standard basis
 420      array([1.5+0.j, 0. +0.j, 0.5+0.j])
 421  
 422      )rQ�
 423  _fromrootsr
 424  r)�rootsr2r2r3rs4rcCr7)a
 425      Add one Chebyshev series to another.
 426  
 427      Returns the sum of two Chebyshev series `c1` + `c2`.  The arguments
 428      are sequences of coefficients ordered from lowest order term to
 429      highest, i.e., [1,2,3] represents the series ``T_0 + 2*T_1 + 3*T_2``.
 430  
 431      Parameters
 432      ----------
 433      c1, c2 : array_like
 434          1-D arrays of Chebyshev series coefficients ordered from low to
 435          high.
 436  
 437      Returns
 438      -------
 439      out : ndarray
 440          Array representing the Chebyshev series of their sum.
 441  
 442      See Also
 443      --------
 444      chebsub, chebmulx, chebmul, chebdiv, chebpow
 445  
 446      Notes
 447      -----
 448      Unlike multiplication, division, etc., the sum of two Chebyshev series
 449      is a Chebyshev series (without having to "reproject" the result onto
 450      the basis set) so addition, just like that of "standard" polynomials,
 451      is simply "component-wise."
 452  
 453      Examples
 454      --------
 455      >>> from numpy.polynomial import chebyshev as C
 456      >>> c1 = (1,2,3)
 457      >>> c2 = (3,2,1)
 458      >>> C.chebadd(c1,c2)
 459      array([4., 4., 4.])
 460  
 461      )rQ�_add�r^�c2r2r2r3r9s'rcCr7)a`
 462      Subtract one Chebyshev series from another.
 463  
 464      Returns the difference of two Chebyshev series `c1` - `c2`.  The
 465      sequences of coefficients are from lowest order term to highest, i.e.,
 466      [1,2,3] represents the series ``T_0 + 2*T_1 + 3*T_2``.
 467  
 468      Parameters
 469      ----------
 470      c1, c2 : array_like
 471          1-D arrays of Chebyshev series coefficients ordered from low to
 472          high.
 473  
 474      Returns
 475      -------
 476      out : ndarray
 477          Of Chebyshev series coefficients representing their difference.
 478  
 479      See Also
 480      --------
 481      chebadd, chebmulx, chebmul, chebdiv, chebpow
 482  
 483      Notes
 484      -----
 485      Unlike multiplication, division, etc., the difference of two Chebyshev
 486      series is a Chebyshev series (without having to "reproject" the result
 487      onto the basis set) so subtraction, just like that of "standard"
 488      polynomials, is simply "component-wise."
 489  
 490      Examples
 491      --------
 492      >>> from numpy.polynomial import chebyshev as C
 493      >>> c1 = (1,2,3)
 494      >>> c2 = (3,2,1)
 495      >>> C.chebsub(c1,c2)
 496      array([-2.,  0.,  2.])
 497      >>> C.chebsub(c2,c1) # -C.chebsub(c1,c2)
 498      array([ 2.,  0., -2.])
 499  
 500      )rQ�_subrcr2r2r3rcs)rcCs�t�|g�\}t|�dkr|ddkr|Stjt|�d|jd�}|dd|d<|d|d<t|�dkrM|dd�d}||dd�<|dd�|7<|S)a$Multiply a Chebyshev series by x.
 501  
 502      Multiply the polynomial `c` by x, where x is the independent
 503      variable.
 504  
 505  
 506      Parameters
 507      ----------
 508      c : array_like
 509          1-D array of Chebyshev series coefficients ordered from low to
 510          high.
 511  
 512      Returns
 513      -------
 514      out : ndarray
 515          Array representing the result of the multiplication.
 516  
 517      Notes
 518      -----
 519  
 520      .. versionadded:: 1.5.0
 521  
 522      Examples
 523      --------
 524      >>> from numpy.polynomial import chebyshev as C
 525      >>> C.chebmulx([1,2,3])
 526      array([1. , 2.5, 1. , 1.5])
 527  
 528      rrr)Nr(r[)rQrRr<r-r=r*)r/�prdrFr2r2r3r
�sr
cCs>t�||g�\}}t|�}t|�}t||�}t|�}t�|�S)a�
 529      Multiply one Chebyshev series by another.
 530  
 531      Returns the product of two Chebyshev series `c1` * `c2`.  The arguments
 532      are sequences of coefficients, from lowest order "term" to highest,
 533      e.g., [1,2,3] represents the series ``T_0 + 2*T_1 + 3*T_2``.
 534  
 535      Parameters
 536      ----------
 537      c1, c2 : array_like
 538          1-D arrays of Chebyshev series coefficients ordered from low to
 539          high.
 540  
 541      Returns
 542      -------
 543      out : ndarray
 544          Of Chebyshev series coefficients representing their product.
 545  
 546      See Also
 547      --------
 548      chebadd, chebsub, chebmulx, chebdiv, chebpow
 549  
 550      Notes
 551      -----
 552      In general, the (polynomial) product of two C-series results in terms
 553      that are not in the Chebyshev polynomial basis set.  Thus, to express
 554      the product as a C-series, it is typically necessary to "reproject"
 555      the product onto said basis set, which typically produces
 556      "unintuitive live" (but correct) results; see Examples section below.
 557  
 558      Examples
 559      --------
 560      >>> from numpy.polynomial import chebyshev as C
 561      >>> c1 = (1,2,3)
 562      >>> c2 = (3,2,1)
 563      >>> C.chebmul(c1,c2) # multiplication requires "reprojection"
 564      array([  6.5,  12. ,  12. ,   4. ,   1.5])
 565  
 566      )rQrRr4r;r6�trimseq)r^rdr9r:rf�retr2r2r3r�s)
 567  
 568  rcCs�t�||g�\}}|ddkrt��t|�}t|�}||kr(|dd�d|fS|dkr:||d|dd�dfSt|�}t|�}t||�\}}t�t|��}t�t|��}||fS)ah
 569      Divide one Chebyshev series by another.
 570  
 571      Returns the quotient-with-remainder of two Chebyshev series
 572      `c1` / `c2`.  The arguments are sequences of coefficients from lowest
 573      order "term" to highest, e.g., [1,2,3] represents the series
 574      ``T_0 + 2*T_1 + 3*T_2``.
 575  
 576      Parameters
 577      ----------
 578      c1, c2 : array_like
 579          1-D arrays of Chebyshev series coefficients ordered from low to
 580          high.
 581  
 582      Returns
 583      -------
 584      [quo, rem] : ndarrays
 585          Of Chebyshev series coefficients representing the quotient and
 586          remainder.
 587  
 588      See Also
 589      --------
 590      chebadd, chebsub, chebmulx, chebmul, chebpow
 591  
 592      Notes
 593      -----
 594      In general, the (polynomial) division of one C-series by another
 595      results in quotient and remainder terms that are not in the Chebyshev
 596      polynomial basis set.  Thus, to express these results as C-series, it
 597      is typically necessary to "reproject" the results onto said basis
 598      set, which typically produces "unintuitive" (but correct) results;
 599      see Examples section below.
 600  
 601      Examples
 602      --------
 603      >>> from numpy.polynomial import chebyshev as C
 604      >>> c1 = (1,2,3)
 605      >>> c2 = (3,2,1)
 606      >>> C.chebdiv(c1,c2) # quotient "intuitive," remainder not
 607      (array([3.]), array([-8., -4.]))
 608      >>> c2 = (0,1,2,3)
 609      >>> C.chebdiv(c2,c1) # neither "intuitive"
 610      (array([0., 2.]), array([-2., -4.]))
 611  
 612      r+rNr)rQrR�ZeroDivisionErrorr<r4rHrgr6)r^rdr>r?r9r:rBrGr2r2r3r�s/r�cCs�t�|g�\}t|�}||ks|dkrtd��|dur#||kr#td��|dkr0tjdg|jd�S|dkr6|St|�}|}td|d�D]}t�	||�}qCt
 613  |�S)a�Raise a Chebyshev series to a power.
 614  
 615      Returns the Chebyshev series `c` raised to the power `pow`. The
 616      argument `c` is a sequence of coefficients ordered from low to high.
 617      i.e., [1,2,3] is the series  ``T_0 + 2*T_1 + 3*T_2.``
 618  
 619      Parameters
 620      ----------
 621      c : array_like
 622          1-D array of Chebyshev series coefficients ordered from low to
 623          high.
 624      pow : integer
 625          Power to which the series will be raised
 626      maxpower : integer, optional
 627          Maximum power allowed. This is mainly to limit growth of the series
 628          to unmanageable size. Default is 16
 629  
 630      Returns
 631      -------
 632      coef : ndarray
 633          Chebyshev series of power.
 634  
 635      See Also
 636      --------
 637      chebadd, chebsub, chebmulx, chebmul, chebdiv
 638  
 639      Examples
 640      --------
 641      >>> from numpy.polynomial import chebyshev as C
 642      >>> C.chebpow([1, 2, 3, 4], 2)
 643      array([15.5, 22. , 16. , ..., 12.5, 12. ,  8. ])
 644  
 645      rz%Power must be a non-negative integer.NzPower is too largerr)r()rQrR�int�
 646  ValueErrorr-rJr*r4rSr8r6)r/�pow�maxpower�powerr1rfrCr2r2r3r1s&rc
 647  Cs^tj|ddd�}|jjdvr|�tj�}t�|d�}t�|d�}|dkr(td��t	||j
 648  �}|dkr4|St�||d�}t|�}||krL|d	d�d}nZt
|�D]U}|d}||9}tj|f|jdd	�|jd
 649  �}t
|dd�D] }	d|	||	||	d<||	d|	||	|	d7<qp|dkr�d
|d|d<|d|d<|}qPt�|d|�}|S)a�
 650      Differentiate a Chebyshev series.
 651  
 652      Returns the Chebyshev series coefficients `c` differentiated `m` times
 653      along `axis`.  At each iteration the result is multiplied by `scl` (the
 654      scaling factor is for use in a linear change of variable). The argument
 655      `c` is an array of coefficients from low to high degree along each
 656      axis, e.g., [1,2,3] represents the series ``1*T_0 + 2*T_1 + 3*T_2``
 657      while [[1,2],[1,2]] represents ``1*T_0(x)*T_0(y) + 1*T_1(x)*T_0(y) +
 658      2*T_0(x)*T_1(y) + 2*T_1(x)*T_1(y)`` if axis=0 is ``x`` and axis=1 is
 659      ``y``.
 660  
 661      Parameters
 662      ----------
 663      c : array_like
 664          Array of Chebyshev series coefficients. If c is multidimensional
 665          the different axis correspond to different variables with the
 666          degree in each axis given by the corresponding index.
 667      m : int, optional
 668          Number of derivatives taken, must be non-negative. (Default: 1)
 669      scl : scalar, optional
 670          Each differentiation is multiplied by `scl`.  The end result is
 671          multiplication by ``scl**m``.  This is for use in a linear change of
 672          variable. (Default: 1)
 673      axis : int, optional
 674          Axis over which the derivative is taken. (Default: 0).
 675  
 676          .. versionadded:: 1.7.0
 677  
 678      Returns
 679      -------
 680      der : ndarray
 681          Chebyshev series of the derivative.
 682  
 683      See Also
 684      --------
 685      chebint
 686  
 687      Notes
 688      -----
 689      In general, the result of differentiating a C-series needs to be
 690      "reprojected" onto the C-series basis set. Thus, typically, the
 691      result of this function is "unintuitive," albeit correct; see Examples
 692      section below.
 693  
 694      Examples
 695      --------
 696      >>> from numpy.polynomial import chebyshev as C
 697      >>> c = (1,2,3,4)
 698      >>> C.chebder(c)
 699      array([14., 12., 24.])
 700      >>> C.chebder(c,3)
 701      array([96.])
 702      >>> C.chebder(c,scl=-1)
 703      array([-14., -12., -24.])
 704      >>> C.chebder(c,2,-1)
 705      array([12.,  96.])
 706  
 707      rT��ndminr5�
?bBhHiIlLqQpPzthe order of derivation�the axisrz,The order of derivation must be non-negativeNr)r(r+�)r-rJr*�char�astype�doublerQ�_deprecate_as_intrlr�ndim�moveaxisr<rSr=�shape)
 708  r/�mrA�axis�cnt�iaxisr0rC�derrDr2r2r3rks6< &rc	Cs
 709  tj|ddd�}|jjdvr|�tj�}t�|�s|g}t�|d�}t�|d�}|dkr0t	d��t
 710  |�|kr:t	d	��t�|�dkrEt	d
 711  ��t�|�dkrPt	d��t||j�}|dkr\|St�
||d�}t|�dg|t
 712  |�}t|�D]�}t
 713  |�}	||9}|	dkr�t�|ddk�r�|d||7<qttj|	df|jdd�|jd
�}
 714  |dd|
 715  d<|d|
 716  d<|	dkr�|dd|
 717  d<td|	�D]"}||d|d|
 718  |d<|
 719  |d||d|d8<q�|
 720  d||t||
 721  �7<|
 722  }qtt�
|d|�}|S)a�
 723      Integrate a Chebyshev series.
 724  
 725      Returns the Chebyshev series coefficients `c` integrated `m` times from
 726      `lbnd` along `axis`. At each iteration the resulting series is
 727      **multiplied** by `scl` and an integration constant, `k`, is added.
 728      The scaling factor is for use in a linear change of variable.  ("Buyer
 729      beware": note that, depending on what one is doing, one may want `scl`
 730      to be the reciprocal of what one might expect; for more information,
 731      see the Notes section below.)  The argument `c` is an array of
 732      coefficients from low to high degree along each axis, e.g., [1,2,3]
 733      represents the series ``T_0 + 2*T_1 + 3*T_2`` while [[1,2],[1,2]]
 734      represents ``1*T_0(x)*T_0(y) + 1*T_1(x)*T_0(y) + 2*T_0(x)*T_1(y) +
 735      2*T_1(x)*T_1(y)`` if axis=0 is ``x`` and axis=1 is ``y``.
 736  
 737      Parameters
 738      ----------
 739      c : array_like
 740          Array of Chebyshev series coefficients. If c is multidimensional
 741          the different axis correspond to different variables with the
 742          degree in each axis given by the corresponding index.
 743      m : int, optional
 744          Order of integration, must be positive. (Default: 1)
 745      k : {[], list, scalar}, optional
 746          Integration constant(s).  The value of the first integral at zero
 747          is the first value in the list, the value of the second integral
 748          at zero is the second value, etc.  If ``k == []`` (the default),
 749          all constants are set to zero.  If ``m == 1``, a single scalar can
 750          be given instead of a list.
 751      lbnd : scalar, optional
 752          The lower bound of the integral. (Default: 0)
 753      scl : scalar, optional
 754          Following each integration the result is *multiplied* by `scl`
 755          before the integration constant is added. (Default: 1)
 756      axis : int, optional
 757          Axis over which the integral is taken. (Default: 0).
 758  
 759          .. versionadded:: 1.7.0
 760  
 761      Returns
 762      -------
 763      S : ndarray
 764          C-series coefficients of the integral.
 765  
 766      Raises
 767      ------
 768      ValueError
 769          If ``m < 1``, ``len(k) > m``, ``np.ndim(lbnd) != 0``, or
 770          ``np.ndim(scl) != 0``.
 771  
 772      See Also
 773      --------
 774      chebder
 775  
 776      Notes
 777      -----
 778      Note that the result of each integration is *multiplied* by `scl`.
 779      Why is this important to note?  Say one is making a linear change of
 780      variable :math:`u = ax + b` in an integral relative to `x`.  Then
 781      :math:`dx = du/a`, so one will need to set `scl` equal to
 782      :math:`1/a`- perhaps not what one would have first thought.
 783  
 784      Also note that, in general, the result of integrating a C-series needs
 785      to be "reprojected" onto the C-series basis set.  Thus, typically,
 786      the result of this function is "unintuitive," albeit correct; see
 787      Examples section below.
 788  
 789      Examples
 790      --------
 791      >>> from numpy.polynomial import chebyshev as C
 792      >>> c = (1,2,3)
 793      >>> C.chebint(c)
 794      array([ 0.5, -0.5,  0.5,  0.5])
 795      >>> C.chebint(c,3)
 796      array([ 0.03125   , -0.1875    ,  0.04166667, -0.05208333,  0.01041667, # may vary
 797          0.00625   ])
 798      >>> C.chebint(c, k=3)
 799      array([ 3.5, -0.5,  0.5,  0.5])
 800      >>> C.chebint(c,lbnd=-2)
 801      array([ 8.5, -0.5,  0.5,  0.5])
 802      >>> C.chebint(c,scl=-2)
 803      array([-1.,  1., -1., -1.])
 804  
 805      rTrprrzthe order of integrationrsrz-The order of integration must be non-negativezToo many integration constantszlbnd must be a scalar.zscl must be a scalar.Nr)rtr()r-rJr*rurvrw�iterablerQrxrlr<ryrrz�listrS�allr=r{r)r/r|�k�lbndrAr}r~rrCr0rFrDr2r2r3r�sJU
 806  $&rTcCs�tj|ddd�}|jjdvr|�tj�}t|ttf�r t�	|�}t|tj
 807  �r3|r3|�|jd|j
�}t|�dkr@|d}d}n6t|�dkrO|d}|d}n'd|}|d}|d	}td
 808  t|�d�D]}|}|||}|||}qd|||S)aL	
 809      Evaluate a Chebyshev series at points x.
 810  
 811      If `c` is of length `n + 1`, this function returns the value:
 812  
 813      .. math:: p(x) = c_0 * T_0(x) + c_1 * T_1(x) + ... + c_n * T_n(x)
 814  
 815      The parameter `x` is converted to an array only if it is a tuple or a
 816      list, otherwise it is treated as a scalar. In either case, either `x`
 817      or its elements must support multiplication and addition both with
 818      themselves and with the elements of `c`.
 819  
 820      If `c` is a 1-D array, then `p(x)` will have the same shape as `x`.  If
 821      `c` is multidimensional, then the shape of the result depends on the
 822      value of `tensor`. If `tensor` is true the shape will be c.shape[1:] +
 823      x.shape. If `tensor` is false the shape will be c.shape[1:]. Note that
 824      scalars have shape (,).
 825  
 826      Trailing zeros in the coefficients will be used in the evaluation, so
 827      they should be avoided if efficiency is a concern.
 828  
 829      Parameters
 830      ----------
 831      x : array_like, compatible object
 832          If `x` is a list or tuple, it is converted to an ndarray, otherwise
 833          it is left unchanged and treated as a scalar. In either case, `x`
 834          or its elements must support addition and multiplication with
 835          themselves and with the elements of `c`.
 836      c : array_like
 837          Array of coefficients ordered so that the coefficients for terms of
 838          degree n are contained in c[n]. If `c` is multidimensional the
 839          remaining indices enumerate multiple polynomials. In the two
 840          dimensional case the coefficients may be thought of as stored in
 841          the columns of `c`.
 842      tensor : boolean, optional
 843          If True, the shape of the coefficient array is extended with ones
 844          on the right, one for each dimension of `x`. Scalars have dimension 0
 845          for this action. The result is that every column of coefficients in
 846          `c` is evaluated for every element of `x`. If False, `x` is broadcast
 847          over the columns of `c` for the evaluation.  This keyword is useful
 848          when `c` is multidimensional. The default value is True.
 849  
 850          .. versionadded:: 1.7.0
 851  
 852      Returns
 853      -------
 854      values : ndarray, algebra_like
 855          The shape of the return value is described above.
 856  
 857      See Also
 858      --------
 859      chebval2d, chebgrid2d, chebval3d, chebgrid3d
 860  
 861      Notes
 862      -----
 863      The evaluation uses Clenshaw recursion, aka synthetic division.
 864  
 865      rTrprr)rrr(r[r+rZ)r-rJr*rurvrw�
 866  isinstance�tupler��asarray�ndarray�reshaper{ryr<rS)�xr/�tensorr]r^�x2rCrFr2r2r3rFs*;
 867  
 868  rcC�t�t|||�S)aH
 869      Evaluate a 2-D Chebyshev series at points (x, y).
 870  
 871      This function returns the values:
 872  
 873      .. math:: p(x,y) = \sum_{i,j} c_{i,j} * T_i(x) * T_j(y)
 874  
 875      The parameters `x` and `y` are converted to arrays only if they are
 876      tuples or a lists, otherwise they are treated as a scalars and they
 877      must have the same shape after conversion. In either case, either `x`
 878      and `y` or their elements must support multiplication and addition both
 879      with themselves and with the elements of `c`.
 880  
 881      If `c` is a 1-D array a one is implicitly appended to its shape to make
 882      it 2-D. The shape of the result will be c.shape[2:] + x.shape.
 883  
 884      Parameters
 885      ----------
 886      x, y : array_like, compatible objects
 887          The two dimensional series is evaluated at the points `(x, y)`,
 888          where `x` and `y` must have the same shape. If `x` or `y` is a list
 889          or tuple, it is first converted to an ndarray, otherwise it is left
 890          unchanged and if it isn't an ndarray it is treated as a scalar.
 891      c : array_like
 892          Array of coefficients ordered so that the coefficient of the term
 893          of multi-degree i,j is contained in ``c[i,j]``. If `c` has
 894          dimension greater than 2 the remaining indices enumerate multiple
 895          sets of coefficients.
 896  
 897      Returns
 898      -------
 899      values : ndarray, compatible object
 900          The values of the two dimensional Chebyshev series at points formed
 901          from pairs of corresponding values from `x` and `y`.
 902  
 903      See Also
 904      --------
 905      chebval, chebgrid2d, chebval3d, chebgrid3d
 906  
 907      Notes
 908      -----
 909  
 910      .. versionadded:: 1.7.0
 911  
 912      �rQ�_valndr�r��yr/r2r2r3r�s.rcCr�)a�
 913      Evaluate a 2-D Chebyshev series on the Cartesian product of x and y.
 914  
 915      This function returns the values:
 916  
 917      .. math:: p(a,b) = \sum_{i,j} c_{i,j} * T_i(a) * T_j(b),
 918  
 919      where the points `(a, b)` consist of all pairs formed by taking
 920      `a` from `x` and `b` from `y`. The resulting points form a grid with
 921      `x` in the first dimension and `y` in the second.
 922  
 923      The parameters `x` and `y` are converted to arrays only if they are
 924      tuples or a lists, otherwise they are treated as a scalars. In either
 925      case, either `x` and `y` or their elements must support multiplication
 926      and addition both with themselves and with the elements of `c`.
 927  
 928      If `c` has fewer than two dimensions, ones are implicitly appended to
 929      its shape to make it 2-D. The shape of the result will be c.shape[2:] +
 930      x.shape + y.shape.
 931  
 932      Parameters
 933      ----------
 934      x, y : array_like, compatible objects
 935          The two dimensional series is evaluated at the points in the
 936          Cartesian product of `x` and `y`.  If `x` or `y` is a list or
 937          tuple, it is first converted to an ndarray, otherwise it is left
 938          unchanged and, if it isn't an ndarray, it is treated as a scalar.
 939      c : array_like
 940          Array of coefficients ordered so that the coefficient of the term of
 941          multi-degree i,j is contained in `c[i,j]`. If `c` has dimension
 942          greater than two the remaining indices enumerate multiple sets of
 943          coefficients.
 944  
 945      Returns
 946      -------
 947      values : ndarray, compatible object
 948          The values of the two dimensional Chebyshev series at points in the
 949          Cartesian product of `x` and `y`.
 950  
 951      See Also
 952      --------
 953      chebval, chebval2d, chebval3d, chebgrid3d
 954  
 955      Notes
 956      -----
 957  
 958      .. versionadded:: 1.7.0
 959  
 960      �rQ�_gridndrr�r2r2r3r �s2r cC�t�t||||�S)a�
 961      Evaluate a 3-D Chebyshev series at points (x, y, z).
 962  
 963      This function returns the values:
 964  
 965      .. math:: p(x,y,z) = \sum_{i,j,k} c_{i,j,k} * T_i(x) * T_j(y) * T_k(z)
 966  
 967      The parameters `x`, `y`, and `z` are converted to arrays only if
 968      they are tuples or a lists, otherwise they are treated as a scalars and
 969      they must have the same shape after conversion. In either case, either
 970      `x`, `y`, and `z` or their elements must support multiplication and
 971      addition both with themselves and with the elements of `c`.
 972  
 973      If `c` has fewer than 3 dimensions, ones are implicitly appended to its
 974      shape to make it 3-D. The shape of the result will be c.shape[3:] +
 975      x.shape.
 976  
 977      Parameters
 978      ----------
 979      x, y, z : array_like, compatible object
 980          The three dimensional series is evaluated at the points
 981          `(x, y, z)`, where `x`, `y`, and `z` must have the same shape.  If
 982          any of `x`, `y`, or `z` is a list or tuple, it is first converted
 983          to an ndarray, otherwise it is left unchanged and if it isn't an
 984          ndarray it is  treated as a scalar.
 985      c : array_like
 986          Array of coefficients ordered so that the coefficient of the term of
 987          multi-degree i,j,k is contained in ``c[i,j,k]``. If `c` has dimension
 988          greater than 3 the remaining indices enumerate multiple sets of
 989          coefficients.
 990  
 991      Returns
 992      -------
 993      values : ndarray, compatible object
 994          The values of the multidimensional polynomial on points formed with
 995          triples of corresponding values from `x`, `y`, and `z`.
 996  
 997      See Also
 998      --------
 999      chebval, chebval2d, chebgrid2d, chebgrid3d
1000  
1001      Notes
1002      -----
1003  
1004      .. versionadded:: 1.7.0
1005  
1006      r��r�r��zr/r2r2r3rs0rcCr�)aP
1007      Evaluate a 3-D Chebyshev series on the Cartesian product of x, y, and z.
1008  
1009      This function returns the values:
1010  
1011      .. math:: p(a,b,c) = \sum_{i,j,k} c_{i,j,k} * T_i(a) * T_j(b) * T_k(c)
1012  
1013      where the points `(a, b, c)` consist of all triples formed by taking
1014      `a` from `x`, `b` from `y`, and `c` from `z`. The resulting points form
1015      a grid with `x` in the first dimension, `y` in the second, and `z` in
1016      the third.
1017  
1018      The parameters `x`, `y`, and `z` are converted to arrays only if they
1019      are tuples or a lists, otherwise they are treated as a scalars. In
1020      either case, either `x`, `y`, and `z` or their elements must support
1021      multiplication and addition both with themselves and with the elements
1022      of `c`.
1023  
1024      If `c` has fewer than three dimensions, ones are implicitly appended to
1025      its shape to make it 3-D. The shape of the result will be c.shape[3:] +
1026      x.shape + y.shape + z.shape.
1027  
1028      Parameters
1029      ----------
1030      x, y, z : array_like, compatible objects
1031          The three dimensional series is evaluated at the points in the
1032          Cartesian product of `x`, `y`, and `z`.  If `x`,`y`, or `z` is a
1033          list or tuple, it is first converted to an ndarray, otherwise it is
1034          left unchanged and, if it isn't an ndarray, it is treated as a
1035          scalar.
1036      c : array_like
1037          Array of coefficients ordered so that the coefficients for terms of
1038          degree i,j are contained in ``c[i,j]``. If `c` has dimension
1039          greater than two the remaining indices enumerate multiple sets of
1040          coefficients.
1041  
1042      Returns
1043      -------
1044      values : ndarray, compatible object
1045          The values of the two dimensional polynomial at points in the Cartesian
1046          product of `x` and `y`.
1047  
1048      See Also
1049      --------
1050      chebval, chebval2d, chebgrid2d, chebval3d
1051  
1052      Notes
1053      -----
1054  
1055      .. versionadded:: 1.7.0
1056  
1057      r�r�r2r2r3r!3s5r!cCs�t�|d�}|dkrtd��tj|ddd�d}|df|j}|j}tj||d�}|dd|d<|dkrXd	|}||d<td	|d�D]}||d|||d	||<qEt�	|dd
1058  �S)aPseudo-Vandermonde matrix of given degree.
1059  
1060      Returns the pseudo-Vandermonde matrix of degree `deg` and sample points
1061      `x`. The pseudo-Vandermonde matrix is defined by
1062  
1063      .. math:: V[..., i] = T_i(x),
1064  
1065      where `0 <= i <= deg`. The leading indices of `V` index the elements of
1066      `x` and the last index is the degree of the Chebyshev polynomial.
1067  
1068      If `c` is a 1-D array of coefficients of length `n + 1` and `V` is the
1069      matrix ``V = chebvander(x, n)``, then ``np.dot(V, c)`` and
1070      ``chebval(x, c)`` are the same up to roundoff.  This equivalence is
1071      useful both for least squares fitting and for the evaluation of a large
1072      number of Chebyshev series of the same degree and sample points.
1073  
1074      Parameters
1075      ----------
1076      x : array_like
1077          Array of points. The dtype is converted to float64 or complex128
1078          depending on whether any of the elements are complex. If `x` is
1079          scalar it is converted to a 1-D array.
1080      deg : int
1081          Degree of the resulting matrix.
1082  
1083      Returns
1084      -------
1085      vander : ndarray
1086          The pseudo Vandermonde matrix. The shape of the returned matrix is
1087          ``x.shape + (deg + 1,)``, where The last index is the degree of the
1088          corresponding Chebyshev polynomial.  The dtype will be the same as
1089          the converted `x`.
1090  
1091      rUrzdeg must be non-negativeFr)r5rqgr)r(r+)
1092  rQrxrlr-rJr{r*r=rSrz)r�rU�ideg�dims�dtyp�vr�rCr2r2r3rks#"rcCst�ttf||f|�S)a�Pseudo-Vandermonde matrix of given degrees.
1093  
1094      Returns the pseudo-Vandermonde matrix of degrees `deg` and sample
1095      points `(x, y)`. The pseudo-Vandermonde matrix is defined by
1096  
1097      .. math:: V[..., (deg[1] + 1)*i + j] = T_i(x) * T_j(y),
1098  
1099      where `0 <= i <= deg[0]` and `0 <= j <= deg[1]`. The leading indices of
1100      `V` index the points `(x, y)` and the last index encodes the degrees of
1101      the Chebyshev polynomials.
1102  
1103      If ``V = chebvander2d(x, y, [xdeg, ydeg])``, then the columns of `V`
1104      correspond to the elements of a 2-D coefficient array `c` of shape
1105      (xdeg + 1, ydeg + 1) in the order
1106  
1107      .. math:: c_{00}, c_{01}, c_{02} ... , c_{10}, c_{11}, c_{12} ...
1108  
1109      and ``np.dot(V, c.flat)`` and ``chebval2d(x, y, c)`` will be the same
1110      up to roundoff. This equivalence is useful both for least squares
1111      fitting and for the evaluation of a large number of 2-D Chebyshev
1112      series of the same degrees and sample points.
1113  
1114      Parameters
1115      ----------
1116      x, y : array_like
1117          Arrays of point coordinates, all of the same shape. The dtypes
1118          will be converted to either float64 or complex128 depending on
1119          whether any of the elements are complex. Scalars are converted to
1120          1-D arrays.
1121      deg : list of ints
1122          List of maximum degrees of the form [x_deg, y_deg].
1123  
1124      Returns
1125      -------
1126      vander2d : ndarray
1127          The shape of the returned matrix is ``x.shape + (order,)``, where
1128          :math:`order = (deg[0]+1)*(deg[1]+1)`.  The dtype will be the same
1129          as the converted `x` and `y`.
1130  
1131      See Also
1132      --------
1133      chebvander, chebvander3d, chebval2d, chebval3d
1134  
1135      Notes
1136      -----
1137  
1138      .. versionadded:: 1.7.0
1139  
1140      �rQ�_vander_nd_flatr)r�r�rUr2r2r3r"�s2r"cCst�tttf|||f|�S)aPseudo-Vandermonde matrix of given degrees.
1141  
1142      Returns the pseudo-Vandermonde matrix of degrees `deg` and sample
1143      points `(x, y, z)`. If `l, m, n` are the given degrees in `x, y, z`,
1144      then The pseudo-Vandermonde matrix is defined by
1145  
1146      .. math:: V[..., (m+1)(n+1)i + (n+1)j + k] = T_i(x)*T_j(y)*T_k(z),
1147  
1148      where `0 <= i <= l`, `0 <= j <= m`, and `0 <= j <= n`.  The leading
1149      indices of `V` index the points `(x, y, z)` and the last index encodes
1150      the degrees of the Chebyshev polynomials.
1151  
1152      If ``V = chebvander3d(x, y, z, [xdeg, ydeg, zdeg])``, then the columns
1153      of `V` correspond to the elements of a 3-D coefficient array `c` of
1154      shape (xdeg + 1, ydeg + 1, zdeg + 1) in the order
1155  
1156      .. math:: c_{000}, c_{001}, c_{002},... , c_{010}, c_{011}, c_{012},...
1157  
1158      and ``np.dot(V, c.flat)`` and ``chebval3d(x, y, z, c)`` will be the
1159      same up to roundoff. This equivalence is useful both for least squares
1160      fitting and for the evaluation of a large number of 3-D Chebyshev
1161      series of the same degrees and sample points.
1162  
1163      Parameters
1164      ----------
1165      x, y, z : array_like
1166          Arrays of point coordinates, all of the same shape. The dtypes will
1167          be converted to either float64 or complex128 depending on whether
1168          any of the elements are complex. Scalars are converted to 1-D
1169          arrays.
1170      deg : list of ints
1171          List of maximum degrees of the form [x_deg, y_deg, z_deg].
1172  
1173      Returns
1174      -------
1175      vander3d : ndarray
1176          The shape of the returned matrix is ``x.shape + (order,)``, where
1177          :math:`order = (deg[0]+1)*(deg[1]+1)*(deg[2]+1)`.  The dtype will
1178          be the same as the converted `x`, `y`, and `z`.
1179  
1180      See Also
1181      --------
1182      chebvander, chebvander3d, chebval2d, chebval3d
1183  
1184      Notes
1185      -----
1186  
1187      .. versionadded:: 1.7.0
1188  
1189      r�)r�r�r�rUr2r2r3r#�s3r#Fc	Cst�t||||||�S)a(
1190      Least squares fit of Chebyshev series to data.
1191  
1192      Return the coefficients of a Chebyshev series of degree `deg` that is the
1193      least squares fit to the data values `y` given at points `x`. If `y` is
1194      1-D the returned coefficients will also be 1-D. If `y` is 2-D multiple
1195      fits are done, one for each column of `y`, and the resulting
1196      coefficients are stored in the corresponding columns of a 2-D return.
1197      The fitted polynomial(s) are in the form
1198  
1199      .. math::  p(x) = c_0 + c_1 * T_1(x) + ... + c_n * T_n(x),
1200  
1201      where `n` is `deg`.
1202  
1203      Parameters
1204      ----------
1205      x : array_like, shape (M,)
1206          x-coordinates of the M sample points ``(x[i], y[i])``.
1207      y : array_like, shape (M,) or (M, K)
1208          y-coordinates of the sample points. Several data sets of sample
1209          points sharing the same x-coordinates can be fitted at once by
1210          passing in a 2D-array that contains one dataset per column.
1211      deg : int or 1-D array_like
1212          Degree(s) of the fitting polynomials. If `deg` is a single integer,
1213          all terms up to and including the `deg`'th term are included in the
1214          fit. For NumPy versions >= 1.11.0 a list of integers specifying the
1215          degrees of the terms to include may be used instead.
1216      rcond : float, optional
1217          Relative condition number of the fit. Singular values smaller than
1218          this relative to the largest singular value will be ignored. The
1219          default value is len(x)*eps, where eps is the relative precision of
1220          the float type, about 2e-16 in most cases.
1221      full : bool, optional
1222          Switch determining nature of return value. When it is False (the
1223          default) just the coefficients are returned, when True diagnostic
1224          information from the singular value decomposition is also returned.
1225      w : array_like, shape (`M`,), optional
1226          Weights. If not None, the weight ``w[i]`` applies to the unsquared
1227          residual ``y[i] - y_hat[i]`` at ``x[i]``. Ideally the weights are
1228          chosen so that the errors of the products ``w[i]*y[i]`` all have the
1229          same variance.  When using inverse-variance weighting, use
1230          ``w[i] = 1/sigma(y[i])``.  The default value is None.
1231  
1232          .. versionadded:: 1.5.0
1233  
1234      Returns
1235      -------
1236      coef : ndarray, shape (M,) or (M, K)
1237          Chebyshev coefficients ordered from low to high. If `y` was 2-D,
1238          the coefficients for the data in column k  of `y` are in column
1239          `k`.
1240  
1241      [residuals, rank, singular_values, rcond] : list
1242          These values are only returned if ``full == True``
1243  
1244          - residuals -- sum of squared residuals of the least squares fit
1245          - rank -- the numerical rank of the scaled Vandermonde matrix
1246          - singular_values -- singular values of the scaled Vandermonde matrix
1247          - rcond -- value of `rcond`.
1248  
1249          For more details, see `numpy.linalg.lstsq`.
1250  
1251      Warns
1252      -----
1253      RankWarning
1254          The rank of the coefficient matrix in the least-squares fit is
1255          deficient. The warning is only raised if ``full == False``.  The
1256          warnings can be turned off by
1257  
1258          >>> import warnings
1259          >>> warnings.simplefilter('ignore', np.RankWarning)
1260  
1261      See Also
1262      --------
1263      numpy.polynomial.polynomial.polyfit
1264      numpy.polynomial.legendre.legfit
1265      numpy.polynomial.laguerre.lagfit
1266      numpy.polynomial.hermite.hermfit
1267      numpy.polynomial.hermite_e.hermefit
1268      chebval : Evaluates a Chebyshev series.
1269      chebvander : Vandermonde matrix of Chebyshev series.
1270      chebweight : Chebyshev weight function.
1271      numpy.linalg.lstsq : Computes a least-squares fit from the matrix.
1272      scipy.interpolate.UnivariateSpline : Computes spline fits.
1273  
1274      Notes
1275      -----
1276      The solution is the coefficients of the Chebyshev series `p` that
1277      minimizes the sum of the weighted squared errors
1278  
1279      .. math:: E = \sum_j w_j^2 * |y_j - p(x_j)|^2,
1280  
1281      where :math:`w_j` are the weights. This problem is solved by setting up
1282      as the (typically) overdetermined matrix equation
1283  
1284      .. math:: V(x) * c = w * y,
1285  
1286      where `V` is the weighted pseudo Vandermonde matrix of `x`, `c` are the
1287      coefficients to be solved for, `w` are the weights, and `y` are the
1288      observed values.  This equation is then solved using the singular value
1289      decomposition of `V`.
1290  
1291      If some of the singular values of `V` are so small that they are
1292      neglected, then a `RankWarning` will be issued. This means that the
1293      coefficient values may be poorly determined. Using a lower order fit
1294      will usually get rid of the warning.  The `rcond` parameter can also be
1295      set to a value smaller than its default, but the resulting fit may be
1296      spurious and have large contributions from roundoff error.
1297  
1298      Fits using Chebyshev series are usually better conditioned than fits
1299      using power series, but much can depend on the distribution of the
1300      sample points and the smoothness of the data. If the quality of the fit
1301      is inadequate splines may be a good alternative.
1302  
1303      References
1304      ----------
1305      .. [1] Wikipedia, "Curve fitting",
1306             https://en.wikipedia.org/wiki/Curve_fitting
1307  
1308      Examples
1309      --------
1310  
1311      )rQ�_fitr)r�r�rU�rcond�full�wr2r2r3rs|rcCst�|g�\}t|�dkrtd��t|�dkr%t�|d|dgg�St|�d}tj||f|jd�}t�dgt�d�g|d�}|�	d�dd	|d�}|�	d�|d	|d�}t�d�|d<d|dd	�<||d
1312  <|d	d	�df|d	d�|d||dd8<|S)a�Return the scaled companion matrix of c.
1313  
1314      The basis polynomials are scaled so that the companion matrix is
1315      symmetric when `c` is a Chebyshev basis polynomial. This provides
1316      better eigenvalue estimates than the unscaled case and for basis
1317      polynomials the eigenvalues are guaranteed to be real if
1318      `numpy.linalg.eigvalsh` is used to obtain them.
1319  
1320      Parameters
1321      ----------
1322      c : array_like
1323          1-D array of Chebyshev series coefficients ordered from low to high
1324          degree.
1325  
1326      Returns
1327      -------
1328      mat : ndarray
1329          Scaled companion matrix of dimensions (deg, deg).
1330  
1331      Notes
1332      -----
1333  
1334      .. versionadded:: 1.7.0
1335  
1336      r(z.Series must have maximum degree of at least 1.rrr)��?��?r+N.)
1337  rQrRr<rlr-rJr.r*�sqrtr�)r/r0�matrA�top�botr2r2r3r$�s 8r$cCs�t�|g�\}t|�dkrtjg|jd�St|�dkr(t�|d|dg�St|�ddd�ddd�f}t�|�}|�	�|S)a�
1338      Compute the roots of a Chebyshev series.
1339  
1340      Return the roots (a.k.a. "zeros") of the polynomial
1341  
1342      .. math:: p(x) = \sum_i c[i] * T_i(x).
1343  
1344      Parameters
1345      ----------
1346      c : 1-D array_like
1347          1-D array of coefficients.
1348  
1349      Returns
1350      -------
1351      out : ndarray
1352          Array of the roots of the series. If all the roots are real,
1353          then `out` is also real, otherwise it is complex.
1354  
1355      See Also
1356      --------
1357      numpy.polynomial.polynomial.polyroots
1358      numpy.polynomial.legendre.legroots
1359      numpy.polynomial.laguerre.lagroots
1360      numpy.polynomial.hermite.hermroots
1361      numpy.polynomial.hermite_e.hermeroots
1362  
1363      Notes
1364      -----
1365      The root estimates are obtained as the eigenvalues of the companion
1366      matrix, Roots far from the origin of the complex plane may have large
1367      errors due to the numerical instability of the series for such
1368      values. Roots with multiplicity greater than 1 will also show larger
1369      errors as the value of the series near such points is relatively
1370      insensitive to errors in the roots. Isolated roots near the origin can
1371      be improved by a few iterations of Newton's method.
1372  
1373      The Chebyshev series basis polynomials aren't powers of `x` so the
1374      results of this function may seem unintuitive.
1375  
1376      Examples
1377      --------
1378      >>> import numpy.polynomial.chebyshev as cheb
1379      >>> cheb.chebroots((-1, 1,-1, 1)) # T3 - T2 + T1 - T0 has real roots
1380      array([ -5.00000000e-01,   2.60860684e-17,   1.00000000e+00]) # may vary
1381  
1382      r(r)rrNr+)
1383  rQrRr<r-rJr*r$�la�eigvals�sort)r/r|rEr2r2r3r�s0
1384  rr2cCs�t�|�}|jdks|jjdvs|jdkrtd��|dkr!td��|d}t|�}||g|�R�}t	||�}t�
1385  |j|�}|d|<|dd�d|<|S)a2Interpolate a function at the Chebyshev points of the first kind.
1386  
1387      Returns the Chebyshev series that interpolates `func` at the Chebyshev
1388      points of the first kind in the interval [-1, 1]. The interpolating
1389      series tends to a minmax approximation to `func` with increasing `deg`
1390      if the function is continuous in the interval.
1391  
1392      .. versionadded:: 1.14.0
1393  
1394      Parameters
1395      ----------
1396      func : function
1397          The function to be approximated. It must be a function of a single
1398          variable of the form ``f(x, a, b, c...)``, where ``a, b, c...`` are
1399          extra arguments passed in the `args` parameter.
1400      deg : int
1401          Degree of the interpolating polynomial
1402      args : tuple, optional
1403          Extra arguments to be used in the function call. Default is no extra
1404          arguments.
1405  
1406      Returns
1407      -------
1408      coef : ndarray, shape (deg + 1,)
1409          Chebyshev coefficients of the interpolating series ordered from low to
1410          high.
1411  
1412      Examples
1413      --------
1414      >>> import numpy.polynomial.chebyshev as C
1415      >>> C.chebfromfunction(lambda x: np.tanh(x) + 0.5, 8)
1416      array([  5.00000000e-01,   8.11675684e-01,  -9.86864911e-17,
1417              -5.42457905e-02,  -2.71387850e-16,   4.51658839e-03,
1418               2.46716228e-17,  -3.79694221e-04,  -3.26899002e-16])
1419  
1420      Notes
1421      -----
1422  
1423      The Chebyshev polynomials used in the interpolation are orthogonal when
1424      sampled at the Chebyshev points of the first kind. If it is desired to
1425      constrain some of the coefficients they can simply be set to the desired
1426      value after the interpolation, no new interpolation or fit is needed. This
1427      is especially useful if it is known apriori that some of coefficients are
1428      zero. For instance, if the function is even then the coefficients of the
1429      terms of odd degree in the result can be set to zero.
1430  
1431      r�iuzdeg must be an intzexpected deg >= 0rNr�)r-r�ryr*�kindr,�	TypeErrorrlrr�dot�T)�funcrU�args�orderZxchebZyfuncr|r/r2r2r3r'�s
1432  0 
1433  r'cCs^t�|d�}|dkrtd��t�tjt�dd|d�d|�}t�|�tj|}||fS)a�
1434      Gauss-Chebyshev quadrature.
1435  
1436      Computes the sample points and weights for Gauss-Chebyshev quadrature.
1437      These sample points and weights will correctly integrate polynomials of
1438      degree :math:`2*deg - 1` or less over the interval :math:`[-1, 1]` with
1439      the weight function :math:`f(x) = 1/\sqrt{1 - x^2}`.
1440  
1441      Parameters
1442      ----------
1443      deg : int
1444          Number of sample points and weights. It must be >= 1.
1445  
1446      Returns
1447      -------
1448      x : ndarray
1449          1-D ndarray containing the sample points.
1450      y : ndarray
1451          1-D ndarray containing the weights.
1452  
1453      Notes
1454      -----
1455  
1456      .. versionadded:: 1.7.0
1457  
1458      The results have only been tested up to degree 100, higher degrees may
1459      be problematic. For Gauss-Chebyshev there are closed form solutions for
1460      the sample points and weights. If n = `deg`, then
1461  
1462      .. math:: x_i = \cos(\pi (2 i - 1) / (2 n))
1463  
1464      .. math:: w_i = \pi / n
1465  
1466      rUrzdeg must be a positive integerrr(g@)rQrxrlr-�cos�pirK�ones)rUr�r�r�r2r2r3r%7s#&r%cCs$dt�d|�t�d|�}|S)a�
1467      The weight function of the Chebyshev polynomials.
1468  
1469      The weight function is :math:`1/\sqrt{1 - x^2}` and the interval of
1470      integration is :math:`[-1, 1]`. The Chebyshev polynomials are
1471      orthogonal, but not normalized, with respect to this weight function.
1472  
1473      Parameters
1474      ----------
1475      x : array_like
1476         Values at which the weight function will be computed.
1477  
1478      Returns
1479      -------
1480      w : ndarray
1481         The weight function at `x`.
1482  
1483      Notes
1484      -----
1485  
1486      .. versionadded:: 1.7.0
1487  
1488      r�)r-r�)r�r�r2r2r3r&ds r&cCsXt|�}||krtd��|dkrtd��dtj|t�|d|dd�}t�|�S)a�
1489      Chebyshev points of the first kind.
1490  
1491      The Chebyshev points of the first kind are the points ``cos(x)``,
1492      where ``x = [pi*(k + .5)/npts for k in range(npts)]``.
1493  
1494      Parameters
1495      ----------
1496      npts : int
1497          Number of sample points desired.
1498  
1499      Returns
1500      -------
1501      pts : ndarray
1502          The Chebyshev points of the first kind.
1503  
1504      See Also
1505      --------
1506      chebpts2
1507  
1508      Notes
1509      -----
1510  
1511      .. versionadded:: 1.5.0
1512  
1513      �npts must be integerrznpts must be >= 1r�r()rkrlr-r�rK�sin�ZnptsZ_nptsr�r2r2r3r�s&
1514  rcCsDt|�}||krtd��|dkrtd��t�tjd|�}t�|�S)a�
1515      Chebyshev points of the second kind.
1516  
1517      The Chebyshev points of the second kind are the points ``cos(x)``,
1518      where ``x = [pi*k/(npts - 1) for k in range(npts)]`` sorted in ascending
1519      order.
1520  
1521      Parameters
1522      ----------
1523      npts : int
1524          Number of sample points desired.
1525  
1526      Returns
1527      -------
1528      pts : ndarray
1529          The Chebyshev points of the second kind.
1530  
1531      Notes
1532      -----
1533  
1534      .. versionadded:: 1.5.0
1535  
1536      r�r(znpts must be >= 2r)rkrlr-�linspacer�r�r�r2r2r3r�s
1537  rc@s�eZdZdZee�Zee�Zee	�Z
1538  ee�Zee
�Zee�Zee�Zee�Zee�Zee�Zee�Zee�Zeddd��Ze� e!�Z"e� e!�Z#dZ$dS)ra�A Chebyshev series class.
1539  
1540      The Chebyshev class provides the standard Python numerical methods
1541      '+', '-', '*', '//', '%', 'divmod', '**', and '()' as well as the
1542      methods listed below.
1543  
1544      Parameters
1545      ----------
1546      coef : array_like
1547          Chebyshev coefficients in order of increasing degree, i.e.,
1548          ``(1, 2, 3)`` gives ``1*T_0(x) + 2*T_1(x) + 3*T_2(x)``.
1549      domain : (2,) array_like, optional
1550          Domain to use. The interval ``[domain[0], domain[1]]`` is mapped
1551          to the interval ``[window[0], window[1]]`` by shifting and scaling.
1552          The default value is [-1, 1].
1553      window : (2,) array_like, optional
1554          Window, see `domain` for its use. The default value is [-1, 1].
1555  
1556          .. versionadded:: 1.6.0
1557  
1558      Nr2cs6�dur�j�����fdd�}t||�}�|�d�S)a�Interpolate a function at the Chebyshev points of the first kind.
1559  
1560          Returns the series that interpolates `func` at the Chebyshev points of
1561          the first kind scaled and shifted to the `domain`. The resulting series
1562          tends to a minmax approximation of `func` when the function is
1563          continuous in the domain.
1564  
1565          .. versionadded:: 1.14.0
1566  
1567          Parameters
1568          ----------
1569          func : function
1570              The function to be interpolated. It must be a function of a single
1571              variable of the form ``f(x, a, b, c...)``, where ``a, b, c...`` are
1572              extra arguments passed in the `args` parameter.
1573          deg : int
1574              Degree of the interpolating polynomial.
1575          domain : {None, [beg, end]}, optional
1576              Domain over which `func` is interpolated. The default is None, in
1577              which case the domain is [-1, 1].
1578          args : tuple, optional
1579              Extra arguments to be used in the function call. Default is no
1580              extra arguments.
1581  
1582          Returns
1583          -------
1584          polynomial : Chebyshev instance
1585              Interpolating Chebyshev instance.
1586  
1587          Notes
1588          -----
1589          See `numpy.polynomial.chebfromfunction` for more details.
1590  
1591          Ncs�t�|�j��g��R�S)N)rQ�	mapdomain�window)r��r��cls�domainr�r2r3�<lambda>sz'Chebyshev.interpolate.<locals>.<lambda>)r�)r�r')r�r�rUr�r�Zxfunc�coefr2r�r3�interpolate�s
1592  $
1593  zChebyshev.interpolater�)Nr2)%�__name__�
1594  __module__�__qualname__�__doc__�staticmethodrrbrrer�_mulr�_divr�_powr�_valr�_intr�_derrr�r
1595  �_liner�_rootsrr`�classmethodr�r-rJr	r�r��
1596  basis_namer2r2r2r3r�s&
1597  *
1598  r)rj)rrr)T)NFN)r2)8r��numpyr-�numpy.linalg�linalgr��numpy.core.multiarrayr�rrQ�	_polybaser�__all__�trimcoefrr4r6r;rHrNrPrrrJr	rrrr
1599  rrrr
rrrrrrrr rr!rr"r#rr$rr'r%r&rrrr2r2r2r3�<module>s^m	C &2C&7*,.1
1600  C
1601  :\
1602  T153855
1603  6-
1604  =C-%&