```python
import sympy
sympy.init_printing()
import numpy
from sympy.plotting import plot  #para plotear 2 variables
import matplotlib.pyplot as plt
%matplotlib inline

t, s = sympy.symbols('t, s')
a = sympy.symbols('a', real=True, positive=True)

f = sympy.exp(-a*t)
f
```


```python
sympy.integrate(f*sympy.exp(-s*t), (t, 0, sympy.oo))
```




$\displaystyle \begin{cases} \frac{1}{s \left(\frac{a}{s} + 1\right)} & \text{for}\: \left|{\arg{\left(s \right)}}\right| \leq \frac{\pi}{2} \\\int\limits_{0}^{\infty} e^{- a t} e^{- s t}\, dt & \text{otherwise} \end{cases}$




```python
sympy.laplace_transform(f, t, s)
```




$\displaystyle \left( \frac{1}{a + s}, \  0, \  \text{True}\right)$




```python
def L(f):
    return sympy.laplace_transform(f, t, s, noconds=True)
def invL(F):
    return sympy.inverse_laplace_transform(F, s, t)
```


```python
F=L(f)
F
```


```python
f_=invL(F)
f_
```


```python
sympy.plot(sympy.Heaviside(t));
```


```python
omega = sympy.Symbol('omega', real=True)
exp = sympy.exp
sin = sympy.sin
cos = sympy.cos
functions = [1,
         t,
         exp(-a*t),
         t*exp(-a*t),
         t**2*exp(-a*t),
         sin(omega*t),
         cos(omega*t),
         1 - exp(-a*t),
         exp(-a*t)*sin(omega*t),
         exp(-a*t)*cos(omega*t),
         ]
functions
```


```python
Fs = [L(f) for f in functions]
Fs
```


```python
F = ((s + 1)*(s + 2)* (s + 3))/((s + 4)*(s + 5)*(s + 6))
display(F)
F.apart(s)
```


```python
display(invL(F))
invL(F.apart(s))
```


```python
s = sympy.Symbol('s')
t = sympy.Symbol('t', real=True)
tau = sympy.Symbol('tau', real=True, positive=True)
G = K/(tau*s + 1)
G
```


```python
u = 1/s
stepresponse = invL(G*u)
stepresponse
```


```python
u = 1/s**2
rampresponse = invL(G*u)
rampresponse
```


```python
g = sympy.inverse_laplace_transform(G.subs({tau: 1,K:10}), s, t)
display(g)
sympy.plot(g, (t, -1, 10), ylim=(0, 1.1))
```


```python
s = sympy.symbols("s")
w = sympy.symbols("omega", real=True)
display(G)
Gw = G.subs({tau : 1,K:10, s : sympy.I*w})
Gw
```


```python
RA = abs(Gw)
phi = sympy.arg(Gw)
sympy.plot(RA, (w, 0.01, 100), xscale="log", yscale="log", ylabel="RA", xlabel="$\omega$")
sympy.plot(phi*180/sympy.pi, (w, 0.01, 100), xscale="log", xlabel="$\omega$", ylabel="$\phi$")
```


```python
from ipywidgets import interact
evalfimpulse = sympy.lambdify((K, tau, t), impulseresponse, 'numpy')
evalfstep = sympy.lambdify((K, tau, t), stepresponse, 'numpy')
evalframp = sympy.lambdify((K, tau, t), rampresponse, 'numpy')
```


```python
ts = numpy.linspace(0, 10)

def firstorder(tau_in, K_in):
    plt.figure(figsize=(12, 6))
    ax_impulse = plt.subplot2grid((2, 2), (0, 0))
    ax_step = plt.subplot2grid((2, 2), (1, 0))
    ax_complex = plt.subplot2grid((2, 2), (0, 1), rowspan=2)

    ax_impulse.plot(ts, evalfimpulse(K_in, tau_in, ts))
    ax_impulse.set_title('Impulse response')
    ax_impulse.set_ylim(0, 10)

    tau_height = 1 - numpy.exp(-1)
    ax_step.set_title('Step response')
    ax_step.plot(ts, evalfstep(K_in, tau_in, ts))
    ax_step.axhline(K_in)
    ax_step.plot([0, tau_in, tau_in], [K_in*tau_height]*2 + [0], alpha=0.4)
    ax_step.text(0, K_in, '$K=${}'.format(K_in))
    ax_step.text(0, K_in*tau_height, '{:.3}$K$'.format(tau_height))
    ax_step.text(tau_in, 0, r'$\tau={:.3}$'.format(tau_in))
    ax_step.set_ylim(0, 10)

    ax_complex.set_title('Poles plot')
    ax_complex.scatter(-1/tau_in, 0, marker='x', s=30)
    ax_complex.axhline(0, color='black')
    ax_complex.axvline(0, color='black')
    ax_complex.axis([-10, 10, -10, 10])
```


```python
firstorder(1., 10.)
```


```python

```

9885c761b502ac6997d926555a449d0d3855e9d5
ipynb
Jupyter Notebook
python/0/Laplace.ipynb
WayraLHD/SRA21
1b0447bf925678b8065c28b2767906d1daff2023
Apache-2.0
2021-09-29T16:38:53.000Z
2021-09-29T16:38:53.000Z
python/0/Laplace.ipynb
WayraLHD/SRA21
1b0447bf925678b8065c28b2767906d1daff2023
Apache-2.0
2021-08-10T08:24:57.000Z
2021-08-10T08:24:57.000Z
python/0/Laplace.ipynb
WayraLHD/SRA21
1b0447bf925678b8065c28b2767906d1daff2023
Apache-2.0
Qwen/Qwen-72B
1. YES
2. YES