Esempio n. 1
0
    def test_inv1(self):
        a = [[1, 1, 1, 1], [1, 1, -1, -1], [1, -1, -1, 1], [1, -1, 1, -1]]
        b = matrix_inv.inv(a)
        c = matrix_inv.mult_square(a, b)
        d = matrix_inv.ident(4)

        self.assertEqual(c, d)
Esempio n. 2
0
    def test_inv2(self):
        a = [[2, 2, 0, 2], [4, 0, -4, -4], [0, -8, -8, 8], [16, -16, 16, -0]]
        b = matrix_inv.inv(a)
        c = matrix_inv.mult_square(a, b)
        d = matrix_inv.ident(4)

        self.assertEqual(c, d)
Esempio n. 3
0
    def test_inv4(self):
        a = [[1, 2, 1, 1], [1, 1, -1, -2], [1, -1, -1, 2], [1, -2, 1, -1]]
        b = matrix_inv.inv(a)
        c = [
            [0.25, 0.25, 0.25, 0.25],
            [0.2, 0.1, -0.1, -0.2],
            [0.25, -0.25, -0.25, 0.25],
            [0.1, -0.2, 0.2, -0.1],
        ]

        self.assertEqual(b, c)
Esempio n. 4
0
def main():
    args = parse(" ".join(sys.argv[1:]))
    if not args:
        raise SystemExit(USAGE)
    elif args.get("HELP"):
        print(USAGE)
        return
    elif args.get("INP"):
        matrix = process_stdin()
    else:
        matrix = read_infile(args["ARG1"])

    inverse = matrix_inv.inv(matrix)
    if args.get("ARG2"):
        save_inverse(args["ARG2"], inverse)
    else:
        input_string = """Input matrix: {}""".format(matrix)
        print(input_string)
        output_string = """Inverse matrix: {}""".format(inverse)
        print(output_string)
Esempio n. 5
0
    def test_inv3(self):
        a = matrix_inv.ident(4)
        b = matrix_inv.inv(a)

        self.assertEqual(a, b)