In [1]:
import sympy
In [2]:
t = sympy.symbols('t', real=True)
In [32]:
A = sympy.Matrix([
    [0, 1, -1],
    [-1, 0, 1],
    [1, -1, 0]
])
In [33]:
sympy.exp(A*t).expand(complex=True)
Out[33]:
$\displaystyle \left[\begin{matrix}\frac{2 \cos{\left(\sqrt{3} t \right)}}{3} + \frac{1}{3} & \frac{\sqrt{3} \sin{\left(\sqrt{3} t \right)}}{3} - \frac{\cos{\left(\sqrt{3} t \right)}}{3} + \frac{1}{3} & - \frac{\sqrt{3} \sin{\left(\sqrt{3} t \right)}}{3} - \frac{\cos{\left(\sqrt{3} t \right)}}{3} + \frac{1}{3}\\- \frac{\sqrt{3} \sin{\left(\sqrt{3} t \right)}}{3} - \frac{\cos{\left(\sqrt{3} t \right)}}{3} + \frac{1}{3} & \frac{2 \cos{\left(\sqrt{3} t \right)}}{3} + \frac{1}{3} & \frac{\sqrt{3} \sin{\left(\sqrt{3} t \right)}}{3} - \frac{\cos{\left(\sqrt{3} t \right)}}{3} + \frac{1}{3}\\\frac{\sqrt{3} \sin{\left(\sqrt{3} t \right)}}{3} - \frac{\cos{\left(\sqrt{3} t \right)}}{3} + \frac{1}{3} & - \frac{\sqrt{3} \sin{\left(\sqrt{3} t \right)}}{3} - \frac{\cos{\left(\sqrt{3} t \right)}}{3} + \frac{1}{3} & \frac{2 \cos{\left(\sqrt{3} t \right)}}{3} + \frac{1}{3}\end{matrix}\right]$
In [34]:
T, D = sympy.Matrix.diagonalize(A)
T
Out[34]:
$\displaystyle \left[\begin{matrix}1 & - \frac{1}{2} - \frac{\sqrt{3} i}{2} & - \frac{1}{2} + \frac{\sqrt{3} i}{2}\\1 & - \frac{1}{2} + \frac{\sqrt{3} i}{2} & - \frac{1}{2} - \frac{\sqrt{3} i}{2}\\1 & 1 & 1\end{matrix}\right]$
In [35]:
D
Out[35]:
$\displaystyle \left[\begin{matrix}0 & 0 & 0\\0 & - \sqrt{3} i & 0\\0 & 0 & \sqrt{3} i\end{matrix}\right]$
In [36]:
(T*sympy.exp(D*t)*T.inv()).expand(complex=True)
Out[36]:
$\displaystyle \left[\begin{matrix}\frac{2 \cos{\left(\sqrt{3} t \right)}}{3} + \frac{1}{3} & \frac{\sqrt{3} \sin{\left(\sqrt{3} t \right)}}{3} - \frac{\cos{\left(\sqrt{3} t \right)}}{3} + \frac{1}{3} & - \frac{\sqrt{3} \sin{\left(\sqrt{3} t \right)}}{3} - \frac{\cos{\left(\sqrt{3} t \right)}}{3} + \frac{1}{3}\\- \frac{\sqrt{3} \sin{\left(\sqrt{3} t \right)}}{3} - \frac{\cos{\left(\sqrt{3} t \right)}}{3} + \frac{1}{3} & \frac{2 \cos{\left(\sqrt{3} t \right)}}{3} + \frac{1}{3} & \frac{\sqrt{3} \sin{\left(\sqrt{3} t \right)}}{3} - \frac{\cos{\left(\sqrt{3} t \right)}}{3} + \frac{1}{3}\\\frac{\sqrt{3} \sin{\left(\sqrt{3} t \right)}}{3} - \frac{\cos{\left(\sqrt{3} t \right)}}{3} + \frac{1}{3} & - \frac{\sqrt{3} \sin{\left(\sqrt{3} t \right)}}{3} - \frac{\cos{\left(\sqrt{3} t \right)}}{3} + \frac{1}{3} & \frac{2 \cos{\left(\sqrt{3} t \right)}}{3} + \frac{1}{3}\end{matrix}\right]$
In [37]:
s = sympy.symbols('s')
M = (s*sympy.eye(3) - A).inv()
M
Out[37]:
$\displaystyle \left[\begin{matrix}\frac{s^{2} + 1}{s^{3} + 3 s} & \frac{s + 1}{s^{3} + 3 s} & \frac{1 - s}{s^{3} + 3 s}\\\frac{1 - s}{s^{3} + 3 s} & \frac{s^{2} + 1}{s^{3} + 3 s} & \frac{s + 1}{s^{3} + 3 s}\\\frac{s + 1}{s^{3} + 3 s} & \frac{1 - s}{s^{3} + 3 s} & \frac{s^{2} + 1}{s^{3} + 3 s}\end{matrix}\right]$
In [38]:
M_apart = M.applyfunc(lambda x: x.apart())
M_apart
Out[38]:
$\displaystyle \left[\begin{matrix}\frac{2 s}{3 \left(s^{2} + 3\right)} + \frac{1}{3 s} & - \frac{s - 3}{3 \left(s^{2} + 3\right)} + \frac{1}{3 s} & - \frac{s + 3}{3 \left(s^{2} + 3\right)} + \frac{1}{3 s}\\- \frac{s + 3}{3 \left(s^{2} + 3\right)} + \frac{1}{3 s} & \frac{2 s}{3 \left(s^{2} + 3\right)} + \frac{1}{3 s} & - \frac{s - 3}{3 \left(s^{2} + 3\right)} + \frac{1}{3 s}\\- \frac{s - 3}{3 \left(s^{2} + 3\right)} + \frac{1}{3 s} & - \frac{s + 3}{3 \left(s^{2} + 3\right)} + \frac{1}{3 s} & \frac{2 s}{3 \left(s^{2} + 3\right)} + \frac{1}{3 s}\end{matrix}\right]$

Warning: this will take a long time.

In [41]:
sympy.inverse_laplace_transform(M_apart, s, t)
Out[41]:
$\displaystyle \left[\begin{matrix}\frac{\left(2 \cos{\left(\sqrt{3} t \right)} + 1\right) \theta\left(t\right)}{3} & \frac{\left(\sqrt{3} \sin{\left(\sqrt{3} t \right)} - \cos{\left(\sqrt{3} t \right)} + 1\right) \theta\left(t\right)}{3} & - \frac{\left(\sqrt{3} \sin{\left(\sqrt{3} t \right)} + \cos{\left(\sqrt{3} t \right)} - 1\right) \theta\left(t\right)}{3}\\- \frac{\left(\sqrt{3} \sin{\left(\sqrt{3} t \right)} + \cos{\left(\sqrt{3} t \right)} - 1\right) \theta\left(t\right)}{3} & \frac{\left(2 \cos{\left(\sqrt{3} t \right)} + 1\right) \theta\left(t\right)}{3} & \frac{\left(\sqrt{3} \sin{\left(\sqrt{3} t \right)} - \cos{\left(\sqrt{3} t \right)} + 1\right) \theta\left(t\right)}{3}\\\frac{\left(\sqrt{3} \sin{\left(\sqrt{3} t \right)} - \cos{\left(\sqrt{3} t \right)} + 1\right) \theta\left(t\right)}{3} & - \frac{\left(\sqrt{3} \sin{\left(\sqrt{3} t \right)} + \cos{\left(\sqrt{3} t \right)} - 1\right) \theta\left(t\right)}{3} & \frac{\left(2 \cos{\left(\sqrt{3} t \right)} + 1\right) \theta\left(t\right)}{3}\end{matrix}\right]$

Note that $\Theta(t)$ is the Heaviside unit step function and represents that the output is zero before time zero,due to the nature of the Laplace transform.