def chck_posdef2(X):
    list=X.eigenvalues()
    l=[]
    for i in list:
        if i>=0:
            l.append(i)
        
    if list==l:
        if 0 in list:
            print "pos sem"
        else:
            print "pos"
    elif len(l)==0:
        print "neg"
    else:
        print "ind"    
        
A=matrix([[1,2,3],[2,5,4],[3,4,9]])
chck_posdef2(A)
out:ind

B=matrix([[1,2,0,0],[2,6,-2,0],[0,-2,5,-2],[0,0,-2,3]])
chck_posdef2(B)
out:pos

C=-B
chck_posdef2(C)
out:neg

D=A**(-1)
chck_posdef2(D)
out:ind

Strang-325-14-U (last edited 2010-12-17 04:53:59 by rupampy)