| Server IP : 217.160.0.135 / Your IP : 216.73.217.85 Web Server : Apache System : Linux www 6.18.52-i1-ampere #1203 SMP Mon Sep 14 18:29:59 CEST 2026 aarch64 User : sws1074145052 ( 1074145052) PHP Version : 8.3.32 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /lib/python3/dist-packages/scipy/linalg/__pycache__/ |
Upload File : |
�
d�c�n � �� � d Z ddlZddlZddlmZmZmZmZm Z ddl
mZmZm
Z
ddlmZ ddlmZ ddlmZ dd lmZ dd
lmZ ddlmZ ddlmZmZ g d
�Zd� Zd� ZeZ d� Z!d� Z"dd�Z#dd�Z$dd�Z%dd�Z&dS )zMatrix equation solver routines� N)�inv�LinAlgError�norm�cond�svd� )�solve�solve_triangular�matrix_balance)�get_lapack_funcs)�schur)�lu)�qr)�ordqz)�_asarray_validated)�kron�
block_diag)�solve_sylvester�solve_continuous_lyapunov�solve_discrete_lyapunov�solve_lyapunov�solve_continuous_are�solve_discrete_arec �z � t | d�� � \ }}t |� � � � � � d�� � \ }}t j t j |� � � � � � |� � |� � }t d|||f� � \ }|�t
d� � � ||||d�� � \ } }
}|
| z } |dk rt d | fz � � �t j t j || � � |� � � � � � � � S )
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
�real��output)�trsylNzQLAPACK implementation does not contain a proper Sylvester equation solver (TRSYL)�C��tranbr z(Illegal value encountered in the %d term)r
�conj� transpose�np�dotr �RuntimeErrorr )�a�b�q�r�u�s�v�fr �y�scale�infos �7/usr/lib/python3/dist-packages/scipy/linalg/_solvers.pyr r s7 � �n ��6�"�"�"�D�A�q� ������#�#�%�%�f�5�5�5�D�A�q� ��r�v�a�f�f�h�h�(�(�*�*�A�.�.��2�2�A� �j�1�a��)�
4�
4�F�E��}�� ?� @� @� @��U�1�a��#�.�.�.�N�A�u�d�
�a��A��a�x�x�� (�,0�5�(�3� 4� 4� 4� �6�"�&��A�,�,������ 2� 2� 4� 4�5�5�5� c �� � t j t | d�� � � � } t j t |d�� � � � }t }t | |f� � D ][\ }}t j |� � rt }t j |j � s(t d�
d| � � � � ��\| j |j k rt d� � �t | d�� � \ }}|� � � j
� |� |� � � � }t d||f� � }|t k rd nd
} ||||| �� � \ }
}}|dk r#t d
�
| � � � � �|dk rt! j dt$ � � |
|z }
|� |
� � � |� � � j
� � S )a�
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 {} should be square.�aq�*Matrix a and q should have the same shape.r r r �Tr r r z�?TRSYL exited with the internal error "illegal value in argument number {}.". See LAPACK documentation for the ?TRSYL error codes.r z�Input "a" has an eigenvalue pair whose sum is very close to or exactly zero. The solution is obtained via perturbing the coefficients.)r$ �
atleast_2dr �float� enumerate�iscomplexobj�complex�equal�shape�
ValueError�formatr
r"