# Modelo dinámico de un circuito RLC


```python
import sympy as sym
sym.init_printing()
import matplotlib.pyplot as plt
%matplotlib inline
```




| Elemento | Dominio del tiempo  (EDO)| 
|:---:|:---:|
|  | $u(t) = R \cdot i(t)$ | $U(s) = R \cdot I(s)$ | $R$ |
|  | $\begin{matrix} u(t) = L \frac{d}{dt} i(t) \\ i(t) = \frac{1}{L} \int_{0}^{t} u(\tau) d\tau + i(0+) \epsilon(t) \end{matrix}$ | $\begin{matrix} U(s) = s L I(s) - L i(0+) \\ I(s) = \frac{1}{s L} U(s) + \frac{1}{s} i(0+) \end{matrix}$ | $s L$ |
|  | $\begin{matrix} u(t) = \frac{1}{C} \int_{0}^{t} i(\tau) d\tau + u(0+) \epsilon(t) \\ i(t) = C \frac{d}{dt} u(t) \end{matrix}$ | $\begin{matrix} U(s) = \frac{1}{s C} I(s) + \frac{1}{s} u(0+) \\ I(s) = s C U(s) - C u(0+) \end{matrix}$ | $\frac{1}{s C}$


Considere el circuito que se muestra en la figura. Suponga que la entrada es el voltaje $x(t)$ y la salida es el voltaje $y(t)$. Suponga además que no hay energía almacenada en los elementos que almacenan energía en $t<0$. Además, considere que $x(t)=0 \forall t<0$.






El voltaje $x(t)$ es igual a los voltajes que caen en la red $RLC$.


\begin{align}
v_R(t) + v_L(t) + v_C(t) &= x(t) \\
R i(t) + L \frac{di}{dt} + \frac{1}{C} \int_{0}^{t} i(\tau) d\tau &= x(t) \\
\end{align}

La salida $y(t)$ es el voltaje del capacitor.

\begin{equation}
y(t) = \frac{1}{C} \int_{0}^{t} i(\tau) d\tau
\end{equation}

De donde se obtiene la corriente $i(t)$

\begin{equation}
C \frac{dy}{dt} = i(t)
\end{equation}

Incorporando las expresiones de la salida $y(t)$ y la variable interna $i(t)$ en la ecuación de la malla se obtiene

\begin{align}
R i(t) + L \frac{di}{dt} + \frac{1}{C} \int_{0}^{t} i(\tau) d\tau &= x(t) \\
C R \frac{d y(t)}{dt} + C L \frac{d^2 y(t)}{dt^2} + y(t)& = x(t) \\
\end{align}

-------------------


\begin{equation}
y(t) = \frac{1}{C} \int_{0}^{t} i(\tau) d\tau
\end{equation}


\begin{equation}
C \cdot y(t) = C \cdot \frac{1}{C} \int_{0}^{t} i(\tau) d\tau
\end{equation}

\begin{equation}
C \cdot y(t) =  \int_{0}^{t} i(\tau) d\tau
\end{equation}

\begin{equation}
\frac{d}{dt} (C \cdot y(t)) =  \frac{d}{dt}(\int_{0}^{t} i(\tau) d\tau)
\end{equation}

\begin{equation}
C \frac{dy}{dt} =  i(t)
\end{equation}


```python
t, L, R, C = sym.symbols('t L R C', real=True)
x = sym.Function('x')(t)
y = sym.Function('y')(t)

ode = sym.Eq(C*R*y.diff(t) + C*L*y.diff(t, 2) +  y, x)
ode
```

Dada una entrada $x(t)$, se puede calcular la solución del sistema. Observe que al usar `dsolve` obtiene la solución general de la homogénea relacionada junto a la solución particular.


```python
u = sym.Heaviside(t)
# u = sym.Heaviside(t)*t
# sol = sym.dsolve( ode.subs(x,u))
sol = sym.dsolve( ode.subs(x,u))
sol
```




$\displaystyle y{\left(t \right)} = C_{1} e^{\frac{t \left(- R - \frac{\sqrt{C \left(C R^{2} - 4 L\right)}}{C}\right)}{2 L}} + C_{2} e^{\frac{t \left(- R + \frac{\sqrt{C \left(C R^{2} - 4 L\right)}}{C}\right)}{2 L}} - \frac{\left(\begin{cases} \begin{cases} \frac{2 C L}{C R - \sqrt{C^{2} R^{2} - 4 C L}} & \text{for}\: C R - \sqrt{C^{2} R^{2} - 4 C L} \neq 0 \\0 & \text{otherwise} \end{cases} & \text{for}\: C R - \sqrt{C^{2} R^{2} - 4 C L} = 0 \\\frac{2 C L}{C R - \sqrt{C^{2} R^{2} - 4 C L}} & \text{otherwise} \end{cases}\right) e^{\frac{t \left(- R + \frac{\sqrt{C \left(C R^{2} - 4 L\right)}}{C}\right)}{2 L}} \theta\left(t\right)}{\sqrt{C \left(C R^{2} - 4 L\right)}} + \frac{\left(\begin{cases} \begin{cases} \frac{2 C L}{C R + \sqrt{C^{2} R^{2} - 4 C L}} & \text{for}\: C R + \sqrt{C^{2} R^{2} - 4 C L} \neq 0 \\0 & \text{otherwise} \end{cases} & \text{for}\: C R + \sqrt{C^{2} R^{2} - 4 C L} = 0 \\\frac{2 C L}{C R + \sqrt{C^{2} R^{2} - 4 C L}} & \text{otherwise} \end{cases}\right) e^{\frac{t \left(- R - \frac{\sqrt{C \left(C R^{2} - 4 L\right)}}{C}\right)}{2 L}} \theta\left(t\right)}{\sqrt{C \left(C R^{2} - 4 L\right)}} + \frac{\left(\begin{cases} \begin{cases} \frac{2 C L e^{\frac{R t}{2 L} - \frac{t \sqrt{C^{2} R^{2} - 4 C L}}{2 C L}}}{C R - \sqrt{C^{2} R^{2} - 4 C L}} & \text{for}\: C R - \sqrt{C^{2} R^{2} - 4 C L} \neq 0 \\t & \text{otherwise} \end{cases} & \text{for}\: C R - \sqrt{C^{2} R^{2} - 4 C L} = 0 \\\frac{2 C L e^{\frac{R t}{2 L} - \frac{t \sqrt{C^{2} R^{2} - 4 C L}}{2 C L}}}{C R - \sqrt{C^{2} R^{2} - 4 C L}} & \text{otherwise} \end{cases}\right) e^{\frac{t \left(- R + \frac{\sqrt{C \left(C R^{2} - 4 L\right)}}{C}\right)}{2 L}} \theta\left(t\right)}{\sqrt{C \left(C R^{2} - 4 L\right)}} - \frac{\left(\begin{cases} \begin{cases} \frac{2 C L e^{\frac{R t}{2 L} + \frac{t \sqrt{C^{2} R^{2} - 4 C L}}{2 C L}}}{C R + \sqrt{C^{2} R^{2} - 4 C L}} & \text{for}\: C R + \sqrt{C^{2} R^{2} - 4 C L} \neq 0 \\t & \text{otherwise} \end{cases} & \text{for}\: C R + \sqrt{C^{2} R^{2} - 4 C L} = 0 \\\frac{2 C L e^{\frac{R t}{2 L} + \frac{t \sqrt{C^{2} R^{2} - 4 C L}}{2 C L}}}{C R + \sqrt{C^{2} R^{2} - 4 C L}} & \text{otherwise} \end{cases}\right) e^{\frac{t \left(- R - \frac{\sqrt{C \left(C R^{2} - 4 L\right)}}{C}\right)}{2 L}} \theta\left(t\right)}{\sqrt{C \left(C R^{2} - 4 L\right)}}$



Las constantes $C_1$ y $C_2$ deben calcularse para satisfacer las condiciones iniciales  $y(t) = 0$ and $\frac{d y(t)}{dt} = 0$ para $t<0$. 


```python
C_int = sym.solve((sol.rhs.limit(t, 0, '-'),
                   sol.rhs.diff(t).limit(t, 0, '-')),
                  ['C1', 'C2'])
C_int
```


```python
sol = sol.subs(C_int)
sol
```




$\displaystyle y{\left(t \right)} = - \frac{\left(\begin{cases} \begin{cases} \frac{2 C L}{C R - \sqrt{C^{2} R^{2} - 4 C L}} & \text{for}\: C R - \sqrt{C^{2} R^{2} - 4 C L} \neq 0 \\0 & \text{otherwise} \end{cases} & \text{for}\: C R - \sqrt{C^{2} R^{2} - 4 C L} = 0 \\\frac{2 C L}{C R - \sqrt{C^{2} R^{2} - 4 C L}} & \text{otherwise} \end{cases}\right) e^{\frac{t \left(- R + \frac{\sqrt{C \left(C R^{2} - 4 L\right)}}{C}\right)}{2 L}} \theta\left(t\right)}{\sqrt{C \left(C R^{2} - 4 L\right)}} + \frac{\left(\begin{cases} \begin{cases} \frac{2 C L}{C R + \sqrt{C^{2} R^{2} - 4 C L}} & \text{for}\: C R + \sqrt{C^{2} R^{2} - 4 C L} \neq 0 \\0 & \text{otherwise} \end{cases} & \text{for}\: C R + \sqrt{C^{2} R^{2} - 4 C L} = 0 \\\frac{2 C L}{C R + \sqrt{C^{2} R^{2} - 4 C L}} & \text{otherwise} \end{cases}\right) e^{\frac{t \left(- R - \frac{\sqrt{C \left(C R^{2} - 4 L\right)}}{C}\right)}{2 L}} \theta\left(t\right)}{\sqrt{C \left(C R^{2} - 4 L\right)}} + \frac{\left(\begin{cases} \begin{cases} \frac{2 C L e^{\frac{R t}{2 L} - \frac{t \sqrt{C^{2} R^{2} - 4 C L}}{2 C L}}}{C R - \sqrt{C^{2} R^{2} - 4 C L}} & \text{for}\: C R - \sqrt{C^{2} R^{2} - 4 C L} \neq 0 \\t & \text{otherwise} \end{cases} & \text{for}\: C R - \sqrt{C^{2} R^{2} - 4 C L} = 0 \\\frac{2 C L e^{\frac{R t}{2 L} - \frac{t \sqrt{C^{2} R^{2} - 4 C L}}{2 C L}}}{C R - \sqrt{C^{2} R^{2} - 4 C L}} & \text{otherwise} \end{cases}\right) e^{\frac{t \left(- R + \frac{\sqrt{C \left(C R^{2} - 4 L\right)}}{C}\right)}{2 L}} \theta\left(t\right)}{\sqrt{C \left(C R^{2} - 4 L\right)}} - \frac{\left(\begin{cases} \begin{cases} \frac{2 C L e^{\frac{R t}{2 L} + \frac{t \sqrt{C^{2} R^{2} - 4 C L}}{2 C L}}}{C R + \sqrt{C^{2} R^{2} - 4 C L}} & \text{for}\: C R + \sqrt{C^{2} R^{2} - 4 C L} \neq 0 \\t & \text{otherwise} \end{cases} & \text{for}\: C R + \sqrt{C^{2} R^{2} - 4 C L} = 0 \\\frac{2 C L e^{\frac{R t}{2 L} + \frac{t \sqrt{C^{2} R^{2} - 4 C L}}{2 C L}}}{C R + \sqrt{C^{2} R^{2} - 4 C L}} & \text{otherwise} \end{cases}\right) e^{\frac{t \left(- R - \frac{\sqrt{C \left(C R^{2} - 4 L\right)}}{C}\right)}{2 L}} \theta\left(t\right)}{\sqrt{C \left(C R^{2} - 4 L\right)}}$




```python
RLC = {R: 2,     
       L: 0.05,
       C: .03}
RLC
```


```python
tlaps = (t,-10e-3,0.5*10e-1)

plt.rcParams['figure.figsize'] = 9, 3

sym.plot(sol.rhs.subs(RLC), tlaps, line_color='red',
         ylabel = '$y(t)$',);

sym.plot(u, tlaps, line_color='blue',
         ylabel = '$x(t)$',);

```


```python
sol.rhs.subs(RLC)
```


```python

```


```python

```

7b696937206581591a5fa1ca8d1332f50af3176d
ipynb
Jupyter Notebook
CircuitoRLC.ipynb
pierrediazp/Se-ales_y_Sistemas
b14bdaf814b0643589660078ddd39b5cdf86b659
MIT
CircuitoRLC.ipynb
pierrediazp/Se-ales_y_Sistemas
b14bdaf814b0643589660078ddd39b5cdf86b659
MIT
CircuitoRLC.ipynb
pierrediazp/Se-ales_y_Sistemas
b14bdaf814b0643589660078ddd39b5cdf86b659
MIT
Qwen/Qwen-72B
1. YES
2. YES