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()
In [3]:
M = define(Symbol(r'\mathcal{R}'), Matrix([[3, 1], [1, 3]]))
M
Out[3]:
In [4]:
m = M.rhs.rows # degree of \Xi minimal polynomial
In [5]:
Phi_poly = Phi_poly_ctor(deg=m-1)
Phi_poly
Out[5]:
In [6]:
with lift_to_Lambda(Phi_poly) as Phi_fn:
pass
Phi_fn, Phi_fn(z, 3, j)
Out[6]:
In [7]:
eigendata = spectrum(M)
eigendata
Out[7]:
In [9]:
data, eigenvals, multiplicities = eigendata.rhs
In [12]:
Phi_polynomials = component_polynomials(eigendata)
Phi_polynomials
Out[12]:
In [13]:
f, h = Function('f'), Function('h')
function_eq = define(let=f(z), be=h(z))
function_eq
Out[13]:
In [14]:
g = Hermite_interpolation_polynomial(function_eq, eigendata, Phi_polynomials)
g
Out[14]:
In [15]:
g.subs({h: Lambda(z, sqrt(z))})
Out[15]:
In [16]:
g.subs({h: Lambda(z, 1/z)})
Out[16]:
In [18]:
t = g.subs(eigenvals)
t
Out[18]:
In [19]:
with lift_to_matrix_function(g) as g:
res = g(M)
res
Out[19]:
In [22]:
define(res.lhs, res.rhs.subs(eigenvals))
Out[22]:
In [23]:
cmatrices = component_matrices(M, Phi_polynomials)
cmatrices
Out[23]:
In [25]:
Zi1 = list(cm.rhs.as_immutable() for (i, j), cm in cmatrices.items() if j == 1)
Zi1
Out[25]:
In [29]:
s = zeros(m)
for Z in Zi1:
s += Z
s, s.subs(eigenvals)
Out[29]:
In [30]:
f_const = define(let=f(z), be=r)
f_const
Out[30]:
In [37]:
g_const = Hermite_interpolation_polynomial(f_const, eigendata, Phi_polynomials)
g_const
Out[37]:
In [38]:
g_const = g_const.subs(eigenvals)
g_const
Out[38]:
In [39]:
with lift_to_matrix_function(g_const) as G_const:
m_const = G_const(M)
m_const
Out[39]:
In [40]:
f_identity = Eq(f(z), z)
f_identity
Out[40]:
In [41]:
g_identity = Hermite_interpolation_polynomial(f_identity, eigendata, Phi_polynomials, matrix_form=True)
g_identity
Out[41]:
In [42]:
g_identity = Hermite_interpolation_polynomial(f_identity, eigendata, Phi_polynomials, matrix_form=False)
g_identity
Out[42]:
In [43]:
with lift_to_matrix_function(g_identity) as G_identity:
m_identity = G_identity(M)
m_identity
Out[43]:
In [44]:
f_sqrt = define(let=f(z), be=sqrt(z))
f_sqrt
Out[44]:
In [45]:
g_sqrt = Hermite_interpolation_polynomial(f_sqrt, eigendata, Phi_polynomials)
g_sqrt
Out[45]:
In [46]:
g_sqrt = g_sqrt.subs(eigenvals)
g_sqrt
Out[46]:
In [47]:
with lift_to_matrix_function(g_sqrt) as G_sqrt:
m_sqrt = G_sqrt(M)
m_sqrt
Out[47]:
In [50]:
assert (m_sqrt.rhs**2).applyfunc(simplify) == M.rhs
In [51]:
f_power = define(let=f(z), be=z**r)
f_power
Out[51]:
In [52]:
g_power = Hermite_interpolation_polynomial(f_power, eigendata, Phi_polynomials, matrix_form=True)
g_power
Out[52]:
In [54]:
g_power = Hermite_interpolation_polynomial(f_power, eigendata, Phi_polynomials)
g_power
Out[54]:
In [55]:
g_power = g_power.subs(eigenvals)
g_power.simplify()
Out[55]:
In [56]:
with lift_to_matrix_function(g_power) as G_power:
m_power = G_power(M)
m_power
Out[56]:
In [59]:
assert (M.rhs**r).applyfunc(simplify) == m_power.rhs
In [61]:
f_log = define(let=f(z), be=log(z, 2))
f_log
Out[61]:
In [62]:
g_log = Hermite_interpolation_polynomial(f_log, eigendata, Phi_polynomials)
g_log
Out[62]:
In [63]:
g_log = g_log.subs(eigenvals)
g_log
Out[63]:
In [64]:
with lift_to_matrix_function(g_log) as G_log:
M_log = G_log(M)
M_log
Out[64]:
In [65]:
f_inverse = define(let=f(z), be=1/z)
f_inverse
Out[65]:
In [66]:
g_inverse = Hermite_interpolation_polynomial(f_inverse, eigendata, Phi_polynomials)
g_inverse
Out[66]:
In [67]:
with lift_to_matrix_function(g_inverse) as G_inverse:
m_inverse = G_inverse(M)
m_inverse, m_inverse.rhs.subs(eigenvals)
Out[67]:
In [68]:
f_expt = define(let=f(z), be=exp(z))
f_expt
Out[68]:
In [69]:
g_expt = Hermite_interpolation_polynomial(f_expt, eigendata, Phi_polynomials)
g_expt
Out[69]:
In [70]:
g_expt = g_expt.subs(eigenvals)
g_expt
Out[70]:
In [71]:
with lift_to_matrix_function(g_expt) as G_expt:
m_expt = G_expt(M)
m_expt
Out[71]:
In [72]:
f_geo = define(let=f(z), be=(1-z**(r+1))/(1-z))
f_geo
Out[72]:
In [73]:
g_geo = Hermite_interpolation_polynomial(f_geo, eigendata, Phi_polynomials)
g_geo
Out[73]:
In [79]:
with lift_to_matrix_function(g_geo) as G_geo:
m_geo = G_geo(M)
m_geo
Out[79]:
In [82]:
m_geo= define(m_geo.lhs, m_geo.rhs.subs(eigenvals))
m_geo
Out[82]:
In [83]:
define(m_geo.lhs, m_geo.rhs.subs({r:4}))
Out[83]:
In [84]:
s = Function('s')
sum_def = define(let=s(z), be=Sum(z**i, (i, 0, 4)).doit())
sum_def
Out[84]:
In [86]:
with lift_to_matrix_function(sum_def) as sum_fn:
R = sum_fn(M)
R
Out[86]:
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.