In [2]:
import numpy as np
import sympy
sympy.init_printing()
In [3]:
from sympy.abc import a, t, x, s, g, G, X
x, g, X = sympy.symbols('x, g, X', cls=sympy.Function)
In [4]:
x0 = 4
xd0 = 7
In [5]:
g = sympy.exp(-t)
g
Out[5]:
In [6]:
sympy.laplace_transform(g, t, s)[0]
Out[6]:
sympy doesn't handle undefined functions in the Laplace transform yet, so we will input the EOMS in the Laplace domain ourselves.
https://github.com/sympy/sympy/issues/7219#issuecomment-154768904
In [7]:
eoms = sympy.Eq(3*(s**2 * X(s) - s * x0 - xd0) +
30 * (s * X(s) - x0) +
63 * X(s),
sympy.laplace_transform(4 * sympy.diff(g, t) + 6 * g, t, s)[0])
eoms
Out[7]:
In [8]:
XofS = sympy.solve(eoms, X(s))[0]
sympy.simplify(XofS)
Out[8]:
In [9]:
sol = sympy.inverse_laplace_transform(XofS, s, t)
sol
Out[9]:
In [10]:
sympy.plot(sol, (t, 0.1, 2))
Out[10]:
In [11]:
sol.evalf(subs={t: 5})
Out[11]:
In [21]:
t = sympy.symbols('t', positive=True)
s = sympy.symbols('s', complex=True)
f = 5 * t**2 * sympy.cos(3*t + sympy.pi/4)
f
Out[21]:
In [31]:
F = sympy.laplace_transform(5*t**2*sympy.cos(t), t, s, noconds=True)
F
Out[31]:
Sympy has difficulty with this one. There are many related issues discussing these problems
https://github.com/sympy/sympy/issues/13491
Basically, Sympy is trying to do a numerical integral and having a hard time.