root / pobysoPythonSage / src / sageSLZ / sageMatrixOperations.sage @ 74
Historique | Voir | Annoter | Télécharger (1,36 ko)
| 1 |
def is_lower_triangular_matrix(mat): |
|---|---|
| 2 |
""" |
| 3 |
Check that the matrix is lower triangular. |
| 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 lower triangular. |
| 13 |
if dimensions[0] == 1: |
| 14 |
return True |
| 15 |
for rowIndex in xrange(0, dimensions[0]): |
| 16 |
for colIndex in xrange(rowIndex + 1, dimensions[1]): |
| 17 |
if mat[rowIndex, colIndex] != 0: |
| 18 |
print mat.rows()[rowIndex] |
| 19 |
return False |
| 20 |
return True |
| 21 |
# End is_lower_triangular_matrix |
| 22 |
|
| 23 |
def is_diagonal_complete_matrix(mat): |
| 24 |
""" |
| 25 |
Check that all the element on the diagonal are not 0. |
| 26 |
""" |
| 27 |
dimensions = mat.dimensions() |
| 28 |
# Must be a bidimensional matrix. |
| 29 |
if len(dimensions) != 2: |
| 30 |
return False |
| 31 |
# Must be square. |
| 32 |
if dimensions[0] != dimensions[1]: |
| 33 |
return False |
| 34 |
# A 1x1 matrix is diagonal complete if it's single element is not 0. |
| 35 |
if dimensions[0] == 1: |
| 36 |
if mat[0, 0] != 0: |
| 37 |
return True |
| 38 |
else: |
| 39 |
return False |
| 40 |
# End if |
| 41 |
for rowIndex in xrange(0, dimensions[0]): |
| 42 |
if mat[rowIndex, rowIndex] == 0: |
| 43 |
print mat.rows()[rowIndex], rowIndex |
| 44 |
return False |
| 45 |
return True |
| 46 |
# End is_diagonal_complete_matrix |