root / pobysoPythonSage / src / sageSLZ / sageMatrixOperations.sage @ 85
Historique | Voir | Annoter | Télécharger (2,06 ko)
1 |
def smo_is_diagonal_complete_matrix(mat): |
---|---|
2 |
""" |
3 |
Check that all the element on the diagonal are not 0. |
4 |
""" |
5 |
dimensions = mat.dimensions() |
6 |
# Must be a bidimensional matrix. |
7 |
if len(dimensions) != 2: |
8 |
return False |
9 |
# Must be square. |
10 |
if dimensions[0] != dimensions[1]: |
11 |
return False |
12 |
# A 1x1 matrix is diagonal complete if it's single element is not 0. |
13 |
if dimensions[0] == 1: |
14 |
if mat[0, 0] != 0: |
15 |
return True |
16 |
else: |
17 |
return False |
18 |
# End if |
19 |
for rowIndex in xrange(0, dimensions[0]): |
20 |
if mat[rowIndex, rowIndex] == 0: |
21 |
print mat.rows()[rowIndex], rowIndex |
22 |
return False |
23 |
return True |
24 |
# End smo_is_diagonal_complete_matrix |
25 |
|
26 |
def smo_is_lower_triangular_matrix(mat): |
27 |
""" |
28 |
Check that the matrix is lower triangular. |
29 |
""" |
30 |
dimensions = mat.dimensions() |
31 |
# Must be a bidimensional matrix. |
32 |
if len(dimensions) != 2: |
33 |
return False |
34 |
# Must be square. |
35 |
if dimensions[0] != dimensions[1]: |
36 |
return False |
37 |
# A 1x1 matrix is lower triangular. |
38 |
if dimensions[0] == 1: |
39 |
return True |
40 |
for rowIndex in xrange(0, dimensions[0]): |
41 |
for colIndex in xrange(rowIndex + 1, dimensions[1]): |
42 |
if mat[rowIndex, colIndex] != 0: |
43 |
print mat.rows()[rowIndex] |
44 |
return False |
45 |
return True |
46 |
# End smo_is_lower_triangular_matrix |
47 |
|
48 |
def smo_is_upper_triangular_matrix(mat): |
49 |
""" |
50 |
Check that the matrix is upper triangular. |
51 |
""" |
52 |
dimensions = mat.dimensions() |
53 |
# Must be a bidimensional matrix. |
54 |
if len(dimensions) != 2: |
55 |
return False |
56 |
# Must be square. |
57 |
if dimensions[0] != dimensions[1]: |
58 |
return False |
59 |
# A 1x1 matrix is lower triangular. |
60 |
if dimensions[0] == 1: |
61 |
return True |
62 |
for rowIndex in xrange(1, dimensions[0]): |
63 |
for colIndex in xrange(0, rowIndex): |
64 |
if mat[rowIndex, colIndex] != 0: |
65 |
print mat.rows()[rowIndex] |
66 |
return False |
67 |
return True |
68 |
# End smo_is_upper_triangular_matrix |
69 |
|
70 |
print "sageMatrixOperations loaded..." |