Statistiques
| Révision :

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

Historique | Voir | Annoter | Télécharger (2,06 ko)

1 75 storres
def smo_is_diagonal_complete_matrix(mat):
2 74 storres
    """
3 75 storres
    Check that all the element on the diagonal are not 0.
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 75 storres
    # A 1x1 matrix is diagonal complete if it's single element is not 0.
13 74 storres
    if dimensions[0] == 1:
14 75 storres
        if mat[0, 0] != 0:
15 75 storres
            return True
16 75 storres
        else:
17 75 storres
            return False
18 75 storres
    # End if
19 74 storres
    for rowIndex in xrange(0, dimensions[0]):
20 75 storres
        if mat[rowIndex, rowIndex] == 0:
21 75 storres
            print mat.rows()[rowIndex], rowIndex
22 75 storres
            return False
23 74 storres
    return True
24 75 storres
# End smo_is_diagonal_complete_matrix
25 74 storres
26 75 storres
def smo_is_lower_triangular_matrix(mat):
27 74 storres
    """
28 75 storres
    Check that the matrix is lower triangular.
29 74 storres
    """
30 74 storres
    dimensions = mat.dimensions()
31 74 storres
    # Must be a bidimensional matrix.
32 74 storres
    if len(dimensions) != 2:
33 74 storres
        return False
34 74 storres
    # Must be square.
35 74 storres
    if dimensions[0] != dimensions[1]:
36 74 storres
        return False
37 75 storres
    # A 1x1 matrix is lower triangular.
38 74 storres
    if dimensions[0] == 1:
39 75 storres
        return True
40 74 storres
    for rowIndex in xrange(0, dimensions[0]):
41 75 storres
        for colIndex in xrange(rowIndex + 1, dimensions[1]):
42 75 storres
            if mat[rowIndex, colIndex] != 0:
43 75 storres
                print mat.rows()[rowIndex]
44 75 storres
                return False
45 74 storres
    return True
46 75 storres
# End smo_is_lower_triangular_matrix
47 75 storres
48 83 storres
def smo_is_upper_triangular_matrix(mat):
49 83 storres
    """
50 83 storres
    Check that the matrix is upper triangular.
51 83 storres
    """
52 83 storres
    dimensions = mat.dimensions()
53 83 storres
    # Must be a bidimensional matrix.
54 83 storres
    if len(dimensions) != 2:
55 83 storres
        return False
56 83 storres
    # Must be square.
57 83 storres
    if dimensions[0] != dimensions[1]:
58 83 storres
        return False
59 83 storres
    # A 1x1 matrix is lower triangular.
60 83 storres
    if dimensions[0] == 1:
61 83 storres
        return True
62 83 storres
    for rowIndex in xrange(1, dimensions[0]):
63 83 storres
        for colIndex in xrange(0, rowIndex):
64 83 storres
            if mat[rowIndex, colIndex] != 0:
65 83 storres
                print mat.rows()[rowIndex]
66 83 storres
                return False
67 83 storres
    return True
68 83 storres
# End smo_is_upper_triangular_matrix
69 83 storres
70 83 storres
print "sageMatrixOperations loaded..."