polynomial.pyc
1 o 2 [��c� � @ s d Z g d�ZddlZddlZddlZddlm mZ ddl m 3 Z 4 mZmZm Z mZmZmZmZ ddl mZ ddlmZ ddlmZmZ ddlmZ dd lmZmZmZmZ dd 5 lm Z m!Z!m"Z" ej#ej$dd�Z$ed�G d d� de%��Z&dd� Z'e$e'�dd� �Z(dd� Z)e$e)�dd� �Z*d<dd�Z+e$e+�d=dd��Z,d>dd�Z-e$e-�d?dd��Z.d@d d!�Z/e$e/�dAd#d$��Z0d%d&� Z1e$e1�d'd(� �Z2d)d*� Z3e$e3�d+d,� �Z4e$e3�d-d.� �Z5e$e3�d/d0� �Z6d1d2� Z7e$e7�d3d4� �Z8e�9d5�Z:dBd7d8�Z;ed�G d9d:� d:��Z<e�=d;e&� dS )Cz' 6 Functions to operate on polynomials. 7 8 )�poly�roots�polyint�polyder�polyadd�polysub�polymul�polydiv�polyval�poly1d�polyfit�RankWarning� N)�isscalar�abs�finfo� 9 atleast_1d�hstack�dot�array�ones)� overrides)� 10 set_module)�diag�vander)� 11 trim_zeros)� iscomplex�real�imag�mintypecode)�eigvals�lstsq�inv�numpy)�modulec @ s e Zd ZdZdS )r z� 12 Issued by `polyfit` when the Vandermonde matrix is rank deficient. 13 14 For more information, a way to suppress the warning, and an example of 15 `RankWarning` being issued, see `polyfit`. 16 17 N)�__name__� 18 __module__�__qualname__�__doc__� r( r( ��C:\Users\Jacks.GUTTSPC\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\numpy\lib\polynomial.pyr s r c C � | S �Nr( )�seq_of_zerosr( r( r) �_poly_dispatcher( � r- c C s t | �} | j}t|�dkr |d |d kr |d dkr t| �} nt|�dkr6| j}|tkr5| �t|j��} nt d��t| �dkrBdS | j}t 19 d|d�}| D ]}tj|t d| g|d�dd �}qMt|jjtj�r�t�| t�}t�t�|�t�|�� �k�r�|j�� }|S ) 20 a# 21 Find the coefficients of a polynomial with the given sequence of roots. 22 23 .. note:: 24 This forms part of the old polynomial API. Since version 1.4, the 25 new polynomial API defined in `numpy.polynomial` is preferred. 26 A summary of the differences can be found in the 27 :doc:`transition guide </reference/routines.polynomials>`. 28 29 Returns the coefficients of the polynomial whose leading coefficient 30 is one for the given sequence of zeros (multiple roots must be included 31 in the sequence as many times as their multiplicity; see Examples). 32 A square matrix (or array, which will be treated as a matrix) can also 33 be given, in which case the coefficients of the characteristic polynomial 34 of the matrix are returned. 35 36 Parameters 37 ---------- 38 seq_of_zeros : array_like, shape (N,) or (N, N) 39 A sequence of polynomial roots, or a square array or matrix object. 40 41 Returns 42 ------- 43 c : ndarray 44 1D array of polynomial coefficients from highest to lowest degree: 45 46 ``c[0] * x**(N) + c[1] * x**(N-1) + ... + c[N-1] * x + c[N]`` 47 where c[0] always equals 1. 48 49 Raises 50 ------ 51 ValueError 52 If input is the wrong shape (the input must be a 1-D or square 53 2-D array). 54 55 See Also 56 -------- 57 polyval : Compute polynomial values. 58 roots : Return the roots of a polynomial. 59 polyfit : Least squares polynomial fit. 60 poly1d : A one-dimensional polynomial class. 61 62 Notes 63 ----- 64 Specifying the roots of a polynomial still leaves one degree of 65 freedom, typically represented by an undetermined leading 66 coefficient. [1]_ In the case of this function, that coefficient - 67 the first one in the returned array - is always taken as one. (If 68 for some reason you have one other point, the only automatic way 69 presently to leverage that information is to use ``polyfit``.) 70 71 The characteristic polynomial, :math:`p_a(t)`, of an `n`-by-`n` 72 matrix **A** is given by 73 74 :math:`p_a(t) = \mathrm{det}(t\, \mathbf{I} - \mathbf{A})`, 75 76 where **I** is the `n`-by-`n` identity matrix. [2]_ 77 78 References 79 ---------- 80 .. [1] M. Sullivan and M. Sullivan, III, "Algebra and Trignometry, 81 Enhanced With Graphing Utilities," Prentice-Hall, pg. 318, 1996. 82 83 .. [2] G. Strang, "Linear Algebra and Its Applications, 2nd Edition," 84 Academic Press, pg. 182, 1980. 85 86 Examples 87 -------- 88 Given a sequence of a polynomial's zeros: 89 90 >>> np.poly((0, 0, 0)) # Multiple root example 91 array([1., 0., 0., 0.]) 92 93 The line above represents z**3 + 0*z**2 + 0*z + 0. 94 95 >>> np.poly((-1./2, 0, 1./2)) 96 array([ 1. , 0. , -0.25, 0. ]) 97 98 The line above represents z**3 - z/4 99 100 >>> np.poly((np.random.random(1)[0], 0, np.random.random(1)[0])) 101 array([ 1. , -0.77086955, 0.08618131, 0. ]) # random 102 103 Given a square array object: 104 105 >>> P = np.array([[0, 1./3], [-1./2, 0]]) 106 >>> np.poly(P) 107 array([1. , 0. , 0.16666667]) 108 109 Note how in all cases the leading coefficient is always 1. 110 111 � r � z.input must be 1d or non-empty square 2d array.� �?�r0 ��dtype�full)�mode)r �shape�lenr r4 �object�astyper �char� 112 ValueErrorr �NX�convolver � 113 issubclass�type�complexfloating�asarray�complex�all�sort� conjugater �copy)r, �sh�dt�a�zeror r( r( r) r , s* ^( 114 � 115 r c C r* r+ r( )�pr( r( r) �_roots_dispatcher� r. rM c C s t | �} | jdkr td��t�t�| ��d }t|�dkr"t�g �S t| �|d d }| t|d �t|d �d � } t | j 116 jtjtj f�sL| �t�} t| �}|dkrwtt�|d f| j 117 �d�}| dd� | d |ddd�f<