← Back
Editing: _lti_conversion.cpython-311.pyc
� d�c? � � � d Z ddlZddlZddlmZmZmZmZmZmZm Z m Z mZmZ ddl mZ ddlmZmZmZ g d�Zd� Zd � Zd � Zd� Zd� Zd � Zdd�Zdd�Zd� Zdd�Zdd�ZdS )zr ltisys -- a collection of functions to convert linear time invariant systems from one representation to another. � N) �r_�eye� atleast_2d�poly�dot�asarray�prod�zeros�array�outer)�linalg� )�tf2zpk�zpk2tf� normalize)�tf2ss�abcd_normalize�ss2tf�zpk2ss�ss2zpk� cont2discretec �� � t | |� � \ } }t | j � � }|dk rt | g| j � � } | j d }t |� � }||k rd}t |� � �|dk s|dk rRt g t � � t g t � � t g t � � t g t � � fS t dt | j d ||z f| j � � | f } | j d dk rt | dd�df � � }nt dggt � � }|dk ra|� | j � � }t d� � t d|j d f� � t |j d df� � |fS t |dd� g� � }t |t |dz |dz � � f }t |dz d� � } | dd�dd�f t | dd�df |dd� � � z } |� | j d | j d f� � }|| | |fS ) a� Transfer function to state-space representation. Parameters ---------- num, den : array_like Sequences representing the coefficients of the numerator and denominator polynomials, in order of descending degree. The denominator needs to be at least as long as the numerator. Returns ------- A, B, C, D : ndarray State space representation of the system, in controller canonical form. Examples -------- Convert the transfer function: .. math:: H(s) = \frac{s^2 + 3s + 3}{s^2 + 2s + 1} >>> num = [1, 3, 3] >>> den = [1, 2, 1] to the state-space representation: .. math:: \dot{\textbf{x}}(t) = \begin{bmatrix} -2 & -1 \\ 1 & 0 \end{bmatrix} \textbf{x}(t) + \begin{bmatrix} 1 \\ 0 \end{bmatrix} \textbf{u}(t) \\ \textbf{y}(t) = \begin{bmatrix} 1 & 2 \end{bmatrix} \textbf{x}(t) + \begin{bmatrix} 1 \end{bmatrix} \textbf{u}(t) >>> from scipy.signal import tf2ss >>> A, B, C, D = tf2ss(num, den) >>> A array([[-2., -1.], [ 1., 0.]]) >>> B array([[ 1.], [ 0.]]) >>> C array([[ 1., 2.]]) >>> D array([[ 1.]]) r z7Improper transfer function. `num` is longer than `den`.r z-1���N)r r � )r �len�shaper �dtype� ValueErrorr �floatr r r �reshaper r )�num�den�nn�M�K�msg�D�frow�A�B�Cs �>/usr/lib/python3/dist-packages/scipy/signal/_lti_conversion.pyr r s= � �p ��c�"�"�H�C�� �S�Y���B� �Q�w�w��s�e�S�Y�'�'��� �!��A��C���A��1�u�u�G����o�o���A�v�v��a����b�%� � �%��E�"2�"2�E�"�e�4D�4D��b�%� � �"� "� �T�5�#�)�A�,��A��.�� �:�:�C� ?� @�C� �y��}�q����s�1�1�1�a�4�y�!�!��� �A�3�%������A�v�v� �I�I�c�i� � ���f� � �u�a�����_�5�5��q�w�q�z�1�o�&�&��+� +� �3�q�r�r�7�)����D� �4��Q��U�A��E�"�"�"�#�A��A��E�1� � �A��A�A�A�q�r�r�E� �U�3�q�q�q�!�t�9�c�!�"�"�g�.�.�.�A� � � �1�7�1�:�q�w�q�z�*�+�+�A��a��A�:�� c �( � | �t d� � S | S )N�r r )r ��args r, �_none_to_empty_2dr2 s s � � �{��V�}�}��� r- c �( � | �t | � � S d S �N)r r0 s r, �_atleast_2d_or_noner5 z s � � ���#���� �r- c � � | �| j S dS )N)NN)r )r$ s r, �_shape_or_noner7 s � ��}��w���{r- c � � | D ]}|�|c S � d S r4 � )�argsr1 s r, �_choice_not_noner; � s. � �� � ���?��J�J�J� �� r- c �n � | j dk rt |� � S | j |k rt d� � �| S )Nr/ z*The input arrays have incompatible shapes.)r r r )r$ r s r, �_restorer= � s<