
    (phL                        S SK rS SKJrJr  S SKJrJrJr  S SK	J
r
  S SKJr  SSKJrJrJrJrJrJrJrJr  SSKJrJr  S	r\R4                  " S
\-
  S-  S
\-   S-  S/5      r\R4                  " SS\-  -
  SS\-  -   S/5      S-  rSrSr\R4                  " / SQ/ SQ/ SQ/5      r\R4                  " / SQ/ SQ/ SQ/5      r \ S    r!\ S   S\ S   -  -   r"\R4                  " SS\-  S-  -   SS\-  S-  -
  SS\-  -   /SS\-  S-  -
  SS\-  S-  -   SS\-  -
  // SQ/5      r#S r$S!r%Sr&S" r'S# r( " S$ S%\5      r) " S& S'\5      r*g)(    N)	lu_factorlu_solve)
csc_matrixissparseeye)splu)group_columns   )validate_max_stepvalidate_tolselect_initial_stepnormnum_jacEPSwarn_extraneousvalidate_first_step)	OdeSolverDenseOutputg.!	@   
   i      gs>H@yrr@Gg)g{g]#-?g;@L¿ghm?)g
}?gQ  ?gmؿ)r
   r
   r   )gF@gN]?gV?)gFgN]Կg!R ?)g$Z?goNg{?              ?   gUUUUUU@g   竪
@   )gUUUUUU?gUUUUUUr      g?c
                    UR                   S   n
[        U-  n[        U-  n[        R	                  U5      nUn[
        R                  " SU
45      nU[        -  nSn[
        R                  " U5      nSnSn[        [        5       GH]  n[        S5       H  nU " UUU   -   X.U   -   5      UU'   M     [
        R                  " [
        R                  " U5      5      (       d    GOUR                  R	                  [        5      XS   -  -
  nUR                  R	                  [        5      XS   SUS   -  -   -  -
  nU	" UU5      nU	" UU5      nUUS'   UR                   US'   UR"                  US'   [%        UU-  5      nUb  UU-  nUb!  US:  d  U[        U-
  -  SU-
  -  U-  U:  a    O=UU-  n[        R	                  U5      nUS:X  d  Ub  USU-
  -  U-  U:  a  Sn  OUnGM`     UWS-   UU4$ )	a  Solve the collocation system.

Parameters
----------
fun : callable
    Right-hand side of the system.
t : float
    Current time.
y : ndarray, shape (n,)
    Current state.
h : float
    Step to try.
Z0 : ndarray, shape (3, n)
    Initial guess for the solution. It determines new values of `y` at
    ``t + h * C`` as ``y + Z0``, where ``C`` is the Radau method constants.
scale : ndarray, shape (n)
    Problem tolerance scale, i.e. ``rtol * abs(y) + atol``.
tol : float
    Tolerance to which solve the system. This value is compared with
    the normalized by `scale` error.
LU_real, LU_complex
    LU decompositions of the system Jacobians.
solve_lu : callable
    Callable which solves a linear system given a LU decomposition. The
    signature is ``solve_lu(LU, b)``.

Returns
-------
converged : bool
    Whether iterations converged.
n_iter : int
    Number of completed iterations.
Z : ndarray, shape (3, n)
    Found solution.
rate : float
    The rate of convergence.
r   r   NFr
   r   r   T)shapeMU_REAL
MU_COMPLEXTIdotnpemptyC
empty_likerangeNEWTON_MAXITERallisfiniteTTI_REAL
TI_COMPLEXrealimagr   )funtyhZ0scaletolLU_real
LU_complexsolve_lunM_real	M_complexWZFchdW_norm_olddW	convergedratekif_real	f_complexdW_real
dW_complexdW_norms                               M/var/www/html/venv/lib/python3.13/site-packages/scipy/integrate/_ivp/radau.pysolve_collocation_systemrP   0   s   N 	

Aq[FQI
r
A
A
!QA	
QBK	q	BID>"qAq2a5y!d(+AaD  vvbkk!n%%!FqTM1CCGGJ')tb1Q4i7G*HH	7F+j)4
111rEz""[(D$!)!+,D9GCcI	REE!HqL TQX%6%@3%FIC #F a!eQ$$    c                     Ub	  Ub  US:X  a  SnOX-  X2-  S-  -  n[         R                  " SS9   [        SU5      US-  -  nSSS5        U$ ! , (       d  f       W$ = f)a  Predict by which factor to increase/decrease the step size.

The algorithm is described in [1]_.

Parameters
----------
h_abs, h_abs_old : float
    Current and previous values of the step size, `h_abs_old` can be None
    (see Notes).
error_norm, error_norm_old : float
    Current and previous values of the error norm, `error_norm_old` can
    be None (see Notes).

Returns
-------
factor : float
    Predicted factor.

Notes
-----
If `h_abs_old` and `error_norm_old` are both not None then a two-step
algorithm is used, otherwise a one-step algorithm is used.

References
----------
.. [1] E. Hairer, S. P. Norsett G. Wanner, "Solving Ordinary Differential
       Equations II: Stiff and Differential-Algebraic Problems", Sec. IV.8.
Nr   r
   g      ?ignore)divideg      п)r&   errstatemin)h_abs	h_abs_old
error_normerror_norm_old
multiplierfactors         rO   predict_factorr]      sm    : !2jAo
&.*E$)NN
	H	%Q
#jE&99 
& M 
&	% Ms   A
Ac                   j   ^  \ rS rSrSr\R                  SSSSSS4U 4S jjrS rS	 r	S
 r
S rSrU =r$ )Radau   a  Implicit Runge-Kutta method of Radau IIA family of order 5.

The implementation follows [1]_. The error is controlled with a
third-order accurate embedded formula. A cubic polynomial which satisfies
the collocation conditions is used for the dense output.

Parameters
----------
fun : callable
    Right-hand side of the system: the time derivative of the state ``y``
    at time ``t``. The calling signature is ``fun(t, y)``, where ``t`` is a
    scalar and ``y`` is an ndarray with ``len(y) = len(y0)``. ``fun`` must
    return an array of the same shape as ``y``. See `vectorized` for more
    information.
t0 : float
    Initial time.
y0 : array_like, shape (n,)
    Initial state.
t_bound : float
    Boundary time - the integration won't continue beyond it. It also
    determines the direction of the integration.
first_step : float or None, optional
    Initial step size. Default is ``None`` which means that the algorithm
    should choose.
max_step : float, optional
    Maximum allowed step size. Default is np.inf, i.e., the step size is not
    bounded and determined solely by the solver.
rtol, atol : float and array_like, optional
    Relative and absolute tolerances. The solver keeps the local error
    estimates less than ``atol + rtol * abs(y)``. HHere `rtol` controls a
    relative accuracy (number of correct digits), while `atol` controls
    absolute accuracy (number of correct decimal places). To achieve the
    desired `rtol`, set `atol` to be smaller than the smallest value that
    can be expected from ``rtol * abs(y)`` so that `rtol` dominates the
    allowable error. If `atol` is larger than ``rtol * abs(y)`` the
    number of correct digits is not guaranteed. Conversely, to achieve the
    desired `atol` set `rtol` such that ``rtol * abs(y)`` is always smaller
    than `atol`. If components of y have different scales, it might be
    beneficial to set different `atol` values for different components by
    passing array_like with shape (n,) for `atol`. Default values are
    1e-3 for `rtol` and 1e-6 for `atol`.
jac : {None, array_like, sparse_matrix, callable}, optional
    Jacobian matrix of the right-hand side of the system with respect to
    y, required by this method. The Jacobian matrix has shape (n, n) and
    its element (i, j) is equal to ``d f_i / d y_j``.
    There are three ways to define the Jacobian:

        * If array_like or sparse_matrix, the Jacobian is assumed to
          be constant.
        * If callable, the Jacobian is assumed to depend on both
          t and y; it will be called as ``jac(t, y)`` as necessary.
          For the 'Radau' and 'BDF' methods, the return value might be a
          sparse matrix.
        * If None (default), the Jacobian will be approximated by
          finite differences.

    It is generally recommended to provide the Jacobian rather than
    relying on a finite-difference approximation.
jac_sparsity : {None, array_like, sparse matrix}, optional
    Defines a sparsity structure of the Jacobian matrix for a
    finite-difference approximation. Its shape must be (n, n). This argument
    is ignored if `jac` is not `None`. If the Jacobian has only few non-zero
    elements in *each* row, providing the sparsity structure will greatly
    speed up the computations [2]_. A zero entry means that a corresponding
    element in the Jacobian is always zero. If None (default), the Jacobian
    is assumed to be dense.
vectorized : bool, optional
    Whether `fun` can be called in a vectorized fashion. Default is False.

    If ``vectorized`` is False, `fun` will always be called with ``y`` of
    shape ``(n,)``, where ``n = len(y0)``.

    If ``vectorized`` is True, `fun` may be called with ``y`` of shape
    ``(n, k)``, where ``k`` is an integer. In this case, `fun` must behave
    such that ``fun(t, y)[:, i] == fun(t, y[:, i])`` (i.e. each column of
    the returned array is the time derivative of the state corresponding
    with a column of ``y``).

    Setting ``vectorized=True`` allows for faster finite difference
    approximation of the Jacobian by this method, but may result in slower
    execution overall in some circumstances (e.g. small ``len(y0)``).

Attributes
----------
n : int
    Number of equations.
status : string
    Current status of the solver: 'running', 'finished' or 'failed'.
t_bound : float
    Boundary time.
direction : float
    Integration direction: +1 or -1.
t : float
    Current time.
y : ndarray
    Current state.
t_old : float
    Previous time. None if no steps were made yet.
step_size : float
    Size of the last successful step. None if no steps were made yet.
nfev : int
    Number of evaluations of the right-hand side.
njev : int
    Number of evaluations of the Jacobian.
nlu : int
    Number of LU decompositions.

References
----------
.. [1] E. Hairer, G. Wanner, "Solving Ordinary Differential Equations II:
       Stiff and Differential-Algebraic Problems", Sec. IV.8.
.. [2] A. Curtis, M. J. D. Powell, and J. Reid, "On the estimation of
       sparse Jacobian matrices", Journal of the Institute of Mathematics
       and its Applications, 13, pp. 117-120, 1974.
MbP?gư>NFc                   >^  [        U5        [        TT ]	  XX4U
5        S T l        [	        U5      T l        [        XgT R                  5      u  T l        T l	        T R                  T R                  T R                  5      T l        Uc_  [        T R                  T R                  T R                  XET R                  T R                  ST R                  T R                  5
      T l        O[#        XU5      T l        S T l        S T l        [)        S[*        -  U-  [-        SUS-  5      5      T l        S T l        S T l        T R5                  X5      u  T l        T l        [;        T R8                  5      (       a  U 4S jnS n[=        T R                  SS9nO)U 4S	 jnS
 n[>        R@                  " T R                  5      nUT l!        UT l"        UT l#        ST l$        S T l%        S T l&        S T l'        g )Nr   r   gQ?      ?c                 D   > T=R                   S-  sl         [        U 5      $ Nr
   )nlur   Aselfs    rO   luRadau.__init__.<locals>.luA  s    AAwrQ   c                 $    U R                  U5      $ N)solveLUbs     rO   r<    Radau.__init__.<locals>.solve_luE  s    xx{"rQ   csc)formatc                 B   > T=R                   S-  sl         [        U SS9$ )Nr
   T)overwrite_a)rf   r   rg   s    rO   rj   rk   J  s    A 55rQ   c                     [        XSS9$ )NT)overwrite_b)r   ro   s     rO   r<   rr   N  s    488rQ   T)(r   super__init__y_oldr   max_stepr   r=   rtolatolr3   r4   r5   fr   	directionrW   r   rX   rZ   maxr   rV   
newton_tolsol
jac_factor_validate_jacjacJr   r   r&   identityrj   r<   Icurrent_jacr:   r;   rA   )ri   r3   t0y0t_boundr|   r}   r~   r   jac_sparsity
vectorized
first_step
extraneousrj   r<   r   	__class__s   `               rO   rz   Radau.__init__'  s    	
#"z:
)(3+D?	49$&&$&&) ,$&&$&&'TVVT^^499dii)DJ -ZWEDJ"b3hos4/EF--c@$&DFF# DFF5)A69 DFF#A rQ   c                 z  ^ ^^ T R                   nT R                  nTcJ  Tb*  [        T5      (       a  [        T5      m[	        T5      nTU4mU U4S jnU" X4T R
                  5      nXg4$ [        T5      (       a  T" X45      nST l        [        U5      (       a  [        U5      nS	UU 4S jjnO"[        R                  " U[        S9nS	UU 4S jjnUR                  T R                  T R                  4:w  a2  [        ST R                  T R                  4 SUR                   S35      e Xg4$ [        T5      (       a  [        T5      nO[        R                  " T[        S9nUR                  T R                  T R                  4:w  a2  [        ST R                  T R                  4 SUR                   S35      eS nXg4$ )
Nc           	         > T=R                   S-  sl         [        TR                  XUTR                  TR                  T5      u  nTl        U$ re   )njevr   fun_vectorizedr~   r   )r4   r5   r   r   ri   sparsitys       rO   jac_wrapped(Radau._validate_jac.<locals>.jac_wrappedg  sD    		Q	%,T-@-@!-1YY-5&7"4? rQ   r
   c                 V   > T=R                   S-  sl         [        T" X5      [        S9$ Nr
   dtype)r   r   floatr4   r5   _r   ri   s      rO   r   r   t  s!    IINI%c!iu==rQ   r   c                 l   > T=R                   S-  sl         [        R                  " T" X5      [        S9$ r   )r   r&   asarrayr   r   s      rO   r   r   {  s%    IINI::c!iu==rQ   z `jac` is expected to have shape z, but actually has .rm   )r4   r5   r   r   r	   r   callabler   r&   r   r   r!   r=   
ValueError)ri   r   r   r   r   groupsr   r   s   ```     rO   r   Radau._validate_jac\  s   VVVV;#H%%)(3H&x0$f- BDFF+A@ ~? c]]BADI{{qM> >
 JJq.> > ww466466** #CTVVTVVDTCU V667ggYa"A B B + ~ }}sOJJs%0ww466466** #CTVVTVVDTCU V667ggYa"A B BK~rQ   c                 
   U R                   nU R                  nU R                  nU R                  nU R                  nU R
                  nS[        R                  " [        R                  " XR                  [        R                  -  5      U-
  5      -  nU R                  U:  a  UnS n	S n
O;U R                  U:  a  UnS n	S n
O$U R                  nU R                  n	U R                  n
U R                  nU R                  nU R                   nU R"                  nU R$                  nSnSnS nU(       Gd  X:  a  SU R&                  4$ XR                  -  nUU-   nU R                  UU R(                  -
  -  S:  a  U R(                  nUU-
  n[        R                  " U5      nU R*                  c&  [        R,                  " SUR.                  S   45      nO(U R+                  UU[0        -  -   5      R2                  U-
  nU[        R                  " U5      U-  -   nSnU(       d  Ub  UcP  U R5                  [6        U-  U R8                  -  U-
  5      nU R5                  [:        U-  U R8                  -  U-
  5      n[=        U R>                  XUUUU R@                  XU RB                  5
      u  nnnnU(       d   U(       a  O!U R%                  XU5      nSnS nS nU(       d  M  U(       d  US-  nS nS nGM  UWS   -   nUR2                  RE                  [F        5      U-  nU RC                  XU-   5      nU[        RH                  " [        R                  " U5      [        R                  " U5      5      U-  -   n[K        UU-  5      nSS	[L        -  S
-   -  S	[L        -  W-   -  nU(       a:  US
:  a4  U RC                  XR?                  XU-   5      U-   5      n[K        UU-  5      nUS
:  a*  [O        XUU
5      n U[Q        [R        UU -  5      -  nS nS nSnOSnU(       d  GM  US L=(       a    WS	:  =(       a    WS:  n![O        XWU
5      n [U        [V        WU -  5      n U!(       d	  U S:  a  S
n OS nS nU R?                  WW5      n"U!(       a  U" UUU"5      nSnOUb  SnU R                  U l        UU l        UU -  U l        X l,        UU l         UU l        U"U l        WU l-        Xl        Xl        Xl        Xl        Xl.        U R_                  5       U l        UU4$ )Nr   Fr   r   Trc   r   g?r   r
   ra   g333333?)0r4   r5   r   r|   r~   r}   r&   abs	nextafterr   infrW   rX   rZ   r   r:   r;   r   r   TOO_SMALL_STEPr   r   zerosr!   r(   r.   rj   r"   r   r#   rP   r3   r   r<   r%   Emaximumr   r+   r]   r   
MIN_FACTORrV   
MAX_FACTORr{   rA   t_old_compute_dense_output)#ri   r4   r5   r   r|   r~   r}   min_steprW   rX   rZ   r   r:   r;   r   r   rejectedstep_acceptedmessager6   t_newr7   r8   rF   n_iterrA   rG   y_newZEerrorrY   safetyr\   recompute_jacf_news#                                      rO   
_step_implRadau._step_impl  s   FFFFFF==yyyyr||A~~/FG!KLL:: EI!NZZ("EI!NJJEI!00NFF,,__
&&hhd1111&AEE~~!56:	AFF1IExxXXq!''!*o.XXa!a%i(**Q.266!9t++EI?j&8"gggkDFF&:Q&>?G!%a$&&)@1)D!EJ-EHHaAr5$//.8*	61d !"q)A"&K"G!%J!  i$ !
"IEaBMM'r62E2::bffQi?$FFEeem,JA.23q>7I9?8@ AF JNgxxu9/E/JK!%%-0
A~'(2NDZ&99!
 $E  -H 4FFQJF4$;*nMZ&1#FGJ&E5%(AK_K(V^

$&
--/g%%rQ   c                     [         R                  " U R                  R                  [        5      n[        U R                  U R                  U R                  U5      $ rm   )	r&   r%   rA   r.   PRadauDenseOutputr   r4   r{   )ri   Qs     rO   r   Radau._compute_dense_output  s7    FF46688Q

DFFDJJBBrQ   c                     U R                   $ rm   )r   )ri   s    rO   _dense_output_implRadau._dense_output_impl!  s    xxrQ   )r   r   r;   r:   rA   r~   r   rZ   r   rW   rX   r   r   rj   r|   r   r   r}   r   r<   r4   r   r5   r{   )__name__
__module____qualname____firstlineno____doc__r&   r   rz   r   r   r   r   __static_attributes____classcell__r   s   @rO   r_   r_      sD    rf 79ff4d!d3j1fL&\C rQ   r_   c                   .   ^  \ rS rSrU 4S jrS rSrU =r$ )r   i%  c                 |   > [         TU ]  X5        X!-
  U l        X@l        UR                  S   S-
  U l        X0l        g re   )ry   rz   r6   r   r!   orderr{   )ri   r   r4   r{   r   r   s        rO   rz   RadauDenseOutput.__init__&  s6    "WWQZ!^

rQ   c                    XR                   -
  U R                  -  nUR                  S:X  a:  [        R                  " X R
                  S-   5      n[        R                  " U5      nO:[        R                  " X R
                  S-   S45      n[        R                  " USS9n[        R                  " U R                  U5      nUR                  S:X  a  X@R                  S S 2S 4   -  nU$ X@R                  -  nU$ )Nr   r
   )axisr   )
r   r6   ndimr&   tiler   cumprodr%   r   r{   )ri   r4   xpr5   s        rO   
_call_implRadauDenseOutput._call_impl-  s    ^tvv%66Q;::>*A

1AJJNA./A

11%AFF466166Q;AtG$$A  OArQ   )r   r6   r   r{   )r   r   r   r   rz   r   r   r   r   s   @rO   r   r   %  s     rQ   r   )+numpyr&   scipy.linalgr   r   scipy.sparser   r   r   scipy.sparse.linalgr   scipy.optimize._numdiffr	   commonr   r   r   r   r   r   r   r   baser   r   S6arrayr(   r   r"   r#   r.   r$   r/   r0   r   r+   r   r   rP   r]   r_   r    rQ   rO   <module>r      s    , 2 2 $ 1* * * ) HHq2vma"f]A./HHcAFlC!b&L"-.2 *5
 HHDD  XXCEDF G
 Q%UR"Q%Z
 HH	AbDF]EBrE!GOTAF]3	AbDF]EBrE!GOTAF]3  

X%v%PoI od{ rQ   