Révision 75 pobysoPythonSage/src/sageSLZ/sageMatrixOperations.sage

sageMatrixOperations.sage (revision 75)
1
def is_lower_triangular_matrix(mat):
1
def smo_is_diagonal_complete_matrix(mat):
2 2
    """
3
    Check that the matrix is lower triangular.
3
    Check that all the element on the diagonal are not 0.
4 4
    """
5 5
    dimensions = mat.dimensions()
6 6
    # Must be a bidimensional matrix.
......
9 9
    # Must be square.
10 10
    if dimensions[0] != dimensions[1]:
11 11
        return False
12
    # A 1x1 matrix is lower triangular.
12
    # A 1x1 matrix is diagonal complete if it's single element is not 0.
13 13
    if dimensions[0] == 1:
14
        return True
14
        if mat[0, 0] != 0:
15
            return True
16
        else:
17
            return False
18
    # End if
15 19
    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
        if mat[rowIndex, rowIndex] == 0:
21
            print mat.rows()[rowIndex], rowIndex
22
            return False
20 23
    return True
21
# End is_lower_triangular_matrix
24
# End smo_is_diagonal_complete_matrix
22 25

  
23
def is_diagonal_complete_matrix(mat):
26
def smo_is_lower_triangular_matrix(mat):
24 27
    """
25
    Check that all the element on the diagonal are not 0.
28
    Check that the matrix is lower triangular.
26 29
    """
27 30
    dimensions = mat.dimensions()
28 31
    # Must be a bidimensional matrix.
......
31 34
    # Must be square.
32 35
    if dimensions[0] != dimensions[1]:
33 36
        return False
34
    # A 1x1 matrix is diagonal complete if it's single element is not 0.
37
    # A 1x1 matrix is lower triangular.
35 38
    if dimensions[0] == 1:
36
        if mat[0, 0] != 0:
37
            return True
38
        else:
39
            return False
40
    # End if
39
        return True
41 40
    for rowIndex in xrange(0, dimensions[0]):
42
        if mat[rowIndex, rowIndex] == 0:
43
            print mat.rows()[rowIndex], rowIndex
44
            return False
41
        for colIndex in xrange(rowIndex + 1, dimensions[1]):
42
            if mat[rowIndex, colIndex] != 0:
43
                print mat.rows()[rowIndex]
44
                return False
45 45
    return True
46
# End is_diagonal_complete_matrix
46
# End smo_is_lower_triangular_matrix
47

  

Formats disponibles : Unified diff