def prod(l):
    a=1
    i=0
    while i<range(len(l)):
        a=a*l[i]
        i=i+1
    return a    
        
def chck_sum(A):
    l=A.eigenvalues()
    tr=A.trace()
    if sum(l)==tr:
        print "sum is equal"
    else:
        print "not equal sum"    
def chck_prod(A):
    l=A.eigenvalues()
    a=det(A)
    b=prod(l)
    if a==b:
        print "product equal"
    else:
        print "product not equal"


A=matrix([[3,4,2],[0,1,2],[0,0,0]])            
chck_sum(A)
out:sum is equal

chck_prod(A)
out:product not equal

B=matrix([[0,0,2],[0,2,0],[2,0,0]])
chck_sum(B)
out:sum is equal

chck_prod(B)
out:product not equal   

Strang-241-5-U (last edited 2010-12-17 06:37:38 by rupampy)