o
    h.=                     @   sP  d dl mZ d dlmZ d dlmZ d dlmZmZ d dl	m
Z
 d dlmZmZmZ d dlmZ d dlmZmZmZmZmZmZmZmZmZmZmZ d d	lmZmZm Z m!Z! d d
l"m#Z#m$Z$ edddgie%fdZ&edZ'eded de  d eZ(eeded  de  d eZ)eeed d eZ*eded eZ+eded de  d eZ,eddeZ-ede d ded   de  d ded  ded   d eZ.eded de e  d eZ/ee+eded eZ0ee*eeed eZ1e e(e)Z2dd Z3dd Z4d d! Z5d"d# Z6d$d% Z7d&d' Z8d(d) Z9d*d+ Z:d,d- Z;d.d/ Z<d0S )1    isclose)I)Dummy)Absarg)log)spa)import_module)pole_zero_numerical_datapole_zero_plotstep_response_numerical_datastep_response_plotimpulse_response_numerical_dataimpulse_response_plotramp_response_numerical_dataramp_response_plotbode_magnitude_numerical_databode_phase_numerical_data	bode_plot)TransferFunctionSeriesParallelTransferFunctionMatrix)raisesskip
matplotlibfromlistpyplot)import_kwargscatchnumpy      g      ?      
         	   皙?      c                 C   s   t | t |fS N)tupler   b r3   b/var/www/vscode/kcb/lib/python3.10/site-packages/sympy/physics/control/tests/test_control_plots.py	_to_tuple'   s   r5   c                 C   s   t | |\} }t| dd | t| d t| d d   | dd   t|dd |t|d t|d d   |dd   fS )Nr   r%   r$   )r5   r0   lenr1   r3   r3   r4   _trim_tuple*   s   ::r8   c                    sJ   | \}}t ||\}}t fdd|D }tdd t||D S )zChecks whether the y-coordinate value of the plotted
    data point is equal to the value of the function at a
    particular x.c                 3   s    | ]} |V  qd S r/   r3   ).0x_i
evalf_funcsystemr3   r4   	<genexpr>5   s    z(y_coordinate_equality.<locals>.<genexpr>c                 s   s$    | ]\}}t || d k V  qdS )g:0yE>N)r   )r9   y_exp_iy_ir3   r3   r4   r>   6   s   " )r8   r0   allzip)plot_data_funcr<   r=   xyy_expr3   r;   r4   y_coordinate_equality/   s   rG   c                      s  t std tttgttggdtd d   ttfdd tt fdd tt fdd ttfdd ttfd	d tt fd
d tt fdd ttfdd ttfdd tt	td ttt
fdd tt
fdd tt
fdd tt
fdd tt
fdd tt
fdd tt
fdd tt
fdd tt
fdd tt
dd  tt
dd  tt
dd  tt
dd  tt
dd  tt
dd  d S )Nz"Matplotlib not the default backendr$   r%   c                         t  S r/   r   r3   tfmr3   r4   <lambda>@       ztest_errors.<locals>.<lambda>c                      rH   r/   r   r3   exprr3   r4   rL   A   rM   c                      rH   r/   r   r3   rO   r3   r4   rL   B   rM   c                      rH   r/   r   r3   rJ   r3   r4   rL   C   rM   c                      rH   r/   r   r3   rJ   r3   r4   rL   D   rM   c                      rH   r/   r   r3   rO   r3   r4   rL   E   rM   c                      rH   r/   r   r3   rO   r3   r4   rL   F   rM   c                      rH   r/   r   r3   rJ   r3   r4   rL   G   rM   c                      rH   r/   r   r3   rJ   r3   r4   rL   H   rM   c                      rH   r/   rI   r3   tf_ar3   r4   rL   L   rM   c                      rH   r/   rN   r3   rX   r3   r4   rL   M   rM   c                      rH   r/   rQ   r3   rX   r3   r4   rL   N   rM   c                      rH   r/   rR   r3   rX   r3   r4   rL   O   rM   c                      rH   r/   rS   r3   rX   r3   r4   rL   P   rM   c                      rH   r/   rT   r3   rX   r3   r4   rL   Q   rM   c                      rH   r/   rU   r3   rX   r3   r4   rL   R   rM   c                      rH   r/   rV   r3   rX   r3   r4   rL   S   rM   c                      rH   r/   rW   r3   rX   r3   r4   rL   T   rM   c                   S      t tddS )Nlower_limit)r   tf1r3   r3   r3   r4   rL   W       c                   S   rZ   )N皙r\   )r   r^   r3   r3   r3   r4   rL   X   r_   c                   S   rZ   )NgUUUUUUr\   r   r^   r3   r3   r3   r4   rL   Y   r_   c                   S   rZ   )Nr`   )slopera   r3   r3   r3   r4   rL   \   r_   c                   S   rZ   )Nhz)	freq_unitr   r^   r3   r3   r3   r4   rL   _   r_   c                   S   rZ   )Ndegree)
phase_unitre   r3   r3   r3   r4   rL   `   r_   )r   r   r   tf6tf5r	   r   NotImplementedErrorr   r   
ValueErrorr3   r3   )rP   rY   rK   r4   test_errors9   s:   rl   c                  C   s   t std dd } g ddgg}dgddgg}dgg d	g}g g d
g}g dg dg}g ddgg}| t|s9J | t|s@J | t|sGJ | t|sNJ | t|sUJ | t|s\J d S )NNumPy is required for this testc                 S   s4   t | \}}t||d }t||d }|o|S )Nr   r$   )r   r#   allclose)sysexpected_valuezr
   z_checkp_checkr3   r3   r4   	pz_testerg   s   z!test_pole_zero.<locals>.pz_testeryϿhdE?yϿhdE        y      п4?y      п4Կ)y     ࿲LXz?y     ࿲LXzy?        )g      @ru   ru   ru   )gv|?g     g8hֿ)yϿhdE?yϿhdEyϿ4?yϿ4ԿyZEf;]yJu3;]@)r#   r   r^   tf2tf3ser1par1tf8)rt   exp1exp2exp3exp4exp5exp6r3   r3   r4   test_pole_zeroc   s&   r   c                     sj   t std dd dd   fdd} | tsJ | ts!J | ts'J | ts-J | ts3J d S )Nrm   c                 S   s>   |   }tddd}|| jt| i}t|||i S )NwTreal)to_exprr   subsvarr   r   evalfr=   pointrP   _ww_exprr3   r3   r4   bode_phase_evalf   s   z#test_bode.<locals>.bode_phase_evalfc                 S   sH   |   }tddd}|| jt| i}dtt|d||i  S )Nr   Tr      r(   )r   r   r   r   r   r   r   r   r   r3   r3   r4   bode_mag_evalf   s    z!test_bode.<locals>.bode_mag_evalfc                    s   t t | ot t| S r/   )rG   r   r   )ro   r   r   r3   r4   test_bode_data   s   
z!test_bode.<locals>.test_bode_data)r#   r   r^   rv   rw   tf4ri   )r   r3   r   r4   	test_bode   s   r   c                 C   s   t dd t| |D S )Nc                 s   s     | ]}t |d ddV  qdS )r,   gư>)rel_tolabs_tolNr   )r9   _r3   r3   r4   r>      s    z'check_point_accuracy.<locals>.<genexpr>)rA   rB   r1   r3   r3   r4   check_point_accuracy   s   r   c                  C   s   t std dd } d}d}d}d}d}d	}d
}| t|sJ | t|s&J | t|s-J | t|s4J | t|s;J | t|sBJ | t|sIJ d S )Nrm   c                 S   :   t t| ddd \}}t||d }t||d }|o|S NFr(   )adaptivenr   r$   )r5   r   r   ro   rp   rD   rE   x_checky_checkr3   r3   r4   impulse_res_tester      z1test_impulse_response.<locals>.impulse_res_tester)
ru   grq?grq@g
@grq@g88@g@gqq@grq!@      $@)
ru   gϡ(h?g j?gyӿgTHfg'?g*Vrv?g>ﹿg)c gkz?)r   )
gvWUU?gV!y?g7?gfꦎgJIPgWMJĤg"Gga6ߞgiރgP=))r   )
g   2>g?gxL#V
@gĮU"@g^<@gTU@g|/u^p@gjD#;݈@gi@gNU(@)r   )
ru   gf@gf8@gsqK@gfX@gOEJc@gsqk@gr@gfx@g     @@)r   )
ru   gٵ:/ĺgy%L?g2ƜgGLK&ы?gybŔugΕ_?g-~HFgof.?g&;)r   )
g   `n9g&l?gqɔ
@g(w\=(@gl%)k9@g+<Z=@glއ~>gLqggf}L)r   )
ru   g6qD2@g7մ@gO/ߡ 5AgsYAgzC5Bgl̹˵BgC/6CgJ@Cg"-|6D)	r#   r   r^   rv   rw   r   ri   tf7rx   )r   r{   r|   r}   r~   r   r   exp7r3   r3   r4   test_impulse_response   s"   r   c                  C   s   t std dd } d}d}d}d}d}d	}| t|sJ | t|s$J | t|s+J | t|s2J | t|s9J | t|s@J d S )
Nrm   c                 S   r   r   )r5   r   r   r   r3   r3   r4   step_res_tester   r   z+test_step_response.<locals>.step_res_tester)r   )
g   jϛTgڴW?g?gg	?gM?g#J?g"@te?g ?g/P?gc?)r   )
ru   gRul?gql?g."aG?g?gb?gVߴ?g-b[S?g7 ގ?g\7' m)r   )
ru   gNw4?gh&7|@g."@gs<@gHvU@grnT^p@gh%݈@gs@g{ct'@)r   )
ru   gۍ^6J@gۍ^6J2@gb<N@gۍ^6Jb@gVJyq@gb<~@go@gۍ^6J@gg
@)r   )
g   .1gъQ?gUZ?gup?grBz?g5k?g뎸?g(%
- ?gj?g9U ?)r   )
g   ΃g
V?g}{?g.cRz	@g į"^"@gy;+<@gNU@g@ lp@g&O-@gN2q@)r#   r   r^   rv   rw   r   ri   ser2)r   r{   r|   r}   r~   r   r   r3   r3   r4   test_step_response   s   r   c                  C   s   t std ddd} d}d}d}d}d	}d
}| td|sJ | td|ds(J | td|ds1J | td|ds:J | td|dsCJ | td|sKJ d S )Nrm   r$   c                 S   s<   t t| |d|d \}}t||d }t||d }|o|S )NF)rb   r   r   r   r$   )r5   r   r   )ro   
num_pointsrp   rb   rD   rE   r   r   r3   r3   r4   ramp_res_tester  s   z+test_ramp_response.<locals>.ramp_res_tester))ru   g       @g      @g      @g       @r   )ru   g+^p?g C?gmX]@gBOBa@gNʡf@)r   )
g   (Z>gr?g8g((?go!(?gي2?gz$Y?gxMw?g5^)?gv]?gǓ?)r   )
g   WegD/l3?g@g7CЃ(@g!%8D@glZ_@gR×vx@gJ̳ @gs;4O@gk<0݁@)r   )
ru   g?{?g?{>@gQEJc@g?{~@g(|R@gQEJ@g`ޱ@g?{@g     j@)r   )
ru   ggGS@gU-XH"@gEBT1,@gޝn3@gzj8@gS\=@g}A@g5jهǌC@g>6F@)r   r   r&   r(   g333333?g      ?r'   r+   )r$   )r#   r   r^   rv   rw   r   ri   rh   )r   r{   r|   r}   r~   r   r   r3   r3   r4   test_ramp_response  s   
r   N)=mathr   sympy.core.numbersr   sympy.core.symbolr   $sympy.functions.elementary.complexesr   r   &sympy.functions.elementary.exponentialr   	sympy.abcr	   r
   r   sympy.externalr   #sympy.physics.control.control_plotsr   r   r   r   r   r   r   r   r   r   r   sympy.physics.control.ltir   r   r   r   sympy.testing.pytestr   r   RuntimeErrorr   r#   r^   rv   rw   r   ri   rh   r   rz   rx   r   ry   r5   r8   rG   rl   r   r   r   r   r   r   r3   r3   r3   r4   <module>   sH    4
 D 

*30