@@ -0,0 +1,2644 @@
+from decimal import Decimal, getcontext%0Afrom copy import deepcopy%0A%0Afrom vector import Vector%0Afrom plane import Plane%0A%0Agetcontext().prec = 30%0A%0A%0Aclass LinearSystem(object):%0A%0A    ALL_PLANES_MUST_BE_IN_SAME_DIM_MSG = 'All planes in the system should live in the same dimension'%0A    NO_SOLUTIONS_MSG = 'No solutions'%0A    INF_SOLUTIONS_MSG = 'Infinitely many solutions'%0A%0A    def __init__(self, planes):%0A        try:%0A            d = planes%5B0%5D.dimension%0A            for p in planes:%0A                assert p.dimension == d%0A%0A            self.planes = planes%0A            self.dimension = d%0A%0A        except AssertionError:%0A            raise Exception(self.ALL_PLANES_MUST_BE_IN_SAME_DIM_MSG)%0A%0A%0A    def swap_rows(self, row1, row2):%0A        pass # add your code here%0A%0A%0A    def multiply_coefficient_and_row(self, coefficient, row):%0A        pass # add your code here%0A%0A%0A    def add_multiple_times_row_to_row(self, coefficient, row_to_add, row_to_be_added_to):%0A        pass # add your code here%0A%0A%0A    def indices_of_first_nonzero_terms_in_each_row(self):%0A        num_equations = len(self)%0A        num_variables = self.dimension%0A%0A        indices = %5B-1%5D * num_equations%0A%0A        for i,p in enumerate(self.planes):%0A            try:%0A                indices%5Bi%5D = p.first_nonzero_index(p.normal_vector)%0A            except Exception as e:%0A                if str(e) == Plane.NO_NONZERO_ELTS_FOUND_MSG:%0A                    continue%0A                else:%0A                    raise e%0A%0A        return indices%0A%0A%0A    def __len__(self):%0A        return len(self.planes)%0A%0A%0A    def __getitem__(self, i):%0A        return self.planes%5Bi%5D%0A%0A%0A    def __setitem__(self, i, x):%0A        try:%0A            assert x.dimension == self.dimension%0A            self.planes%5Bi%5D = x%0A%0A        except AssertionError:%0A            raise Exception(self.ALL_PLANES_MUST_BE_IN_SAME_DIM_MSG)%0A%0A%0A    def __str__(self):%0A        ret = 'Linear System:%5Cn'%0A        temp = %5B'Equation %7B%7D: %7B%7D'.format(i+1,p) for i,p in enumerate(self.planes)%5D%0A        ret += '%5Cn'.join(temp)%0A        return ret%0A%0A%0Aclass MyDecimal(Decimal):%0A    def is_near_zero(self, eps=1e-10):%0A        return abs(self) %3C eps%0A%0A%0Ap0 = Plane(normal_vector=Vector(%5B'1','1','1'%5D), constant_term='1')%0Ap1 = Plane(normal_vector=Vector(%5B'0','1','0'%5D), constant_term='2')%0Ap2 = Plane(normal_vector=Vector(%5B'1','1','-1'%5D), constant_term='3')%0Ap3 = Plane(normal_vector=Vector(%5B'1','0','-2'%5D), constant_term='2')%0A%0As = LinearSystem(%5Bp0,p1,p2,p3%5D)%0A%0Aprint s.indices_of_first_nonzero_terms_in_each_row()%0Aprint '%7B%7D,%7B%7D,%7B%7D,%7B%7D'.format(s%5B0%5D,s%5B1%5D,s%5B2%5D,s%5B3%5D)%0Aprint len(s)%0Aprint s%0A%0As%5B0%5D = p1%0Aprint s%0A%0Aprint MyDecimal('1e-9').is_near_zero()%0Aprint MyDecimal('1e-11').is_near_zero()%0A

add linsys