Beispiel #1
0
def demo_eigen_number():
    m = Matrix(3,3,[2,1,0,0,2,1,0,0,2])
    pprint(m)
    print "\nany n*n matrix has n complex eigen values, counted with multiplications\n"\
            "since the characteritic polynomial is n-dim\n"\
            "and Fundamental Theorem of Algebra gives us exactly n roots:"
    pprint(m.charpoly().as_expr())
    print"\neach distinct eigen value as at least 1 at most multiplication eigen vectors\n"\
            "but it's possible to have less than multiplication number of eigen vectors\n"\
            "the given matrix is an example with only 1 eigen vector:\n"
    pprint(m.eigenvects())
    print "to see this for any vector v we can compute M * v:\n"
    v = IndexedBase('v')
    vec = Matrix(m.rows, 1, lambda i, j: v[i+1])
    pprint(vec)
    pprint(m*vec)
Beispiel #2
0
def check_positive_definite(A: type_A):
    """
    1. General Method
    Cholesky decomposition will fail only when the matrix is not symmetric positive semi definite. Thus, if the algorithm doesn’t work, then you know your matrix is not symmetric positive semidefinite.
    2. (Assume A is Hermitian)
    "A is positive definite if and only if all of its eigenvalues are
    positive. (keep in mind that eigenvalues' are not required to be
    distinctive to one another)"
    https://en.wikipedia.org/wiki/Definiteness_of_a_matrix#Eigenvalues
    """
    # How to check symmetric matrix is positive-definite
    # Check Gershgorin circle theorem
    symmetry = check_symmetry(A)
    assert symmetry, "positive definite only defined for symmetric matrix"

    if A.shape[0] == 2 :
        M = Matrix(A)
        roots = M.charpoly().all_roots()
        return all(element > 0 for element in roots)
    pass
Beispiel #3
0
import numpy
from sympy import *
from sympy.matrices import Matrix
x = Symbol('x')
A = Matrix(([-5,-5,-9],[8,9,18],[-2,-3,-7]))
# list_eye = lambda n: numpy.eye(n).tolist()
p = A.charpoly(x)
print roots(p,x)