
    (phL                     4    S SK JrJrJrJrJr  SS jrSS jrg)    )arangenewaxishstackprodarrayc                 J   XS-   :  a  [        S5      eU S-  S:X  a  [        S5      eSSKJn  U S-	  n[        U* US-   5      nUSS2[        4   nUS	-  n[        SU 5       H  n[        XTU-  /5      nM     [        [        SUS-   5      SS
9UR                  U5      U   -  nU$ )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

   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)Npndivr   hoxXkws           Q/var/www/html/venv/lib/python3.13/site-packages/scipy/_lib/_finite_differences.py_central_diff_weightsr      s    ^ 
1H}I
 	
 
Av{<==	qBsBHA	!W*A	3A1b\A!t9 VAtax q)FJJqM$,??AH    c                    XSS-   :  a  [        S5      eUS-  S:X  a  [        S5      eUS:X  ai  US:X  a  [        / SQ5      S-  nOUS	:X  a  [        / S
Q5      S-  nOUS:X  a  [        / SQ5      S-  nOUS:X  a  [        / SQ5      S-  nO[        US5      nOwUS:X  af  US:X  a  [        / SQ5      nO]US	:X  a  [        / SQ5      S-  nOFUS:X  a  [        / SQ5      S-  nO/US:X  a  [        / SQ5      S-  nO[        US5      nO[        XS5      nSnUS-	  n[        U5       H  n	XvU	   U " XU-
  U-  -   /UQ76 -  -  nM     U[	        U4U-  SS9-  $ )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   r	   g       @   )r	   ir      r    g      (@   )r    	   ir   -   r	   g      N@r$   )	r   i   i`r   i  iX    g     @@)r	   g       r	   )r       ir*   r    )r
     ir,   r+   r
   g     f@)	r&        ir/   r.   r-   r&   g     @r   r   )r   r   r   r   r   )
funcx0dxnargsorderweightsvalr   r   s
             r   _derivativer8   E   s   D 1u}=
 	
 qyA~
 	

 	AvA:J'#-GaZ-.5GaZ67$>GaZEFNG+E15G	
aA:L)GaZ12T9GaZ<=EGaZJK 
 ,E15G'1
C	!B5\qzD2vm!3;d;;; reaia(((r   N)r	   )r   r	    r   )numpyr   r   r   r   r   r   r8   r9   r   r   <module>r;      s    6 6>BL)r   