Massimo Nocentini

November 9, 2016: splitting from "big" notebook



Abstract
Theory of matrix functions applied to Fibonacci matrix and a matrix with a eigenvalue with multiplicity greater than 1.

In [1]:
from sympy import *
from sympy.abc import n, i, N, x, lamda, phi, z, j, r, k, a

from commons import *
from matrix_functions import *
from sequences import *
import functions_catalog

init_printing()

Fibonacci matrix


In [2]:
F = define(Symbol(r'\mathcal{F}'), Matrix([[1, 1], [1, 0]]))
F


Out[2]:
$$\mathcal{F} = \left[\begin{matrix}1 & 1\\1 & 0\end{matrix}\right]$$

In [3]:
m = F.rhs.rows

In [4]:
eigendata = spectrum(F)
eigendata


Out[4]:
$$\sigma{\left (\mathcal{F} \right )} = \left ( \left \{ 1 : \left ( \lambda_{1}, \quad m_{1}\right ), \quad 2 : \left ( \lambda_{2}, \quad m_{2}\right )\right \}, \quad \left \{ \lambda_{1} : - \frac{\sqrt{5}}{2} + \frac{1}{2}, \quad \lambda_{2} : \frac{1}{2} + \frac{\sqrt{5}}{2}\right \}, \quad \left \{ m_{1} : 1, \quad m_{2} : 1\right \}\right )$$

In [5]:
data, eigenvals, multiplicities = eigendata.rhs

In [6]:
Phi_poly = Phi_poly_ctor(deg=m-1)
Phi_poly


Out[6]:
$$\Phi{\left (z,i,j \right )} = z \phi_{i,j,0} + \phi_{i,j,1}$$

In [7]:
Phi_polynomials = component_polynomials(eigendata)
Phi_polynomials


Out[7]:
$$\left \{ \left ( 1, \quad 1\right ) : \Phi_{ 1, 1 }{\left (z \right )} = \frac{z}{\lambda_{1} - \lambda_{2}} - \frac{\lambda_{2}}{\lambda_{1} - \lambda_{2}}, \quad \left ( 2, \quad 1\right ) : \Phi_{ 2, 1 }{\left (z \right )} = - \frac{z}{\lambda_{1} - \lambda_{2}} + \frac{\lambda_{1}}{\lambda_{1} - \lambda_{2}}\right \}$$

In [8]:
cmatrices = component_matrices(F, Phi_polynomials)
cmatrices


Out[8]:
$$\left \{ \left ( 1, \quad 1\right ) : Z^{\left[ \mathcal{F} \right]}_{1,1} = \left[\begin{matrix}- \frac{\lambda_{2} - 1}{\lambda_{1} - \lambda_{2}} & \frac{1}{\lambda_{1} - \lambda_{2}}\\\frac{1}{\lambda_{1} - \lambda_{2}} & - \frac{\lambda_{2}}{\lambda_{1} - \lambda_{2}}\end{matrix}\right], \quad \left ( 2, \quad 1\right ) : Z^{\left[ \mathcal{F} \right]}_{2,1} = \left[\begin{matrix}\frac{\lambda_{1} - 1}{\lambda_{1} - \lambda_{2}} & - \frac{1}{\lambda_{1} - \lambda_{2}}\\- \frac{1}{\lambda_{1} - \lambda_{2}} & \frac{\lambda_{1}}{\lambda_{1} - \lambda_{2}}\end{matrix}\right]\right \}$$

In [9]:
Z_11 = cmatrices[1,1].rhs

In [13]:
assert (F.rhs * Z_11 - Z_11 * F.rhs).simplify() == zeros(2)

In [14]:
assert (Z_11*Z_11 - Z_11).subs(eigenvals).applyfunc(simplify) == zeros(2)

In [12]:
Zi1 = list(cm.rhs.as_immutable() for (i, j), cm in cmatrices.items() if j == 1)

s = zeros(m)
for Z in Zi1:
    s += Z
s, s.simplify(), s.subs(eigenvals).applyfunc(simplify)


Out[12]:
$$\left ( \left[\begin{matrix}\frac{\lambda_{1} - 1}{\lambda_{1} - \lambda_{2}} - \frac{\lambda_{2} - 1}{\lambda_{1} - \lambda_{2}} & 0\\0 & \frac{\lambda_{1}}{\lambda_{1} - \lambda_{2}} - \frac{\lambda_{2}}{\lambda_{1} - \lambda_{2}}\end{matrix}\right], \quad \left[\begin{matrix}1 & 0\\0 & 1\end{matrix}\right], \quad \left[\begin{matrix}1 & 0\\0 & 1\end{matrix}\right]\right )$$

In [14]:
v = IndexedBase('v')
v_vector = Matrix(m, 1, lambda i, _: v[i])
M_space_ctor = M_space(cmatrices)
M_space_v = M_space_ctor(v_vector)
M_space_v


Out[14]:
$$\left \{ 1 : \left \{ 1 : \boldsymbol{x}_{1,1} = \left[\begin{matrix}- \frac{\left(\lambda_{2} - 1\right) v_{0}}{\lambda_{1} - \lambda_{2}} + \frac{v_{1}}{\lambda_{1} - \lambda_{2}}\\- \frac{\lambda_{2} v_{1}}{\lambda_{1} - \lambda_{2}} + \frac{v_{0}}{\lambda_{1} - \lambda_{2}}\end{matrix}\right]\right \}, \quad 2 : \left \{ 1 : \boldsymbol{x}_{2,1} = \left[\begin{matrix}\frac{\left(\lambda_{1} - 1\right) v_{0}}{\lambda_{1} - \lambda_{2}} - \frac{v_{1}}{\lambda_{1} - \lambda_{2}}\\\frac{\lambda_{1} v_{1}}{\lambda_{1} - \lambda_{2}} - \frac{v_{0}}{\lambda_{1} - \lambda_{2}}\end{matrix}\right]\right \}\right \}$$

In [15]:
i = 1
eq = Eq(F.rhs*M_space_v[i][1].rhs, M_space_v[i][1].rhs.applyfunc(lambda k: k * data[i][0]))
eq


Out[15]:
$$\left[\begin{matrix}- \frac{\left(\lambda_{2} - 1\right) v_{0}}{\lambda_{1} - \lambda_{2}} - \frac{\lambda_{2} v_{1}}{\lambda_{1} - \lambda_{2}} + \frac{v_{0}}{\lambda_{1} - \lambda_{2}} + \frac{v_{1}}{\lambda_{1} - \lambda_{2}}\\- \frac{\left(\lambda_{2} - 1\right) v_{0}}{\lambda_{1} - \lambda_{2}} + \frac{v_{1}}{\lambda_{1} - \lambda_{2}}\end{matrix}\right] = \left[\begin{matrix}\left(- \frac{\left(\lambda_{2} - 1\right) v_{0}}{\lambda_{1} - \lambda_{2}} + \frac{v_{1}}{\lambda_{1} - \lambda_{2}}\right) \lambda_{1}\\\left(- \frac{\lambda_{2} v_{1}}{\lambda_{1} - \lambda_{2}} + \frac{v_{0}}{\lambda_{1} - \lambda_{2}}\right) \lambda_{1}\end{matrix}\right]$$

In [33]:
assert (eq.lhs.applyfunc(lambda i: i.subs(eigenvals).ratsimp()) == 
        eq.rhs.applyfunc(lambda i: i.subs(eigenvals).ratsimp()))

In [19]:
GEs = generalized_eigenvectors_matrices(M_space_v)
GEs # actually, not necessary for Jordan Normal Form computation


Out[19]:
$$\left \{ 1 : X_{1} = \left[\begin{matrix}- \frac{\left(\lambda_{2} - 1\right) v_{0}}{\lambda_{1} - \lambda_{2}} + \frac{v_{1}}{\lambda_{1} - \lambda_{2}}\\- \frac{\lambda_{2} v_{1}}{\lambda_{1} - \lambda_{2}} + \frac{v_{0}}{\lambda_{1} - \lambda_{2}}\end{matrix}\right], \quad 2 : X_{2} = \left[\begin{matrix}\frac{\left(\lambda_{1} - 1\right) v_{0}}{\lambda_{1} - \lambda_{2}} - \frac{v_{1}}{\lambda_{1} - \lambda_{2}}\\\frac{\lambda_{1} v_{1}}{\lambda_{1} - \lambda_{2}} - \frac{v_{0}}{\lambda_{1} - \lambda_{2}}\end{matrix}\right]\right \}$$

In [20]:
relations = generalized_eigenvectors_relations(eigendata)

In [29]:
eqs = relations(F.rhs, M_space_v,post=lambda i: i.subs(eigenvals).ratsimp())
eqs


Out[29]:
$$\left \{ 1 : \left \{ 1 : \left[\begin{matrix}- \frac{3 \sqrt{5}}{10} v_{0} + \frac{v_{0}}{2} - \frac{\sqrt{5} v_{1}}{10} + \frac{v_{1}}{2}\\- \frac{\sqrt{5} v_{0}}{10} + \frac{v_{0}}{2} - \frac{\sqrt{5} v_{1}}{5}\end{matrix}\right] = \left[\begin{matrix}- \frac{3 \sqrt{5}}{10} v_{0} + \frac{v_{0}}{2} - \frac{\sqrt{5} v_{1}}{10} + \frac{v_{1}}{2}\\- \frac{\sqrt{5} v_{0}}{10} + \frac{v_{0}}{2} - \frac{\sqrt{5} v_{1}}{5}\end{matrix}\right]\right \}, \quad 2 : \left \{ 1 : \left[\begin{matrix}\frac{v_{0}}{2} + \frac{3 \sqrt{5}}{10} v_{0} + \frac{\sqrt{5} v_{1}}{10} + \frac{v_{1}}{2}\\\frac{\sqrt{5} v_{0}}{10} + \frac{v_{0}}{2} + \frac{\sqrt{5} v_{1}}{5}\end{matrix}\right] = \left[\begin{matrix}\frac{v_{0}}{2} + \frac{3 \sqrt{5}}{10} v_{0} + \frac{\sqrt{5} v_{1}}{10} + \frac{v_{1}}{2}\\\frac{\sqrt{5} v_{0}}{10} + \frac{v_{0}}{2} + \frac{\sqrt{5} v_{1}}{5}\end{matrix}\right]\right \}\right \}$$

In [23]:
miniblocks = Jordan_blocks(eigendata)
miniblocks


Out[23]:
$$\left \{ 1 : \left \{ 1 : \left[\begin{matrix}\lambda_{1}\end{matrix}\right]\right \}, \quad 2 : \left \{ 1 : \left[\begin{matrix}\lambda_{2}\end{matrix}\right]\right \}\right \}$$

In [25]:
X, J = Jordan_normalform(eigendata, matrices=(F.rhs, M_space_v, miniblocks))

In [26]:
X


Out[26]:
$$X = \left[\begin{matrix}- \frac{\left(\lambda_{2} - 1\right) v_{0}}{\lambda_{1} - \lambda_{2}} + \frac{v_{1}}{\lambda_{1} - \lambda_{2}} & \frac{\left(\lambda_{1} - 1\right) v_{0}}{\lambda_{1} - \lambda_{2}} - \frac{v_{1}}{\lambda_{1} - \lambda_{2}}\\- \frac{\lambda_{2} v_{1}}{\lambda_{1} - \lambda_{2}} + \frac{v_{0}}{\lambda_{1} - \lambda_{2}} & \frac{\lambda_{1} v_{1}}{\lambda_{1} - \lambda_{2}} - \frac{v_{0}}{\lambda_{1} - \lambda_{2}}\end{matrix}\right]$$

In [27]:
J


Out[27]:
$$J = \left[\begin{matrix}\lambda_{1} & 0\\0 & \lambda_{2}\end{matrix}\right]$$

In [34]:
assert ((F.rhs*X.rhs).applyfunc(lambda i: i.subs(eigenvals).ratsimp()) ==
        (X.rhs*J.rhs).applyfunc(lambda i: i.subs(eigenvals).ratsimp()))

In [37]:
fq = (X.rhs**(-1)*F.rhs*X.rhs).applyfunc(lambda i: i.subs(eigenvals).simplify())
fq


Out[37]:
$$\left[\begin{matrix}- \frac{\sqrt{5}}{2} + \frac{1}{2} & 0\\0 & \frac{1}{2} + \frac{\sqrt{5}}{2}\end{matrix}\right]$$

In [39]:
x = symbols('x', positive=True)
assert (fq[0, 0].subs({v[0]:1, v[1]:x}).radsimp() == eigenvals[data[1][0]].radsimp())

power function


In [40]:
f = Function('f')
f_power = define(let=f(z), be=z**r)
f_power


Out[40]:
$$f{\left (z \right )} = z^{r}$$

In [41]:
g_power = Hermite_interpolation_polynomial(f_power, eigendata, Phi_polynomials)
g_power


Out[41]:
$$\operatorname{f_{ 2 }}{\left (z \right )} = z \left(\frac{\lambda_{1}^{r}}{\lambda_{1} - \lambda_{2}} - \frac{\lambda_{2}^{r}}{\lambda_{1} - \lambda_{2}}\right) + \frac{\lambda_{1} \lambda_{2}^{r}}{\lambda_{1} - \lambda_{2}} - \frac{\lambda_{1}^{r} \lambda_{2}}{\lambda_{1} - \lambda_{2}}$$

In [42]:
g_power = g_power.subs(eigenvals)
g_power


Out[42]:
$$\operatorname{f_{ 2 }}{\left (z \right )} = z \left(\frac{\sqrt{5}}{5} \left(\frac{1}{2} + \frac{\sqrt{5}}{2}\right)^{r} - \frac{\sqrt{5}}{5} \left(- \frac{\sqrt{5}}{2} + \frac{1}{2}\right)^{r}\right) - \frac{\sqrt{5}}{5} \left(\frac{1}{2} + \frac{\sqrt{5}}{2}\right)^{r} \left(- \frac{\sqrt{5}}{2} + \frac{1}{2}\right) + \frac{\sqrt{5}}{5} \left(\frac{1}{2} + \frac{\sqrt{5}}{2}\right) \left(- \frac{\sqrt{5}}{2} + \frac{1}{2}\right)^{r}$$

In [43]:
with lift_to_matrix_function(g_power) as G_power:
    m_power = G_power(F)
m_power


Out[43]:
$$\operatorname{f_{ 2 }}{\left (\mathcal{F} \right )} = \left[\begin{matrix}\frac{2^{- r}}{10} \left(\sqrt{5} \left(1 + \sqrt{5}\right)^{r} + 5 \left(1 + \sqrt{5}\right)^{r} - \sqrt{5} \left(- \sqrt{5} + 1\right)^{r} + 5 \left(- \sqrt{5} + 1\right)^{r}\right) & \frac{2^{- r}}{5} \sqrt{5} \left(\left(1 + \sqrt{5}\right)^{r} - \left(- \sqrt{5} + 1\right)^{r}\right)\\\frac{2^{- r}}{5} \sqrt{5} \left(\left(1 + \sqrt{5}\right)^{r} - \left(- \sqrt{5} + 1\right)^{r}\right) & \frac{2^{- r}}{10} \left(- \sqrt{5} \left(1 + \sqrt{5}\right)^{r} + 5 \left(1 + \sqrt{5}\right)^{r} + \sqrt{5} \left(- \sqrt{5} + 1\right)^{r} + 5 \left(- \sqrt{5} + 1\right)^{r}\right)\end{matrix}\right]$$

In [44]:
m_power.rhs.subs(eigenvals).subs({r:8}).applyfunc(simplify)


Out[44]:
$$\left[\begin{matrix}34 & 21\\21 & 13\end{matrix}\right]$$

In [45]:
F.rhs**r


Out[45]:
$$\left[\begin{matrix}- \frac{\left(\frac{1}{2} + \frac{\sqrt{5}}{2}\right)^{r}}{\left(- \frac{\sqrt{5}}{2} + \frac{1}{2}\right) \left(\frac{1}{\frac{1}{2} + \frac{\sqrt{5}}{2}} - \frac{1}{- \frac{\sqrt{5}}{2} + \frac{1}{2}}\right)} + \frac{\left(- \frac{\sqrt{5}}{2} + \frac{1}{2}\right)^{r}}{\left(\frac{1}{2} + \frac{\sqrt{5}}{2}\right) \left(\frac{1}{\frac{1}{2} + \frac{\sqrt{5}}{2}} - \frac{1}{- \frac{\sqrt{5}}{2} + \frac{1}{2}}\right)} & - \frac{\left(\frac{1}{2} + \frac{\sqrt{5}}{2}\right)^{r}}{\left(\frac{1}{2} + \frac{\sqrt{5}}{2}\right) \left(- \frac{\sqrt{5}}{2} + \frac{1}{2}\right) \left(\frac{1}{\frac{1}{2} + \frac{\sqrt{5}}{2}} - \frac{1}{- \frac{\sqrt{5}}{2} + \frac{1}{2}}\right)} + \frac{\left(- \frac{\sqrt{5}}{2} + \frac{1}{2}\right)^{r}}{\left(\frac{1}{2} + \frac{\sqrt{5}}{2}\right) \left(- \frac{\sqrt{5}}{2} + \frac{1}{2}\right) \left(\frac{1}{\frac{1}{2} + \frac{\sqrt{5}}{2}} - \frac{1}{- \frac{\sqrt{5}}{2} + \frac{1}{2}}\right)}\\\frac{\left(\frac{1}{2} + \frac{\sqrt{5}}{2}\right)^{r}}{\frac{1}{\frac{1}{2} + \frac{\sqrt{5}}{2}} - \frac{1}{- \frac{\sqrt{5}}{2} + \frac{1}{2}}} - \frac{\left(- \frac{\sqrt{5}}{2} + \frac{1}{2}\right)^{r}}{\frac{1}{\frac{1}{2} + \frac{\sqrt{5}}{2}} - \frac{1}{- \frac{\sqrt{5}}{2} + \frac{1}{2}}} & \frac{\left(\frac{1}{2} + \frac{\sqrt{5}}{2}\right)^{r}}{\left(\frac{1}{2} + \frac{\sqrt{5}}{2}\right) \left(\frac{1}{\frac{1}{2} + \frac{\sqrt{5}}{2}} - \frac{1}{- \frac{\sqrt{5}}{2} + \frac{1}{2}}\right)} - \frac{\left(- \frac{\sqrt{5}}{2} + \frac{1}{2}\right)^{r}}{\left(- \frac{\sqrt{5}}{2} + \frac{1}{2}\right) \left(\frac{1}{\frac{1}{2} + \frac{\sqrt{5}}{2}} - \frac{1}{- \frac{\sqrt{5}}{2} + \frac{1}{2}}\right)}\end{matrix}\right]$$

In [46]:
_.subs({r:8}).applyfunc(simplify)


Out[46]:
$$\left[\begin{matrix}34 & 21\\21 & 13\end{matrix}\right]$$

A multiplicity greater than 1


In [48]:
m = define(Symbol(r'\mathcal{A}'), Matrix([
        [1, 0, 0],
        [1, 1, -1],
        [-2, 0, 3],
    ]))
m


Out[48]:
$$\mathcal{A} = \left[\begin{matrix}1 & 0 & 0\\1 & 1 & -1\\-2 & 0 & 3\end{matrix}\right]$$

In [50]:
eigendata = spectrum(m)
eigendata


Out[50]:
$$\sigma{\left (\mathcal{A} \right )} = \left ( \left \{ 1 : \left ( \lambda_{1}, \quad m_{1}\right ), \quad 2 : \left ( \lambda_{2}, \quad m_{2}\right )\right \}, \quad \left \{ \lambda_{1} : 3, \quad \lambda_{2} : 1\right \}, \quad \left \{ m_{1} : 1, \quad m_{2} : 2\right \}\right )$$

In [51]:
data, eigenvals, multiplicities = eigendata.rhs

In [52]:
m_bar = 3 # degree of \Xi minimal polynomial
Phi_poly = Phi_poly_ctor(deg=m_bar-1)
Phi_poly


Out[52]:
$$\Phi{\left (z,i,j \right )} = z^{2} \phi_{i,j,0} + z \phi_{i,j,1} + \phi_{i,j,2}$$

In [53]:
Phi_polynomials = component_polynomials(eigendata)
Phi_polynomials


Out[53]:
$$\left \{ \left ( 1, \quad 1\right ) : \Phi_{ 1, 1 }{\left (z \right )} = \frac{z^{2}}{\lambda_{1}^{2} - 2 \lambda_{1} \lambda_{2} + \lambda_{2}^{2}} - \frac{2 z \lambda_{2}}{\lambda_{1}^{2} - 2 \lambda_{1} \lambda_{2} + \lambda_{2}^{2}} + \frac{\lambda_{2}^{2}}{\lambda_{1}^{2} - 2 \lambda_{1} \lambda_{2} + \lambda_{2}^{2}}, \quad \left ( 2, \quad 1\right ) : \Phi_{ 2, 1 }{\left (z \right )} = - \frac{z^{2}}{\lambda_{1}^{2} - 2 \lambda_{1} \lambda_{2} + \lambda_{2}^{2}} + \frac{2 z \lambda_{2}}{\lambda_{1}^{2} - 2 \lambda_{1} \lambda_{2} + \lambda_{2}^{2}} + \frac{\left(\lambda_{1} - 2 \lambda_{2}\right) \lambda_{1}}{\lambda_{1}^{2} - 2 \lambda_{1} \lambda_{2} + \lambda_{2}^{2}}, \quad \left ( 2, \quad 2\right ) : \Phi_{ 2, 2 }{\left (z \right )} = - \frac{z^{2}}{\lambda_{1} - \lambda_{2}} + \frac{z \left(\lambda_{1} + \lambda_{2}\right)}{\lambda_{1} - \lambda_{2}} - \frac{\lambda_{1} \lambda_{2}}{\lambda_{1} - \lambda_{2}}\right \}$$

In [54]:
cmatrices = component_matrices(m, Phi_polynomials)
cmatrices


Out[54]:
$$\left \{ \left ( 1, \quad 1\right ) : Z^{\left[ \mathcal{A} \right]}_{1,1} = \left[\begin{matrix}\frac{\left(\lambda_{2} - 1\right)^{2}}{\left(\lambda_{1} - \lambda_{2}\right)^{2}} & 0 & 0\\- \frac{2 \left(\lambda_{2} - 2\right)}{\left(\lambda_{1} - \lambda_{2}\right)^{2}} & \frac{\left(\lambda_{2} - 1\right)^{2}}{\left(\lambda_{1} - \lambda_{2}\right)^{2}} & \frac{2 \left(\lambda_{2} - 2\right)}{\left(\lambda_{1} - \lambda_{2}\right)^{2}}\\\frac{4 \left(\lambda_{2} - 2\right)}{\left(\lambda_{1} - \lambda_{2}\right)^{2}} & 0 & \frac{\left(\lambda_{2} - 3\right)^{2}}{\left(\lambda_{1} - \lambda_{2}\right)^{2}}\end{matrix}\right], \quad \left ( 2, \quad 1\right ) : Z^{\left[ \mathcal{A} \right]}_{2,1} = \left[\begin{matrix}\frac{1}{\left(\lambda_{1} - \lambda_{2}\right)^{2}} \left(\lambda_{1} - 1\right) \left(\lambda_{1} - 2 \lambda_{2} + 1\right) & 0 & 0\\\frac{2 \left(\lambda_{2} - 2\right)}{\left(\lambda_{1} - \lambda_{2}\right)^{2}} & \frac{1}{\left(\lambda_{1} - \lambda_{2}\right)^{2}} \left(\lambda_{1} - 1\right) \left(\lambda_{1} - 2 \lambda_{2} + 1\right) & - \frac{2 \left(\lambda_{2} - 2\right)}{\left(\lambda_{1} - \lambda_{2}\right)^{2}}\\- \frac{4 \left(\lambda_{2} - 2\right)}{\left(\lambda_{1} - \lambda_{2}\right)^{2}} & 0 & \frac{1}{\left(\lambda_{1} - \lambda_{2}\right)^{2}} \left(\lambda_{1} - 3\right) \left(\lambda_{1} - 2 \lambda_{2} + 3\right)\end{matrix}\right], \quad \left ( 2, \quad 2\right ) : Z^{\left[ \mathcal{A} \right]}_{2,2} = \left[\begin{matrix}- \frac{\left(\lambda_{1} - 1\right) \left(\lambda_{2} - 1\right)}{\lambda_{1} - \lambda_{2}} & 0 & 0\\\frac{\lambda_{1} + \lambda_{2} - 4}{\lambda_{1} - \lambda_{2}} & - \frac{\left(\lambda_{1} - 1\right) \left(\lambda_{2} - 1\right)}{\lambda_{1} - \lambda_{2}} & - \frac{\lambda_{1} + \lambda_{2} - 4}{\lambda_{1} - \lambda_{2}}\\- \frac{2 \left(\lambda_{1} + \lambda_{2} - 4\right)}{\lambda_{1} - \lambda_{2}} & 0 & - \frac{\left(\lambda_{1} - 3\right) \left(\lambda_{2} - 3\right)}{\lambda_{1} - \lambda_{2}}\end{matrix}\right]\right \}$$

In [57]:
Zi1 = list(cm.rhs.as_immutable() for (i, j), cm in cmatrices.items() if j == 1)

s = zeros(m.rhs.rows)
for Z in Zi1:
    s += Z
s, s.simplify(), s.subs(eigenvals)


Out[57]:
$$\left ( \left[\begin{matrix}\frac{1}{\left(\lambda_{1} - \lambda_{2}\right)^{2}} \left(\lambda_{1} - 1\right) \left(\lambda_{1} - 2 \lambda_{2} + 1\right) + \frac{\left(\lambda_{2} - 1\right)^{2}}{\left(\lambda_{1} - \lambda_{2}\right)^{2}} & 0 & 0\\0 & \frac{1}{\left(\lambda_{1} - \lambda_{2}\right)^{2}} \left(\lambda_{1} - 1\right) \left(\lambda_{1} - 2 \lambda_{2} + 1\right) + \frac{\left(\lambda_{2} - 1\right)^{2}}{\left(\lambda_{1} - \lambda_{2}\right)^{2}} & 0\\0 & 0 & \frac{1}{\left(\lambda_{1} - \lambda_{2}\right)^{2}} \left(\lambda_{1} - 3\right) \left(\lambda_{1} - 2 \lambda_{2} + 3\right) + \frac{\left(\lambda_{2} - 3\right)^{2}}{\left(\lambda_{1} - \lambda_{2}\right)^{2}}\end{matrix}\right], \quad \left[\begin{matrix}1 & 0 & 0\\0 & 1 & 0\\0 & 0 & 1\end{matrix}\right], \quad \left[\begin{matrix}1 & 0 & 0\\0 & 1 & 0\\0 & 0 & 1\end{matrix}\right]\right )$$

inverse function


In [58]:
f, h = Function('f'), Function('h')
f_inverse = define(let=f(z), be=1/(z))
f_inverse


Out[58]:
$$f{\left (z \right )} = \frac{1}{z}$$

In [59]:
g_inverse = Hermite_interpolation_polynomial(f_inverse, eigendata, Phi_polynomials)
g_inverse


Out[59]:
$$\operatorname{f_{ 3 }}{\left (z \right )} = z^{2} \left(\frac{1}{\lambda_{1}^{3} - 2 \lambda_{1}^{2} \lambda_{2} + \lambda_{1} \lambda_{2}^{2}} - \frac{1}{\lambda_{1}^{2} \lambda_{2} - 2 \lambda_{1} \lambda_{2}^{2} + \lambda_{2}^{3}} + \frac{1}{\lambda_{1} \lambda_{2}^{2} - \lambda_{2}^{3}}\right) + z \left(- \frac{2 \lambda_{2}}{\lambda_{1}^{3} - 2 \lambda_{1}^{2} \lambda_{2} + \lambda_{1} \lambda_{2}^{2}} + \frac{2}{\lambda_{1}^{2} - 2 \lambda_{1} \lambda_{2} + \lambda_{2}^{2}} - \frac{\lambda_{1}}{\lambda_{1} \lambda_{2}^{2} - \lambda_{2}^{3}} - \frac{1}{\lambda_{1} \lambda_{2} - \lambda_{2}^{2}}\right) + \frac{\lambda_{2}^{2}}{\lambda_{1}^{3} - 2 \lambda_{1}^{2} \lambda_{2} + \lambda_{1} \lambda_{2}^{2}} - \frac{2 \lambda_{1}}{\lambda_{1}^{2} - 2 \lambda_{1} \lambda_{2} + \lambda_{2}^{2}} + \frac{\lambda_{1}^{2}}{\lambda_{1}^{2} \lambda_{2} - 2 \lambda_{1} \lambda_{2}^{2} + \lambda_{2}^{3}} + \frac{\lambda_{1}}{\lambda_{1} \lambda_{2} - \lambda_{2}^{2}}$$

In [60]:
g_inverse = g_inverse.subs(eigenvals)
g_inverse


Out[60]:
$$\operatorname{f_{ 3 }}{\left (z \right )} = \frac{z^{2}}{3} - \frac{5 z}{3} + \frac{7}{3}$$

In [61]:
with lift_to_matrix_function(g_inverse) as G_inverse:
    m_inverse = G_inverse(m)
m_inverse


Out[61]:
$$\operatorname{f_{ 3 }}{\left (\mathcal{A} \right )} = \left[\begin{matrix}1 & 0 & 0\\- \frac{1}{3} & 1 & \frac{1}{3}\\\frac{2}{3} & 0 & \frac{1}{3}\end{matrix}\right]$$

In [62]:
m.rhs**(-1)


Out[62]:
$$\left[\begin{matrix}1 & 0 & 0\\- \frac{1}{3} & 1 & \frac{1}{3}\\\frac{2}{3} & 0 & \frac{1}{3}\end{matrix}\right]$$