コード例 #1
0
def test_calculating_the_determinant_of_a_3x3_matrix():
    # Given
    A = Matrix(1, 2, 6,
               -5, 8, -4,
               2, 6, 4)
    # Then
    assert A.cofactor(0, 0) == 56
    assert A.cofactor(0, 1) == 12
    assert A.cofactor(0, 2) == -46
    assert A.determinant() == -196
コード例 #2
0
def test_calculating_a_cofactor_of_a_3x3_matrix():
    # Given
    A = Matrix(3, 5, 0,
               2, -1, -7,
               6, -1, 5)
    # Then
    assert A.minor(0, 0) == -12
    assert A.cofactor(0, 0) == -12
    assert A.minor(1, 0) == 25
    assert A.cofactor(1, 0) == -25
コード例 #3
0
def test_calculating_the_determinant_of_a_4x4_matrix():
    # Given
    A = Matrix(-2, -8, 3, 5,
               -3, 1, 7, 3,
               1, 2, -9, 6,
               -6, 7, 7, -9)
    # Then
    assert A.cofactor(0, 0) == 690
    assert A.cofactor(0, 1) == 447
    assert A.cofactor(0, 2) == 210
    assert A.cofactor(0, 3) == 51
    assert A.determinant() == -4071
コード例 #4
0
def test_calculating_the_inverse_of_a_matrix():
    # Given
    A = Matrix(-5, 2, 6, -8,
               1, -5, 1, 8,
               7, 7, -6, -7,
               1, -3, 7, 4)
    B = A.inverse()
    # Then
    assert A.determinant() == 532
    assert A.cofactor(2, 3) == -160
    assert equal(B.at(3, 2), -160/532)
    assert A.cofactor(3, 2) == 105
    assert equal(B.at(2, 3), 105/532)
    assert B == Matrix(0.21805, 0.45113, 0.24060, -0.04511,
                       -0.80827, -1.45677, -0.44361, 0.52068,
                       -0.07895, -0.22368, -0.05263, 0.19737,
                       -0.52256, -0.81391, -0.30075, 0.30639)