コード例 #1
0
def test_ge_1():
    p1 = Plane(normal_vector=Vector(['5.862', '1.178', '-10.366']),
               constant_term='-8.15')
    p2 = Plane(normal_vector=Vector(['-2.931', '-0.589', '5.183']),
               constant_term='-4.075')
    s = LinearSystem([p1, p2])
    try:
        ge = s.compute_gaussian_elimination()
        print('failed GE test 1')
        assert False
    except Exception as e:
        if str(e) == LinearSystem.NO_SOLUTIONS_MSG:
            pass  # print('passed GE test 1')
        else:
            print('failed GE test 1')
            assert False
コード例 #2
0
def test_ge_3():
    p1 = Plane(Vector([5.262, 2.739, -9.878]), -3.441)
    p2 = Plane(Vector([5.111, 6.358, 7.638]), -2.152)
    p3 = Plane(Vector([2.016, -9.924, -1.367]), -9.278)
    p4 = Plane(Vector([2.167, -13.543, -18.883]), -10.567)
    s = LinearSystem([p1, p2, p3, p4])
    try:
        ge = s.compute_gaussian_elimination()
        assert ge == Vector([
            Decimal('-1.17720187578995858313947665146'),
            Decimal('0.707150558138740933006474968216'),
            Decimal('-0.0826635849022828890650647196936')
        ])
        # print('failed GE test 3')
    except Exception as e:
        print('failed GE test 3')
        assert False
コード例 #3
0
def test_ge_2():
    p1 = Plane(normal_vector=Vector(['8.631', '5.112', '-1.816']),
               constant_term='-5.113')
    p2 = Plane(normal_vector=Vector(['4.315', '11.132', '-5.27']),
               constant_term='-6.775')
    p3 = Plane(normal_vector=Vector(['-2.158', '3.01', '-1.727']),
               constant_term='-0.831')
    s = LinearSystem([p1, p2, p3])
    try:
        ge = s.compute_gaussian_elimination()
        print('failed GE test 2')
        assert False
    except Exception as e:
        if str(e) == LinearSystem.INF_SOLUTIONS_MSG:
            pass  # print('passed GE test 2')
        else:
            print('failed GE test 2')
            assert False
コード例 #4
0
        # print('failed GE test 3')
    except Exception as e:
        print('failed GE test 3')
        assert False


##################################### Quiz: Coding Parametrization ###########################
# Hooray all of these pass.
# See https://classroom.udacity.com/courses/ud953/lessons/4624329808/concepts/48972686550923#
# TODO: turn these into unit tests.

# Fixed equation from github -
p1 = Plane(Vector([0.786, 0.786, 0.588]), -0.714)
p2 = Plane(Vector([-0.131, -0.131, 0.244]), 0.319)
s = LinearSystem([p1, p2])
param_version = s.compute_gaussian_elimination(True)
print("\nparam test 1:")
print(param_version)

p1 = Plane(Vector([8.631, 5.112, -1.816]), -5.113)
p2 = Plane(Vector([4.315, 11.132, -5.27]), -6.775)
p3 = Plane(Vector([-2.158, 3.01, -1.727]), -0.831)
s = LinearSystem([p1, p2, p3])
param_version = s.compute_gaussian_elimination(True)
print("\nparam test 2:")
print(param_version)

p1 = Plane(Vector([0.935, 1.76, -9.365]), -9.955)
p2 = Plane(Vector([0.187, 0.352, -1.873]), -1.991)
p3 = Plane(Vector([0.374, 0.704, -3.746]), -3.982)
p4 = Plane(Vector([-0.561, -1.056, 5.619]), 5.973)