Statistiques
| Révision :

root / pobysoPythonSage / src / sageSLZ / sageMatrixOperations.sage @ 74

Historique | Voir | Annoter | Télécharger (1,36 ko)

1 74 storres
def is_lower_triangular_matrix(mat):
2 74 storres
    """
3 74 storres
    Check that the matrix is lower triangular.
4 74 storres
    """
5 74 storres
    dimensions = mat.dimensions()
6 74 storres
    # Must be a bidimensional matrix.
7 74 storres
    if len(dimensions) != 2:
8 74 storres
        return False
9 74 storres
    # Must be square.
10 74 storres
    if dimensions[0] != dimensions[1]:
11 74 storres
        return False
12 74 storres
    # A 1x1 matrix is lower triangular.
13 74 storres
    if dimensions[0] == 1:
14 74 storres
        return True
15 74 storres
    for rowIndex in xrange(0, dimensions[0]):
16 74 storres
        for colIndex in xrange(rowIndex + 1, dimensions[1]):
17 74 storres
            if mat[rowIndex, colIndex] != 0:
18 74 storres
                print mat.rows()[rowIndex]
19 74 storres
                return False
20 74 storres
    return True
21 74 storres
# End is_lower_triangular_matrix
22 74 storres
23 74 storres
def is_diagonal_complete_matrix(mat):
24 74 storres
    """
25 74 storres
    Check that all the element on the diagonal are not 0.
26 74 storres
    """
27 74 storres
    dimensions = mat.dimensions()
28 74 storres
    # Must be a bidimensional matrix.
29 74 storres
    if len(dimensions) != 2:
30 74 storres
        return False
31 74 storres
    # Must be square.
32 74 storres
    if dimensions[0] != dimensions[1]:
33 74 storres
        return False
34 74 storres
    # A 1x1 matrix is diagonal complete if it's single element is not 0.
35 74 storres
    if dimensions[0] == 1:
36 74 storres
        if mat[0, 0] != 0:
37 74 storres
            return True
38 74 storres
        else:
39 74 storres
            return False
40 74 storres
    # End if
41 74 storres
    for rowIndex in xrange(0, dimensions[0]):
42 74 storres
        if mat[rowIndex, rowIndex] == 0:
43 74 storres
            print mat.rows()[rowIndex], rowIndex
44 74 storres
            return False
45 74 storres
    return True
46 74 storres
# End is_diagonal_complete_matrix