In [1]:
%pdb


Automatic pdb calling has been turned ON

State-space analysis demonstration


In [2]:
from lcapy import Circuit
cct = Circuit(netlist=
"""
V 1 0 {v(t)}; down
R1 1 2; right
L 2 3; right=1.5, i={i_L}
R2 3 0_3; down=1.5, i={i_{R2}}, v={v_{R2}}
W 0 0_3; right
W 3 3_a; right
C 3_a 0_4; down, i={i_C}, v={v_C}
W 0_3 0_4; right
""")
cct.draw(svg=True)


Create state-space model


In [3]:
ss=cct.ss

State-variable vector


In [4]:
ss.x


Out[4]:
$\displaystyle \left[\begin{matrix}i_L(t)\\v_C(t)\end{matrix}\right]$

Independent source vector


In [5]:
ss.u


Out[5]:
$\displaystyle \left[\begin{matrix}v(t)\end{matrix}\right]$

Output vector for node voltages


In [6]:
ss.y


Out[6]:
$\displaystyle \left[\begin{matrix}v_1(t)\\v_2(t)\\v_3(t)\end{matrix}\right]$

State-space state equations


In [7]:
ss.state_equations()


Out[7]:
$$\left[\begin{matrix}\frac{d}{d t} i_L(t)\\\frac{d}{d t} v_C(t)\end{matrix}\right] = \left[\begin{matrix}\frac{1}{L}\\0\end{matrix}\right] \left[\begin{matrix}v(t)\end{matrix}\right] + \left[\begin{matrix}- \frac{R_{1}}{L} & - \frac{1}{L}\\\frac{1}{C} & - \frac{1}{C R_{2}}\end{matrix}\right] \left[\begin{matrix}i_L(t)\\v_C(t)\end{matrix}\right]$$

State-space output equations for the node voltages


In [8]:
ss.output_equations()


Out[8]:
$$\left[\begin{matrix}v_1(t)\\v_2(t)\\v_3(t)\end{matrix}\right] = \left[\begin{matrix}1\\1\\0\end{matrix}\right] \left[\begin{matrix}v(t)\end{matrix}\right] + \left[\begin{matrix}0 & 0\\- R_{1} & 0\\0 & 1\end{matrix}\right] \left[\begin{matrix}i_L(t)\\v_C(t)\end{matrix}\right]$$

Characteristic (system) polynomial


In [9]:
ss.P


Out[9]:
$$s^{2} + \frac{s \left(C R_{1} R_{2} + L\right)}{C L R_{2}} + \frac{R_{1} + R_{2}}{C L R_{2}}$$

Eigenvalues


In [10]:
ss.eigenvalues


Out[10]:
$$\left[ - \frac{C R_{1} R_{2} + L}{2 C L R_{2}} + \frac{\sqrt{C^{2} R_{1}^{2} R_{2}^{2} - 2 C L R_{1} R_{2} - 4 C L R_{2}^{2} + L^{2}}}{2 C L R_{2}}, \ - \frac{C R_{1} R_{2} + L}{2 C L R_{2}} - \frac{\sqrt{C^{2} R_{1}^{2} R_{2}^{2} - 2 C L R_{1} R_{2} - 4 C L R_{2}^{2} + L^{2}}}{2 C L R_{2}}\right]$$

Eigenvectors (modal matrix)


In [11]:
ss.M


Out[11]:
$\displaystyle \left[\begin{matrix}\frac{- C R_{1} R_{2} + L + \sqrt{C^{2} R_{1}^{2} R_{2}^{2} - 2 C L R_{1} R_{2} - 4 C L R_{2}^{2} + L^{2}}}{2 L R_{2}} & \frac{- C R_{1} R_{2} + L - \sqrt{C^{2} R_{1}^{2} R_{2}^{2} - 2 C L R_{1} R_{2} - 4 C L R_{2}^{2} + L^{2}}}{2 L R_{2}}\\1 & 1\end{matrix}\right]$

s-domain state transition matrix


In [12]:
ss.Phi


Out[12]:
$\displaystyle \left[\begin{matrix}\frac{s + \frac{1}{C R_{2}}}{s^{2} + \frac{s \left(C R_{1} R_{2} + L\right)}{C L R_{2}} + \frac{R_{1} + R_{2}}{C L R_{2}}} & - \frac{1}{L \left(s^{2} + \frac{s \left(C R_{1} R_{2} + L\right)}{C L R_{2}} + \frac{R_{1} + R_{2}}{C L R_{2}}\right)}\\\frac{1}{C \left(s^{2} + \frac{s \left(C R_{1} R_{2} + L\right)}{C L R_{2}} + \frac{R_{1} + R_{2}}{C L R_{2}}\right)} & \frac{s + \frac{R_{1}}{L}}{s^{2} + \frac{s \left(C R_{1} R_{2} + L\right)}{C L R_{2}} + \frac{R_{1} + R_{2}}{C L R_{2}}}\end{matrix}\right]$

System transfer functions


In [13]:
ss.G


Out[13]:
$\displaystyle \left[\begin{matrix}1\\\frac{s^{2} + \frac{s}{C R_{2}} + \frac{1}{C L}}{s^{2} + \frac{s \left(C R_{1} R_{2} + L\right)}{C L R_{2}} + \frac{R_{1} + R_{2}}{C L R_{2}}}\\\frac{1}{C L \left(s^{2} + \frac{s \left(C R_{1} R_{2} + L\right)}{C L R_{2}} + \frac{R_{1} + R_{2}}{C L R_{2}}\right)}\end{matrix}\right]$