In [52]:
import numpy as np

In [53]:
from sympy import *
init_printing()

In [54]:
A=np.array([[.02, 0, 11.9, 0], [.05, .12, 5.7, 0], [0, .14, .21, .32], [0, 0, .43, .11]])
A


Out[54]:
array([[  0.02,   0.  ,  11.9 ,   0.  ],
       [  0.05,   0.12,   5.7 ,   0.  ],
       [  0.  ,   0.14,   0.21,   0.32],
       [  0.  ,   0.  ,   0.43,   0.11]])

In [55]:
iteraciones=20
X=np.zeros((iteraciones,4))
X[0]=np.array([0, 50, 50, 0])
for t in range(iteraciones-1):
    X[t+1]=A.dot(X[t])

In [56]:
import matplotlib.pyplot as plt

In [57]:
plt.show(plt.plot(X,'o'))
#las graficas van en orden
#se ven oscilaciones en las primeras 10 iteraciones

In [79]:
lambd=symbols('lambda')
#p=det(A[:4,:4]-lambd*eye(4))
##p
A[:4,:4]-lambd*eye(4)
#no funciona porque p tiene lambdas dividiendo


Out[79]:
$$\left[\begin{matrix}- \lambda + 0.02 & 0 & 11.9 & 0\\0.05 & - \lambda + 0.12 & 5.7 & 0\\0 & 0.14 & - \lambda + 0.21 & 0.32\\0 & 0 & 0.43 & - \lambda + 0.11\end{matrix}\right]$$

In [66]:
AAA=Matrix([[.02, 0, 11.9, 0], [.05, .12, 5.7, 0], [0, .14, .21, .32], [0, 0, .43, .11]])
p=det(AAA-lambd*eye(4))

In [71]:
p=det(A*100-lambd*eye(4))
roots(p)
#tiene raices reales: tres con modulo menor que 1 y una con modulo mayor que 1


Out[71]:
$$\left \{ -74.6335693782618 : 1, \quad -7.37970661370859 : 1, \quad 11.0742715409626 : 1, \quad 116.939004451008 : 1\right \}$$

In [72]:
lambd=symbols('lambda')
AA=Matrix([[2, 0, 1190, 0], [5, 12, 570, 0], [0, 14, 21, 32], [0, 0, 43, 11]])
p=det(AA-lambd*eye(4))
p


Out[72]:
$$\lambda^{4} - 46 \lambda^{3} - 8653 \lambda^{2} + 35702 \lambda + 713260$$

In [73]:
raices=list(roots(p))
raices


Out[73]:
$$\left [ \frac{23}{2} - \frac{1}{2} \sqrt{\frac{37786}{3} - 2 \sqrt[3]{- \frac{452067924025}{216} + \frac{5 i}{4} \sqrt{6659998069507141855}} + \frac{350968}{\sqrt{\frac{18893}{3} + \frac{88360405}{18 \sqrt[3]{- \frac{452067924025}{216} + \frac{5 i}{4} \sqrt{6659998069507141855}}} + 2 \sqrt[3]{- \frac{452067924025}{216} + \frac{5 i}{4} \sqrt{6659998069507141855}}}} - \frac{88360405}{18 \sqrt[3]{- \frac{452067924025}{216} + \frac{5 i}{4} \sqrt{6659998069507141855}}}} + \frac{1}{2} \sqrt{\frac{18893}{3} + \frac{88360405}{18 \sqrt[3]{- \frac{452067924025}{216} + \frac{5 i}{4} \sqrt{6659998069507141855}}} + 2 \sqrt[3]{- \frac{452067924025}{216} + \frac{5 i}{4} \sqrt{6659998069507141855}}}, \quad \frac{23}{2} + \frac{1}{2} \sqrt{\frac{37786}{3} - 2 \sqrt[3]{- \frac{452067924025}{216} + \frac{5 i}{4} \sqrt{6659998069507141855}} - \frac{350968}{\sqrt{\frac{18893}{3} + \frac{88360405}{18 \sqrt[3]{- \frac{452067924025}{216} + \frac{5 i}{4} \sqrt{6659998069507141855}}} + 2 \sqrt[3]{- \frac{452067924025}{216} + \frac{5 i}{4} \sqrt{6659998069507141855}}}} - \frac{88360405}{18 \sqrt[3]{- \frac{452067924025}{216} + \frac{5 i}{4} \sqrt{6659998069507141855}}}} - \frac{1}{2} \sqrt{\frac{18893}{3} + \frac{88360405}{18 \sqrt[3]{- \frac{452067924025}{216} + \frac{5 i}{4} \sqrt{6659998069507141855}}} + 2 \sqrt[3]{- \frac{452067924025}{216} + \frac{5 i}{4} \sqrt{6659998069507141855}}}, \quad \frac{23}{2} + \frac{1}{2} \sqrt{\frac{37786}{3} - 2 \sqrt[3]{- \frac{452067924025}{216} + \frac{5 i}{4} \sqrt{6659998069507141855}} + \frac{350968}{\sqrt{\frac{18893}{3} + \frac{88360405}{18 \sqrt[3]{- \frac{452067924025}{216} + \frac{5 i}{4} \sqrt{6659998069507141855}}} + 2 \sqrt[3]{- \frac{452067924025}{216} + \frac{5 i}{4} \sqrt{6659998069507141855}}}} - \frac{88360405}{18 \sqrt[3]{- \frac{452067924025}{216} + \frac{5 i}{4} \sqrt{6659998069507141855}}}} + \frac{1}{2} \sqrt{\frac{18893}{3} + \frac{88360405}{18 \sqrt[3]{- \frac{452067924025}{216} + \frac{5 i}{4} \sqrt{6659998069507141855}}} + 2 \sqrt[3]{- \frac{452067924025}{216} + \frac{5 i}{4} \sqrt{6659998069507141855}}}, \quad \frac{23}{2} - \frac{1}{2} \sqrt{\frac{18893}{3} + \frac{88360405}{18 \sqrt[3]{- \frac{452067924025}{216} + \frac{5 i}{4} \sqrt{6659998069507141855}}} + 2 \sqrt[3]{- \frac{452067924025}{216} + \frac{5 i}{4} \sqrt{6659998069507141855}}} - \frac{1}{2} \sqrt{\frac{37786}{3} - 2 \sqrt[3]{- \frac{452067924025}{216} + \frac{5 i}{4} \sqrt{6659998069507141855}} - \frac{350968}{\sqrt{\frac{18893}{3} + \frac{88360405}{18 \sqrt[3]{- \frac{452067924025}{216} + \frac{5 i}{4} \sqrt{6659998069507141855}}} + 2 \sqrt[3]{- \frac{452067924025}{216} + \frac{5 i}{4} \sqrt{6659998069507141855}}}} - \frac{88360405}{18 \sqrt[3]{- \frac{452067924025}{216} + \frac{5 i}{4} \sqrt{6659998069507141855}}}}\right ]$$

In [74]:
x=symbols('x:4')
sistema=AA-raices[1]*eye(4),zeros(4,1)
linsolve(sistema,x)


---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
<ipython-input-74-68ce4b909ed7> in <module>()
      1 x=symbols('x:4')
      2 sistema=AA-raices[1]*eye(4),zeros(4,1)
----> 3 linsolve(sistema,x)

C:\Users\Alumno\Anaconda2\lib\site-packages\sympy\solvers\solveset.pyc in linsolve(system, *symbols)
   1098     # Solve using Gauss-Jordan elimination
   1099     try:
-> 1100         sol, params, free_syms = A.gauss_jordan_solve(b, freevar=True)
   1101     except ValueError:
   1102         # No solution

C:\Users\Alumno\Anaconda2\lib\site-packages\sympy\matrices\matrices.pyc in gauss_jordan_solve(self, b, freevar)
   4330 
   4331         # solve by reduced row echelon form
-> 4332         A, pivots = aug.rref(simplify=True)
   4333         A, v = A[:, :-1], A[:, -1]
   4334         pivots = list(filter(lambda p: p < col, pivots))

C:\Users\Alumno\Anaconda2\lib\site-packages\sympy\matrices\matrices.pyc in rref(self, iszerofunc, simplify)
   2718                 break
   2719             if simplify:
-> 2720                 r[pivot, i] = simpfunc(r[pivot, i])
   2721             if iszerofunc(r[pivot, i]):
   2722                 for k in range(pivot, r.rows):

C:\Users\Alumno\Anaconda2\lib\site-packages\sympy\simplify\simplify.pyc in simplify(expr, ratio, measure, fu)
    544     expr = Mul(*powsimp(expr).as_content_primitive())
    545     _e = cancel(expr)
--> 546     expr1 = shorter(_e, _mexpand(_e).cancel())  # issue 6829
    547     expr2 = shorter(together(expr, deep=True), together(expr1, deep=True))
    548 

C:\Users\Alumno\Anaconda2\lib\site-packages\sympy\core\expr.pyc in cancel(self, *gens, **args)
   3076         """See the cancel function in sympy.polys"""
   3077         from sympy.polys import cancel
-> 3078         return cancel(self, *gens, **args)
   3079 
   3080     def invert(self, g, *gens, **args):

C:\Users\Alumno\Anaconda2\lib\site-packages\sympy\polys\polytools.pyc in cancel(f, *gens, **args)
   6329 
   6330     try:
-> 6331         (F, G), opt = parallel_poly_from_expr((p, q), *gens, **args)
   6332     except PolificationFailed:
   6333         if not isinstance(f, (tuple, Tuple)):

C:\Users\Alumno\Anaconda2\lib\site-packages\sympy\polys\polytools.pyc in parallel_poly_from_expr(exprs, *gens, **args)
   4166     """Construct polynomials from expressions. """
   4167     opt = options.build_options(gens, args)
-> 4168     return _parallel_poly_from_expr(exprs, opt)
   4169 
   4170 

C:\Users\Alumno\Anaconda2\lib\site-packages\sympy\polys\polytools.pyc in _parallel_poly_from_expr(exprs, opt)
   4205 
   4206                 if opt.expand:
-> 4207                     expr = expr.expand()
   4208         else:
   4209             failed = True

C:\Users\Alumno\Anaconda2\lib\site-packages\sympy\core\expr.pyc in expand(self, deep, modulus, power_base, power_exp, mul, log, multinomial, basic, **hints)
   2969             if hints.get('mul', False):
   2970                 expr, _ = Expr._expand_hint(
-> 2971                     expr, '_eval_expand_mul', deep=deep, **hints)
   2972             if hints.get('log', False):
   2973                 expr, _ = Expr._expand_hint(

C:\Users\Alumno\Anaconda2\lib\site-packages\sympy\core\expr.pyc in _expand_hint(expr, hint, deep, **hints)
   2893             sargs = []
   2894             for arg in expr.args:
-> 2895                 arg, arghit = Expr._expand_hint(arg, hint, **hints)
   2896                 hit |= arghit
   2897                 sargs.append(arg)

C:\Users\Alumno\Anaconda2\lib\site-packages\sympy\core\expr.pyc in _expand_hint(expr, hint, deep, **hints)
   2901 
   2902         if hasattr(expr, hint):
-> 2903             newexpr = getattr(expr, hint)(**hints)
   2904             if newexpr != expr:
   2905                 return (newexpr, True)

C:\Users\Alumno\Anaconda2\lib\site-packages\sympy\core\mul.pyc in _eval_expand_mul(self, **hints)
    821                     t = self.func(plain, term)
    822                     if t.is_Mul and any(a.is_Add for a in t.args):
--> 823                         t = t._eval_expand_mul()
    824                     args.append(t)
    825                 return Add(*args)

C:\Users\Alumno\Anaconda2\lib\site-packages\sympy\core\mul.pyc in _eval_expand_mul(self, **hints)
    814             return expr
    815         else:
--> 816             plain = self.func(*plain)
    817             if sums:
    818                 terms = self.func._expandsums(sums)

C:\Users\Alumno\Anaconda2\lib\site-packages\sympy\core\operations.pyc in __new__(cls, *args, **options)
     39             return args[0]
     40 
---> 41         c_part, nc_part, order_symbols = cls.flatten(args)
     42         is_commutative = not nc_part
     43         obj = cls._from_args(c_part + nc_part, is_commutative)

C:\Users\Alumno\Anaconda2\lib\site-packages\sympy\core\mul.pyc in flatten(cls, seq)
    602 
    603         # order commutative part canonically
--> 604         _mulsort(c_part)
    605 
    606         # current code expects coeff to be always in slot-0

C:\Users\Alumno\Anaconda2\lib\site-packages\sympy\core\mul.pyc in _mulsort(args)
     30 def _mulsort(args):
     31     # in-place sorting of args
---> 32     args.sort(key=_args_sortkey)
     33 
     34 

C:\Users\Alumno\Anaconda2\lib\functools.pyc in __lt__(self, other)
     85             self.obj = obj
     86         def __lt__(self, other):
---> 87             return mycmp(self.obj, other.obj) < 0
     88         def __gt__(self, other):
     89             return mycmp(self.obj, other.obj) > 0

C:\Users\Alumno\Anaconda2\lib\site-packages\sympy\core\basic.pyc in compare(self, other)
    175         n1 = self.__class__
    176         n2 = other.__class__
--> 177         c = (n1 > n2) - (n1 < n2)
    178         if c:
    179             return c

C:\Users\Alumno\Anaconda2\lib\site-packages\sympy\core\core.pyc in __gt__(cls, other)
    100 
    101     def __gt__(cls, other):
--> 102         if cls.__cmp__(other) == 1:
    103             return True
    104         return False

C:\Users\Alumno\Anaconda2\lib\site-packages\sympy\core\core.pyc in __cmp__(cls, other)
     87             i1 = UNKNOWN
     88         try:
---> 89             i2 = ordering_of_classes.index(n2)
     90         except ValueError:
     91             i2 = UNKNOWN

KeyboardInterrupt: 

In [43]:
Aa=Matrix([[2, 0, 1190, 0], [5, 12, 570, 0], [0, 14, 21, 32], [0, 0, 43, 11]])
Aa.jordan_cells()


---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
<ipython-input-43-86126e1a792a> in <module>()
      1 Aa=Matrix([[2, 0, 1190, 0], [5, 12, 570, 0], [0, 14, 21, 32], [0, 0, 43, 11]])
----> 2 Aa.jordan_cells()

C:\Users\Alumno\Anaconda2\lib\site-packages\sympy\matrices\matrices.pyc in jordan_cells(self, calc_transformation)
   3819         Jcells = []
   3820         Pcols_new = []
-> 3821         jordan_block_structures = self._jordan_block_structure()
   3822         from sympy.matrices import MutableMatrix
   3823 

C:\Users\Alumno\Anaconda2\lib\site-packages\sympy\matrices\matrices.pyc in _jordan_block_structure(self)
   3571         # that will eventually be used to form the transformation P
   3572         jordan_block_structures = {}
-> 3573         _eigenvects = self.eigenvects()
   3574         ev = self.eigenvals()
   3575         if len(ev) == 0:

C:\Users\Alumno\Anaconda2\lib\site-packages\sympy\matrices\matrices.pyc in eigenvects(self, **flags)
   3085         for r, k in vlist:
   3086             tmp = mat.as_mutable() - eye(mat.rows)*r
-> 3087             basis = tmp.nullspace()
   3088             # whether tmp.is_symbolic() is True or False, it is possible that
   3089             # the basis will come back as [] in which case simplification is

C:\Users\Alumno\Anaconda2\lib\site-packages\sympy\matrices\matrices.pyc in nullspace(self, simplify)
   2784         simpfunc = simplify if isinstance(
   2785             simplify, FunctionType) else _simplify
-> 2786         reduced, pivots = self.rref(simplify=simpfunc)
   2787 
   2788         basis = []

C:\Users\Alumno\Anaconda2\lib\site-packages\sympy\matrices\matrices.pyc in rref(self, iszerofunc, simplify)
   2718                 break
   2719             if simplify:
-> 2720                 r[pivot, i] = simpfunc(r[pivot, i])
   2721             if iszerofunc(r[pivot, i]):
   2722                 for k in range(pivot, r.rows):

C:\Users\Alumno\Anaconda2\lib\site-packages\sympy\simplify\simplify.pyc in simplify(expr, ratio, measure, fu)
    544     expr = Mul(*powsimp(expr).as_content_primitive())
    545     _e = cancel(expr)
--> 546     expr1 = shorter(_e, _mexpand(_e).cancel())  # issue 6829
    547     expr2 = shorter(together(expr, deep=True), together(expr1, deep=True))
    548 

C:\Users\Alumno\Anaconda2\lib\site-packages\sympy\core\expr.pyc in cancel(self, *gens, **args)
   3076         """See the cancel function in sympy.polys"""
   3077         from sympy.polys import cancel
-> 3078         return cancel(self, *gens, **args)
   3079 
   3080     def invert(self, g, *gens, **args):

C:\Users\Alumno\Anaconda2\lib\site-packages\sympy\polys\polytools.pyc in cancel(f, *gens, **args)
   6329 
   6330     try:
-> 6331         (F, G), opt = parallel_poly_from_expr((p, q), *gens, **args)
   6332     except PolificationFailed:
   6333         if not isinstance(f, (tuple, Tuple)):

C:\Users\Alumno\Anaconda2\lib\site-packages\sympy\polys\polytools.pyc in parallel_poly_from_expr(exprs, *gens, **args)
   4166     """Construct polynomials from expressions. """
   4167     opt = options.build_options(gens, args)
-> 4168     return _parallel_poly_from_expr(exprs, opt)
   4169 
   4170 

C:\Users\Alumno\Anaconda2\lib\site-packages\sympy\polys\polytools.pyc in _parallel_poly_from_expr(exprs, opt)
   4205 
   4206                 if opt.expand:
-> 4207                     expr = expr.expand()
   4208         else:
   4209             failed = True

C:\Users\Alumno\Anaconda2\lib\site-packages\sympy\core\expr.pyc in expand(self, deep, modulus, power_base, power_exp, mul, log, multinomial, basic, **hints)
   2969             if hints.get('mul', False):
   2970                 expr, _ = Expr._expand_hint(
-> 2971                     expr, '_eval_expand_mul', deep=deep, **hints)
   2972             if hints.get('log', False):
   2973                 expr, _ = Expr._expand_hint(

C:\Users\Alumno\Anaconda2\lib\site-packages\sympy\core\expr.pyc in _expand_hint(expr, hint, deep, **hints)
   2893             sargs = []
   2894             for arg in expr.args:
-> 2895                 arg, arghit = Expr._expand_hint(arg, hint, **hints)
   2896                 hit |= arghit
   2897                 sargs.append(arg)

C:\Users\Alumno\Anaconda2\lib\site-packages\sympy\core\expr.pyc in _expand_hint(expr, hint, deep, **hints)
   2893             sargs = []
   2894             for arg in expr.args:
-> 2895                 arg, arghit = Expr._expand_hint(arg, hint, **hints)
   2896                 hit |= arghit
   2897                 sargs.append(arg)

C:\Users\Alumno\Anaconda2\lib\site-packages\sympy\core\expr.pyc in _expand_hint(expr, hint, deep, **hints)
   2893             sargs = []
   2894             for arg in expr.args:
-> 2895                 arg, arghit = Expr._expand_hint(arg, hint, **hints)
   2896                 hit |= arghit
   2897                 sargs.append(arg)

C:\Users\Alumno\Anaconda2\lib\site-packages\sympy\core\expr.pyc in _expand_hint(expr, hint, deep, **hints)
   2893             sargs = []
   2894             for arg in expr.args:
-> 2895                 arg, arghit = Expr._expand_hint(arg, hint, **hints)
   2896                 hit |= arghit
   2897                 sargs.append(arg)

C:\Users\Alumno\Anaconda2\lib\site-packages\sympy\core\expr.pyc in _expand_hint(expr, hint, deep, **hints)
   2893             sargs = []
   2894             for arg in expr.args:
-> 2895                 arg, arghit = Expr._expand_hint(arg, hint, **hints)
   2896                 hit |= arghit
   2897                 sargs.append(arg)

C:\Users\Alumno\Anaconda2\lib\site-packages\sympy\core\expr.pyc in _expand_hint(expr, hint, deep, **hints)
   2893             sargs = []
   2894             for arg in expr.args:
-> 2895                 arg, arghit = Expr._expand_hint(arg, hint, **hints)
   2896                 hit |= arghit
   2897                 sargs.append(arg)

C:\Users\Alumno\Anaconda2\lib\site-packages\sympy\core\expr.pyc in _expand_hint(expr, hint, deep, **hints)
   2905                 return (newexpr, True)
   2906 
-> 2907         return (expr, hit)
   2908 
   2909     @cacheit

KeyboardInterrupt: 

In [ ]: