
    (php                         S r SSKrSSKrSSKJrJrJr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  SS	KJr  SS
KJr  SSKJr  SSKJr  / SQrS rS r\rS r S r!SS jr"SS jr#SS jr$SS jr%g)zMatrix equation solver routines    N)invLinAlgErrornormcondsvd   )solvesolve_triangularmatrix_balance)get_lapack_funcs)schur)lu)qr)ordqz)_asarray_validated)
block_diag)solve_sylvestersolve_continuous_lyapunovsolve_discrete_lyapunovsolve_lyapunovsolve_continuous_aresolve_discrete_arec                 >   U R                   S:X  d  UR                   S:X  ax  [        R                  [        R                  [        R                  [        R
                  S.n[        SXU4S9u  n[        R                  " UR                  X4R                     S9$ [        U SS9u  pV[        UR                  5       R                  5       SS9u  px[        R                  " [        R                  " UR                  5       R                  5       U5      U5      n	[        SXWU	45      u  n
U
c  [        S5      eU
" XWU	S	S
9u  pnX-  nUS:  a  [        SU* 4-  5      e[        R                  " [        R                  " Xk5      UR                  5       R                  5       5      $ )a  
Computes a solution (X) to the Sylvester equation :math:`AX + XB = Q`.

Parameters
----------
a : (M, M) array_like
    Leading matrix of the Sylvester equation
b : (N, N) array_like
    Trailing matrix of the Sylvester equation
q : (M, N) array_like
    Right-hand side

Returns
-------
x : (M, N) ndarray
    The solution to the Sylvester equation.

Raises
------
LinAlgError
    If solution was not found

Notes
-----
Computes a solution to the Sylvester matrix equation via the Bartels-
Stewart algorithm. The A and B matrices first undergo Schur
decompositions. The resulting matrices are used to construct an
alternative Sylvester equation (``RY + YS^T = F``) where the R and S
matrices are in quasi-triangular form (or, when R, S or F are complex,
triangular form). The simplified equation is then solved using
``*TRSYL`` from LAPACK directly.

.. versionadded:: 0.11.0

Examples
--------
Given `a`, `b`, and `q` solve for `x`:

>>> import numpy as np
>>> from scipy import linalg
>>> a = np.array([[-3, -2, 0], [-1, -1, 3], [3, -5, -1]])
>>> b = np.array([[1]])
>>> q = np.array([[1],[2],[3]])
>>> x = linalg.solve_sylvester(a, b, q)
>>> x
array([[ 0.0625],
       [-0.5625],
       [ 0.6875]])
>>> np.allclose(a.dot(x) + x.dot(b), q)
True

r   sdcztrsylarraysdtyperealoutputzQLAPACK implementation does not contain a proper Sylvester equation solver (TRSYL)Ctranbz(Illegal value encountered in the %d term)sizenpfloat32float64	complex64
complex128r   emptyshapetypecoder   conj	transposedotRuntimeErrorr   )abqtdictfuncrur   vfr    yscaleinfos                 H/var/www/html/venv/lib/python3.13/site-packages/scipy/linalg/_solvers.pyr   r      sY   l 	vv{affkjjrzzll8 Q1I>xxu]]';<< 6"DA ##%f5DA 	rvvaffh((*A.2A j1)4FE} ? @ 	@1#.NAdAax (,05(3 4 	4 66"&&, 2 2 455    c                 f   [         R                  " [        U SS95      n [         R                  " [        USS95      n[        n[	        X45       HZ  u  p4[         R
                  " U5      (       a  [        n[         R                  " UR                  6 (       a  MJ  [        SSU    S35      e   U R                  UR                  :w  a  [        S5      eU R                  S:X  aw  [         R                  [         R                  [         R                  [         R                  S.n[        S	X4S
9u  n[         R                   " U R                  XVR"                     S9$ [%        U SS9u  pxUR'                  5       R(                  R+                  UR+                  U5      5      n	[        SXy45      n
U[        L a  SOSnU
" XwXS9u  pnUS:  a  [        SU*  S35      eUS:X  a  [,        R.                  " S[0        SS9  X-  nUR+                  U5      R+                  UR'                  5       R(                  5      $ )a5  
Solves the continuous Lyapunov equation :math:`AX + XA^H = Q`.

Uses the Bartels-Stewart algorithm to find :math:`X`.

Parameters
----------
a : array_like
    A square matrix

q : array_like
    Right-hand side square matrix

Returns
-------
x : ndarray
    Solution to the continuous Lyapunov equation

See Also
--------
solve_discrete_lyapunov : computes the solution to the discrete-time
    Lyapunov equation
solve_sylvester : computes the solution to the Sylvester equation

Notes
-----
The continuous Lyapunov equation is a special form of the Sylvester
equation, hence this solver relies on LAPACK routine ?TRSYL.

.. versionadded:: 0.11.0

Examples
--------
Given `a` and `q` solve for `x`:

>>> import numpy as np
>>> from scipy import linalg
>>> a = np.array([[-3, -2, 0], [-1, -1, 0], [0, -5, -1]])
>>> b = np.array([2, 4, -1])
>>> q = np.eye(3)
>>> x = linalg.solve_continuous_lyapunov(a, q)
>>> x
array([[ -0.75  ,   0.875 ,  -3.75  ],
       [  0.875 ,  -1.375 ,   5.3125],
       [ -3.75  ,   5.3125, -27.0625]])
>>> np.allclose(a.dot(x) + x.dot(a.T), q)
True
Tcheck_finiteMatrix aq should be square.*Matrix a and q should have the same shape.r   r   r   r!   r#   r%   r&   r    Tr(   r)   zH?TRSYL exited with the internal error "illegal value in argument number z8.". See LAPACK documentation for the ?TRSYL error codes.r   zInput "a" has an eigenvalue pair whose sum is very close to or exactly zero. The solution is obtained via perturbing the coefficients.   )
stacklevel)r,   
atleast_2dr   float	enumerateiscomplexobjcomplexequalr2   
ValueErrorr+   r-   r.   r/   r0   r   r1   r3   r   r4   rM   r6   warningswarnRuntimeWarning)r8   r:   r_or_cind_r;   r<   r=   r>   r@   r    dtype_stringrA   rB   rC   s                  rD   r   r   s   s   d 	(>?A
(>?AFQF#??1Fxx!!wtCyk1CDEE $ 	ww!''EFF 	vv{jjrzzll8 QF;xxu]]';<< 6"DA 	


quuQx A Wqf-E E/3sL17NAdax >?CeW ELL M 	M 
 B %	4 JA558<<

##rE   c                    [         R                  " X R                  5       5      n[         R                  " UR                  S   5      U-
  n[        X!R                  5       5      n[         R                  " X1R                  5      $ )z
Solves the discrete Lyapunov equation directly.

This function is called by the `solve_discrete_lyapunov` function with
`method=direct`. It is not supposed to be called directly.
r   )r,   kronr4   eyer2   r	   flattenreshape)r8   r:   lhsxs       rD   _solve_discrete_lyapunov_directre      sV     ''!VVX
C
&&1

$Cc99;A::a!!rE   c           	         [         R                  " U R                  S   5      nU R                  5       R	                  5       n[        X2-   5      n[         R                  " X2-
  U5      nS[         R                  " [         R                  " [        X-   5      U5      U5      -  n[        UR                  5       R	                  5       U* 5      $ )z
Solves the discrete Lyapunov equation using a bilinear transformation.

This function is called by the `solve_discrete_lyapunov` function with
`method=bilinear`. It is not supposed to be called directly.
r   rN   )r,   r`   r2   r4   r5   r   r6   r   )r8   r:   r`   aHaHI_invr9   r   s          rD   !_solve_discrete_lyapunov_bilinearri      s     &&
C	
			B"(mG
rx!A	"&&AGa('
22A!&&(,,.33rE   c                    [         R                  " U 5      n [         R                  " U5      nUc  U R                  S   S:  a  SnOSnUR                  5       nUS:X  a  [	        X5      nU$ US:X  a  [        X5      nU$ [        SU 35      e)a5  
Solves the discrete Lyapunov equation :math:`AXA^H - X + Q = 0`.

Parameters
----------
a, q : (M, M) array_like
    Square matrices corresponding to A and Q in the equation
    above respectively. Must have the same shape.

method : {'direct', 'bilinear'}, optional
    Type of solver.

    If not given, chosen to be ``direct`` if ``M`` is less than 10 and
    ``bilinear`` otherwise.

Returns
-------
x : ndarray
    Solution to the discrete Lyapunov equation

See Also
--------
solve_continuous_lyapunov : computes the solution to the continuous-time
    Lyapunov equation

Notes
-----
This section describes the available solvers that can be selected by the
'method' parameter. The default method is *direct* if ``M`` is less than 10
and ``bilinear`` otherwise.

Method *direct* uses a direct analytical solution to the discrete Lyapunov
equation. The algorithm is given in, for example, [1]_. However, it requires
the linear solution of a system with dimension :math:`M^2` so that
performance degrades rapidly for even moderately sized matrices.

Method *bilinear* uses a bilinear transformation to convert the discrete
Lyapunov equation to a continuous Lyapunov equation :math:`(BX+XB'=-C)`
where :math:`B=(A-I)(A+I)^{-1}` and
:math:`C=2(A' + I)^{-1} Q (A + I)^{-1}`. The continuous equation can be
efficiently solved since it is a special case of a Sylvester equation.
The transformation algorithm is from Popov (1964) as described in [2]_.

.. versionadded:: 0.11.0

References
----------
.. [1] "Lyapunov equation", Wikipedia,
   https://en.wikipedia.org/wiki/Lyapunov_equation#Discrete_time
.. [2] Gajic, Z., and M.T.J. Qureshi. 2008.
   Lyapunov Matrix Equation in System Stability and Control.
   Dover Books on Engineering Series. Dover Publications.

Examples
--------
Given `a` and `q` solve for `x`:

>>> import numpy as np
>>> from scipy import linalg
>>> a = np.array([[0.2, 0.5],[0.7, -0.9]])
>>> q = np.eye(2)
>>> x = linalg.solve_discrete_lyapunov(a, q)
>>> x
array([[ 0.70872893,  1.43518822],
       [ 1.43518822, -2.4266315 ]])
>>> np.allclose(a.dot(x).dot(a.T)-x, -q)
True

r   
   bilineardirectzUnknown solver )r,   asarrayr2   lowerre   ri   rV   )r8   r:   methodmethrd   s        rD   r   r      s    L 	

1A


1A~771:FF<<>Dx+A1 H 
	-a3 H ?6(344rE   c           
      
   [        XX#XES5      u
  pp#pEpxp[        R                  " SU-  U-   SU-  U-   4U	S9nXSU2SU24'   SUSU2USU-  24'   XSU2SU-  S24'   U* XSU-  2SU24'   U R                  5       R                  * XSU-  2USU-  24'   Uc  SOU* XSU-  2SU-  S24'   Uc  SOUR                  5       R                  USU-  S2SU24'   UR                  5       R                  USU-  S2USU-  24'   X;SU-  S2SU-  S24'   U
(       a:  Ub7  [        XDR                  5       R                  [        R                  " X9S95      nO5[        [        R                  " SU-  5      [        R                  " X9S95      nU(       Ga  [        R                  " U5      [        R                  " U5      -   n[        R                  " US5        [        USSS9u  nu  p[        R                  " U[        R                  " U5      5      (       d  [        R                  " U5      n[        R                  " XSU-   USU -
  S-  5      nS[        R                  XU* USU-  S 4   -  nUSS2S4   [        R                   " U5      -  nUU-  nUU-  n[#        USS2U* S24   5      u  p#USS2US24   R                  5       R                  R%                  USS2SSU-  24   5      nUSSU-  2US24   R                  5       R                  R%                  USSU-  2SSU-  24   5      nU	[&        L a  S	OS
n[)        XSSSSUS9u          nnUbE  [#        [        R*                  " UR%                  USU2SU24   5      UUS2SU24   45      5      u  nnUSU2SU24   nUUS2SU24   n[-        U5      u  nnnS[/        U5      -  [        R0                  " S5      :  a  [3        S5      e[5        UR                  5       R                  [5        UR                  5       R                  UR                  5       R                  SS9SS9R                  5       R                  R%                  UR                  5       R                  5      nU(       a  UWSU2S4   USU -  -  nUR                  5       R                  R%                  U5      n[7        US5      nUUR                  5       R                  -
  n[        R8                  " [        R0                  " S5      SU-  /5      n[7        US5      U:  a  [3        S5      eUUR                  5       R                  -   S-  $ )a  
Solves the continuous-time algebraic Riccati equation (CARE).

The CARE is defined as

.. math::

      X A + A^H X - X B R^{-1} B^H X + Q = 0

The limitations for a solution to exist are :

    * All eigenvalues of :math:`A` on the right half plane, should be
      controllable.

    * The associated hamiltonian pencil (See Notes), should have
      eigenvalues sufficiently away from the imaginary axis.

Moreover, if ``e`` or ``s`` is not precisely ``None``, then the
generalized version of CARE

.. math::

      E^HXA + A^HXE - (E^HXB + S) R^{-1} (B^HXE + S^H) + Q = 0

is solved. When omitted, ``e`` is assumed to be the identity and ``s``
is assumed to be the zero matrix with sizes compatible with ``a`` and
``b``, respectively.

Parameters
----------
a : (M, M) array_like
    Square matrix
b : (M, N) array_like
    Input
q : (M, M) array_like
    Input
r : (N, N) array_like
    Nonsingular square matrix
e : (M, M) array_like, optional
    Nonsingular square matrix
s : (M, N) array_like, optional
    Input
balanced : bool, optional
    The boolean that indicates whether a balancing step is performed
    on the data. The default is set to True.

Returns
-------
x : (M, M) ndarray
    Solution to the continuous-time algebraic Riccati equation.

Raises
------
LinAlgError
    For cases where the stable subspace of the pencil could not be
    isolated. See Notes section and the references for details.

See Also
--------
solve_discrete_are : Solves the discrete-time algebraic Riccati equation

Notes
-----
The equation is solved by forming the extended hamiltonian matrix pencil,
as described in [1]_, :math:`H - \lambda J` given by the block matrices ::

    [ A    0    B ]             [ E   0    0 ]
    [-Q  -A^H  -S ] - \lambda * [ 0  E^H   0 ]
    [ S^H B^H   R ]             [ 0   0    0 ]

and using a QZ decomposition method.

In this algorithm, the fail conditions are linked to the symmetry
of the product :math:`U_2 U_1^{-1}` and condition number of
:math:`U_1`. Here, :math:`U` is the 2m-by-m matrix that holds the
eigenvectors spanning the stable subspace with 2-m rows and partitioned
into two m-row matrices. See [1]_ and [2]_ for more details.

In order to improve the QZ decomposition accuracy, the pencil goes
through a balancing step where the sum of absolute values of
:math:`H` and :math:`J` entries (after removing the diagonal entries of
the sum) is balanced following the recipe given in [3]_.

.. versionadded:: 0.11.0

References
----------
.. [1]  P. van Dooren , "A Generalized Eigenvalue Approach For Solving
   Riccati Equations.", SIAM Journal on Scientific and Statistical
   Computing, Vol.2(2), :doi:`10.1137/0902010`

.. [2] A.J. Laub, "A Schur Method for Solving Algebraic Riccati
   Equations.", Massachusetts Institute of Technology. Laboratory for
   Information and Decision Systems. LIDS-R ; 859. Available online :
   http://hdl.handle.net/1721.1/1301

.. [3] P. Benner, "Symplectic Balancing of Hamiltonian Matrices", 2001,
   SIAM J. Sci. Comput., 2001, Vol.22(5), :doi:`10.1137/S1064827500367993`

Examples
--------
Given `a`, `b`, `q`, and `r` solve for `x`:

>>> import numpy as np
>>> from scipy import linalg
>>> a = np.array([[4, 3], [-4.5, -3.5]])
>>> b = np.array([[1], [-1]])
>>> q = np.array([[9, 6], [6, 4.]])
>>> r = 1
>>> x = linalg.solve_continuous_are(a, b, q, r)
>>> x
array([[ 21.72792206,  14.48528137],
       [ 14.48528137,   9.65685425]])
>>> np.allclose(a.T.dot(x) + x.dot(a)-x.dot(b).dot(b.T).dot(x), -q)
True

carerN   r#   N        r   r   separatepermuter%   rT   lhpTFsortoverwrite_aoverwrite_brH   r'         ?!Failed to find a finite solution.ro   unit_diagonal     @@皙?zQThe associated Hamiltonian pencil has eigenvalues too close to the imaginary axis)_are_validate_argsr,   r1   r4   rM   r   
zeros_liker`   absfill_diagonalr   allclose	ones_likelog2roundr_
reciprocalr   r6   rQ   r   vstackr   r   spacingr   r
   r   max)r8   r9   r:   r=   er   balancedmnrZ   gen_areHJMr\   scaelwisescaleout_strr>   u00u10upuluurd   u_symn_u_symsym_thresholds                               rD   r   r   S  s   p /A561v/O+A!aF 	!A#a%1Qv.Abqb"1"fIAbqb!AaC%iLbqb!A#$hK2A!eRaRiLvvxzzkA!eQqsUlO9R1"A!eQqSTkN	"qvvxzzAacdBQBhKVVXZZAacdAacEkNacdAaCDjM1=q&&(**bmmA&DErvvac{BMM!$BC FF1Iq	!
B$QA>8C{{3S 122 ''#,C#!*s2Aw.12AruuQC!I-..Cag,s);;KAA aA23i=DA	!QR%a4AaC4j)A	$1Q3$(  4AaC4!A#:/A %fYGQ4)-E$+-Aq!Q1
 	}"))QUU1RaR!V9-qRaRy9:;1
BQBF)C
ABF)C CJBBbzBJJrN"=>> 	)"'')++*-((*,,046 (,		
  46!!CC	$4  	S!T]S!W$$ HHJLLS!E5!nGEJJLNN"EFFBJJu-s7{;<ME1~% < = 	= 

NArE   c           
      
   [        XX#XES5      u
  pp#pEpxp[        R                  " SU-  U-   SU-  U-   4U	S9nXSU2SU24'   XSU2SU-  S24'   U* XSU-  2SU24'   Uc  [        R                  " U5      OUR	                  5       R
                  XSU-  2USU-  24'   Uc  SOU* XSU-  2SU-  S24'   Uc  SOUR	                  5       R
                  USU-  S2SU24'   X;SU-  S2SU-  S24'   [        R                  " XS9nUc  [        R                  " U5      OUUSU2SU24'   U R	                  5       R
                  XSU-  2USU-  24'   UR	                  5       R
                  * USU-  S2USU-  24'   U(       Ga  [        R                  " U5      [        R                  " U5      -   n[        R                  " US5        [        USSS9u  nu  p[        R                  " U[        R                  " U5      5      (       d  [        R                  " U5      n[        R                  " XSU-   USU -
  S-  5      nS[        R                  XU* USU-  S 4   -  nUSS2S4   [        R                  " U5      -  nUU-  nUU-  n[!        USS2U* S24   5      u  nnUSS2US24   R	                  5       R
                  R#                  USS2SSU-  24   5      nUSS2US24   R	                  5       R
                  R#                  USS2SSU-  24   5      nU	[$        L a  S	OS
n['        XSSSSUS9u          nnUbE  [!        [        R(                  " UR#                  USU2SU24   5      UUS2SU24   45      5      u  nnUSU2SU24   nUUS2SU24   n[+        U5      u  nnnS[-        U5      -  [        R.                  " S5      :  a  [1        S5      e[3        UR	                  5       R
                  [3        UR	                  5       R
                  UR	                  5       R
                  SS9SS9R	                  5       R
                  R#                  UR	                  5       R
                  5      nU(       a  UWSU2S4   USU -  -  nUR	                  5       R
                  R#                  U5      n[5        US5      nUUR	                  5       R
                  -
  n[        R6                  " [        R.                  " S5      SU-  /5      n[5        US5      U:  a  [1        S5      eUUR	                  5       R
                  -   S-  $ )a  
Solves the discrete-time algebraic Riccati equation (DARE).

The DARE is defined as

.. math::

      A^HXA - X - (A^HXB) (R + B^HXB)^{-1} (B^HXA) + Q = 0

The limitations for a solution to exist are :

    * All eigenvalues of :math:`A` outside the unit disc, should be
      controllable.

    * The associated symplectic pencil (See Notes), should have
      eigenvalues sufficiently away from the unit circle.

Moreover, if ``e`` and ``s`` are not both precisely ``None``, then the
generalized version of DARE

.. math::

      A^HXA - E^HXE - (A^HXB+S) (R+B^HXB)^{-1} (B^HXA+S^H) + Q = 0

is solved. When omitted, ``e`` is assumed to be the identity and ``s``
is assumed to be the zero matrix.

Parameters
----------
a : (M, M) array_like
    Square matrix
b : (M, N) array_like
    Input
q : (M, M) array_like
    Input
r : (N, N) array_like
    Square matrix
e : (M, M) array_like, optional
    Nonsingular square matrix
s : (M, N) array_like, optional
    Input
balanced : bool
    The boolean that indicates whether a balancing step is performed
    on the data. The default is set to True.

Returns
-------
x : (M, M) ndarray
    Solution to the discrete algebraic Riccati equation.

Raises
------
LinAlgError
    For cases where the stable subspace of the pencil could not be
    isolated. See Notes section and the references for details.

See Also
--------
solve_continuous_are : Solves the continuous algebraic Riccati equation

Notes
-----
The equation is solved by forming the extended symplectic matrix pencil,
as described in [1]_, :math:`H - \lambda J` given by the block matrices ::

       [  A   0   B ]             [ E   0   B ]
       [ -Q  E^H -S ] - \lambda * [ 0  A^H  0 ]
       [ S^H  0   R ]             [ 0 -B^H  0 ]

and using a QZ decomposition method.

In this algorithm, the fail conditions are linked to the symmetry
of the product :math:`U_2 U_1^{-1}` and condition number of
:math:`U_1`. Here, :math:`U` is the 2m-by-m matrix that holds the
eigenvectors spanning the stable subspace with 2-m rows and partitioned
into two m-row matrices. See [1]_ and [2]_ for more details.

In order to improve the QZ decomposition accuracy, the pencil goes
through a balancing step where the sum of absolute values of
:math:`H` and :math:`J` rows/cols (after removing the diagonal entries)
is balanced following the recipe given in [3]_. If the data has small
numerical noise, balancing may amplify their effects and some clean up
is required.

.. versionadded:: 0.11.0

References
----------
.. [1]  P. van Dooren , "A Generalized Eigenvalue Approach For Solving
   Riccati Equations.", SIAM Journal on Scientific and Statistical
   Computing, Vol.2(2), :doi:`10.1137/0902010`

.. [2] A.J. Laub, "A Schur Method for Solving Algebraic Riccati
   Equations.", Massachusetts Institute of Technology. Laboratory for
   Information and Decision Systems. LIDS-R ; 859. Available online :
   http://hdl.handle.net/1721.1/1301

.. [3] P. Benner, "Symplectic Balancing of Hamiltonian Matrices", 2001,
   SIAM J. Sci. Comput., 2001, Vol.22(5), :doi:`10.1137/S1064827500367993`

Examples
--------
Given `a`, `b`, `q`, and `r` solve for `x`:

>>> import numpy as np
>>> from scipy import linalg as la
>>> a = np.array([[0, 1], [0, -1]])
>>> b = np.array([[1, 0], [2, 1]])
>>> q = np.array([[-4, -4], [-4, 7]])
>>> r = np.array([[9, 3], [3, 1]])
>>> x = la.solve_discrete_are(a, b, q, r)
>>> x
array([[-4., -4.],
       [-4.,  7.]])
>>> R = la.solve(r + b.T.dot(x).dot(b), b.T.dot(x).dot(a))
>>> np.allclose(a.T.dot(x).dot(a) - x - a.T.dot(x).dot(b).dot(R), -q)
True

darerN   r#   Nrt   r   r   ru   r%   rT   iucTFry   r}   r~   r   r   r   r   zMThe associated symplectic pencil has eigenvalues too close to the unit circle)r   r,   zerosr`   r4   rM   r   r   r   r   r   r   r   r   r   r   r   r6   rQ   r   r   r   r   r   r   r
   r   r   )r8   r9   r:   r=   r   r   r   r   r   rZ   r   r   r   r   r\   r   r   q_of_qrr   r>   r   r   r   r   r   rd   r   r   r   s                                rD   r   r      s
   t /A561v/O+A!aF 	!A#a%1Qv.Abqb"1"fIbqb!A#$hK2A!eRaRiL#$9bffQi!&&(**A!eQqsUlO9R1"A!eQqSTkN	"qvvxzzAacdBQBhKacdAaCDjM
a&AYq	AAbqb"1"fIffhjjA!eQqsUlOffhjj[AacdAacEkN FF1Iq	!
B$QA>8C{{3S 122 ''#,C#!*s2Aw.12AruuQC!I-..Cag,s);;KAA Aa!fIJGQ12##Aa!A#gJ/A12##Aa!A#gJ/A %fYGQ)-)-*/$+	-Aq!Q1 	}"))QUU1RaR!V9-qRaRy9:;1
BQBF)C
ABF)C CJBBbzBJJrN"=>> 	)"'')++*-((*,,046 (,		
  46!!CC	$4  	S!T]S!W$$ HHJLLS!E5!nGEJJLNN"EFFBJJu-s7{;<ME1~% 9 : 	: 

NArE   c           
      D   UR                  5       S;  a  [        S5      e[        R                  " [	        U SS95      n [        R                  " [	        USS95      n[        R                  " [	        USS95      n[        R                  " [	        USS95      n[        R
                  " U5      (       a  [        O[        n[        XU45       HZ  u  p[        R
                  " U	5      (       a  [        n[        R                  " U	R                  6 (       a  MJ  [        SSU    S35      e   UR                  u  pXR                  S   :w  a  [        S	5      eXR                  S   :w  a  [        S
5      eXR                  S   :w  a  [        S5      e[        X#45       Hb  u  p[        XR                  5       R                  -
  S5      [        R                  " [        U	S5      5      S-  :  d  MR  [        SSU    S35      e   US:X  aE  [        USS9S   nUS:X  d'  U[        R                  " S5      [        US5      -  :  a  [        S5      eUSL=(       d    USLnU(       Ga8  Ub  [        R                  " [	        USS95      n[        R                  " UR                  6 (       d  [        S5      eXR                  S   :w  a  [        S5      e[        USS9S   nUS:X  d'  U[        R                  " S5      [        US5      -  :  a  [        S5      e[        R
                  " U5      (       a  [        nUbd  [        R                  " [	        USS95      nUR                  UR                  :w  a  [        S5      e[        R
                  " U5      (       a  [        nXX#XEXX}4
$ )a  
A helper function to validate the arguments supplied to the
Riccati equation solvers. Any discrepancy found in the input
matrices leads to a ``ValueError`` exception.

Essentially, it performs:

    - a check whether the input is free of NaN and Infs
    - a pass for the data through ``numpy.atleast_2d()``
    - squareness check of the relevant arrays
    - shape consistency check of the arrays
    - singularity check of the relevant arrays
    - symmetricity check of the relevant matrices
    - a check whether the regular or the generalized version is asked.

This function is used by ``solve_continuous_are`` and
``solve_discrete_are``.

Parameters
----------
a, b, q, r, e, s : array_like
    Input data
eq_type : str
    Accepted arguments are 'care' and 'dare'.

Returns
-------
a, b, q, r, e, s : ndarray
    Regularized input data
m, n : int
    shape of the problem
r_or_c : type
    Data type of the problem, returns float or complex
gen_or_not : bool
    Type of the equation, True for generalized and False for regular ARE.

)r   rs   z;Equation type unknown. Only 'care' and 'dare' is understoodTrG   rI   aqrrK   r   z3Matrix a and b should have the same number of rows.rL   z3Matrix b and r should have the same number of cols.r   d   r   z should be symmetric/hermitian.rs   F)
compute_uvrt   r}   z!Matrix r is numerically singular.NzMatrix e should be square.z*Matrix a and e should have the same shape.z!Matrix e is numerically singular.z*Matrix b and s should have the same shape.)ro   rV   r,   rP   r   rS   rT   rQ   rR   rU   r2   r   r4   rM   r   r   )r8   r9   r:   r=   r   r   eq_typerZ   r[   matr   r   min_svgeneralized_cases                 rD   r   r     s   N }}.. @ A 	A 	(>?A
(>?A
(>?A
(>?A **WFqQi(??3Fxx##wuSzl2DEFF ) 77DAGGAJNOOGGAJEFFGGAJNOO qf%hhjll"A&DaL)A#)EEwtCyk1PQRR &
 &Q5)"-R<6BJJrN41:$==@AA }5=0FGA88QWW% !=>>GGAJ !MNN u-b1F|v

2a(CC !DEEq!! =0FGAww!''! !MNNq!! qQ6;;rE   )N)NNT)rs   )&__doc__rW   numpyr,   numpy.linalgr   r   r   r   r   _basicr	   r
   r   lapackr   _decomp_schurr   
_decomp_lur   
_decomp_qrr   
_decomp_qzr   _decompr   _special_matricesr   __all__r   r   r   re   ri   r   r   r   r    rE   rD   <module>r      sr    %   : : ; ; $      ' )9R6j`$H +"4XvJZNbh<rE   