U
    …»|eL  ã                   @   s4   d dl mZmZmZmZmZ ddd„Zddd	„Zd
S )é    )ÚarangeÚnewaxisÚhstackÚprodÚarrayé   c                 C   s¬   | |d k rt dƒ‚| d dkr(t dƒ‚ddlm} | d? }t| |d ƒ}|dd…tf }|d	 }td| ƒD ]}t||| gƒ}qnttd|d ƒdd
�| |¡|  }|S )a¯  
    Return weights for an Np-point central derivative.

    Assumes equally-spaced function points.

    If weights are in the vector w, then
    derivative is w[0] * f(x-ho*dx) + ... + w[-1] * f(x+h0*dx)

    Parameters
    ----------
    Np : int
        Number of points for the central derivative.
    ndiv : int, optional
        Number of divisions. Default is 1.

    Returns
    -------
    w : ndarray
        Weights for an Np-point central derivative. Its size is `Np`.

    Notes
    -----
    Can be inaccurate for a large number of points.

    Examples
    --------
    We can calculate a derivative value of a function.

    >>> def f(x):
    ...     return 2 * x**2 + 3
    >>> x = 3.0 # derivative point
    >>> h = 0.1 # differential step
    >>> Np = 3 # point number for central derivative
    >>> weights = _central_diff_weights(Np) # weights for first derivative
    >>> vals = [f(x + (i - Np/2) * h) for i in range(Np)]
    >>> sum(w * v for (w, v) in zip(weights, vals))/h
    11.79999999999998

    This value is close to the analytical solution:
    f'(x) = 4x, so f'(3) = 12

    References
    ----------
    .. [1] https://en.wikipedia.org/wiki/Finite_difference

    r   z;Number of points must be at least the derivative order + 1.é   r   z!The number of points must be odd.)Úlinalgç      ð?Nç        ©Úaxis)	Ú
ValueErrorÚscipyr	   r   r   Úranger   r   Úinv)ZNpZndivr	   ÚhoÚxÚXÚkÚw© r   ú[/var/www/website-v5/atlas_env/lib/python3.8/site-packages/scipy/_lib/_finite_differences.pyÚ_central_diff_weights   s    /ÿ$r   r
   r   é   c           
   
   C   sÆ  ||d k rt dƒ‚|d dkr(t dƒ‚|dkrÄ|dkrLtdddgƒd }nv|d	krltdd
dddgƒd }nV|dkr�tdddddddgƒd }n2|dkr¸tdddddddddg	ƒd }n
t|dƒ}nª|dk�rd|dkrætdddgƒ}n||d	k�rtdddddgƒd }nZ|dk�r.tdddd dddgƒd! }n4|dk�rXtdd"d#d$d%d$d#d"dg	ƒd& }n
t|dƒ}n
t||ƒ}d'}|d? }t|ƒD ],}	|||	 | ||	| |  f|žŽ  7 }�q‚|t|f| dd(� S ))a
  
    Find the nth derivative of a function at a point.

    Given a function, use a central difference formula with spacing `dx` to
    compute the nth derivative at `x0`.

    Parameters
    ----------
    func : function
        Input function.
    x0 : float
        The point at which the nth derivative is found.
    dx : float, optional
        Spacing.
    n : int, optional
        Order of the derivative. Default is 1.
    args : tuple, optional
        Arguments
    order : int, optional
        Number of points to use, must be odd.

    Notes
    -----
    Decreasing the step size too small can result in round-off error.

    Examples
    --------
    >>> def f(x):
    ...     return x**3 + x**2
    >>> _derivative(f, 1.0, dx=1e-6)
    4.9999999999217337

    r   zm'order' (the number of points used to compute the derivative), must be at least the derivative order 'n' + 1.r   r   zJ'order' (the number of points used to compute the derivative) must be odd.r   éÿÿÿÿg       @é   iøÿÿÿé   g      (@é   é	   iÓÿÿÿé-   i÷ÿÿÿg      N@iàÿÿÿé¨   i`ýÿÿi   iXÿÿÿé    éýÿÿÿg     @Š@g       Àé   iâÿÿÿiåÿÿÿi  iþÿÿg     €f@é€   iüÿÿi€  iòÇÿÿg     °³@r   r   )r   r   r   r   r   )
ÚfuncÚx0ÚdxÚnÚargsÚorderÚweightsÚvalr   r   r   r   r   Ú_derivativeE   sJ    "ÿÿ 



ÿÿ
*r.   N)r   )r
   r   r   r   )Únumpyr   r   r   r   r   r   r.   r   r   r   r   Ú<module>   s   
A