Example #1
0
    def test_unimod_inv3(self):
        y1, y2 = yy = st.symb_vector('y1, y2', commutative=False)
        s = sp.Symbol('s', commutative=False)
        ydot1, ydot2 = yyd1 = st.time_deriv(yy, yy, order=1, commutative=False)
        yddot1, yddot2 = yyd2 = st.time_deriv(yy,
                                              yy,
                                              order=2,
                                              commutative=False)
        yyd3 = st.time_deriv(yy, yy, order=3, commutative=False)
        yyd4 = st.time_deriv(yy, yy, order=4, commutative=False)
        yya = st.row_stack(yy, yyd1, yyd2, yyd3, yyd4)

        M3 = sp.Matrix([[ydot2, y1 * s],
                        [
                            y2 * yddot2 + y2 * ydot2 * s, y1 * yddot2 +
                            y2 * y1 * s**2 + y2 * ydot1 * s + ydot2 * ydot1
                        ]])

        M3inv = nct.unimod_inv(M3, s, time_dep_symbs=yya)

        product3a = nct.right_shift_all(nct.nc_mul(M3, M3inv),
                                        s,
                                        func_symbols=yya)
        product3b = nct.right_shift_all(nct.nc_mul(M3inv, M3),
                                        s,
                                        func_symbols=yya)
        res3a = nct.make_all_symbols_commutative(product3a)[0]
        res3b = nct.make_all_symbols_commutative(product3b)[0]
        res3a.simplify()
        res3b.simplify()

        self.assertEqual(res3a, sp.eye(2))
        self.assertEqual(res3b, sp.eye(2))
Example #2
0
    def test_unimod_inv(self):
        y1, y2 = yy = st.symb_vector('y1, y2', commutative=False)
        s = sp.Symbol('s', commutative=False)
        ydot1, ydot2 = yyd1 = st.time_deriv(yy, yy, order=1, commutative=False)
        yddot1, yddot2 = yyd2 = st.time_deriv(yy,
                                              yy,
                                              order=2,
                                              commutative=False)
        yyd3 = st.time_deriv(yy, yy, order=3, commutative=False)
        yyd4 = st.time_deriv(yy, yy, order=4, commutative=False)
        yya = st.row_stack(yy, yyd1, yyd2, yyd3, yyd4)

        M1 = sp.Matrix([yy[0]])
        M1inv = nct.unimod_inv(M1, s, time_dep_symbs=yy)
        self.assertEqual(M1inv, M1.inv())

        M2 = sp.Matrix([[y1, y1 * s], [0, y2]])
        M2inv = nct.unimod_inv(M2, s, time_dep_symbs=yy)

        product2a = nct.right_shift_all(nct.nc_mul(M2, M2inv),
                                        s,
                                        func_symbols=yya)
        product2b = nct.right_shift_all(nct.nc_mul(M2inv, M2),
                                        s,
                                        func_symbols=yya)

        res2a = nct.make_all_symbols_commutative(product2a)[0]
        res2b = nct.make_all_symbols_commutative(product2b)[0]
        self.assertEqual(res2a, sp.eye(2))
        self.assertEqual(res2b, sp.eye(2))
Example #3
0
    def test_make_all_symbols_commutative(self):

        a, b, c = sp.symbols("a, b, c", commutative=False)
        x, y = sp.symbols("x, y")

        exp1 = a*b*x + b*c*y
        exp2 = b*a*x + c*y*b

        diff = exp1 - exp2

        self.assertFalse(diff == 0)
        diff_c, subs_tuples = nct.make_all_symbols_commutative(diff)
        exp1_c, subs_tuples = nct.make_all_symbols_commutative(exp1)

        self.assertTrue( all([r.is_commutative for r in exp1_c.atoms()]) )
Example #4
0
    def test_make_all_symbols_commutative2(self):
        import pickle
        path = make_abspath('test_data', 'Q_matrix_cart_pendulum.pcl')
        with open(path, 'rb') as pfile:
            Q = pickle.load(pfile)

        Qc, stl = nct.make_all_symbols_commutative(Q, '')
Example #5
0
    def test_make_all_symbols_commutative3(self):
        x1, x2, x3 = xx = st.symb_vector('x1, x2, x3', commutative=False)

        xxd = st.time_deriv(xx, xx)

        xxd_c = nct.make_all_symbols_commutative(xxd)[0]

        self.assertEqual(xxd_c[0].difforder, 1)
Example #6
0
    def test_unimod_inv3(self):
        y1, y2 = yy = st.symb_vector('y1, y2', commutative=False)
        s = sp.Symbol('s', commutative=False)
        ydot1, ydot2 = yyd1 = st.time_deriv(yy, yy, order=1, commutative=False)
        yddot1, yddot2 = yyd2 = st.time_deriv(yy, yy, order=2, commutative=False)
        yyd3 = st.time_deriv(yy, yy, order=3, commutative=False)
        yyd4 = st.time_deriv(yy, yy, order=4, commutative=False)
        yya = st.row_stack(yy, yyd1, yyd2, yyd3, yyd4)

        M3 = sp.Matrix([[ydot2,                                              y1*s],
                       [y2*yddot2 + y2*ydot2*s, y1*yddot2 + y2*y1*s**2 + y2*ydot1*s + ydot2*ydot1]])

        M3inv = nct.unimod_inv(M3, s, time_dep_symbs=yya)

        product3a = nct.right_shift_all( nct.nc_mul(M3, M3inv), s, func_symbols=yya)
        product3b = nct.right_shift_all( nct.nc_mul(M3inv, M3), s, func_symbols=yya)
        res3a = nct.make_all_symbols_commutative(product3a)[0]
        res3b = nct.make_all_symbols_commutative(product3b)[0]
        res3a.simplify()
        res3b.simplify()

        self.assertEqual(res3a, sp.eye(2))
        self.assertEqual(res3b, sp.eye(2))
Example #7
0
    def test_unimod_inv(self):
        y1, y2 = yy = st.symb_vector('y1, y2', commutative=False)
        s = sp.Symbol('s', commutative=False)
        ydot1, ydot2 = yyd1 = st.time_deriv(yy, yy, order=1, commutative=False)
        yddot1, yddot2 = yyd2 = st.time_deriv(yy, yy, order=2, commutative=False)
        yyd3 = st.time_deriv(yy, yy, order=3, commutative=False)
        yyd4 = st.time_deriv(yy, yy, order=4, commutative=False)
        yya = st.row_stack(yy, yyd1, yyd2, yyd3, yyd4)

        M1 = sp.Matrix([yy[0]])
        M1inv = nct.unimod_inv(M1, s, time_dep_symbs=yy)
        self.assertEqual(M1inv, M1.inv())

        M2 = sp.Matrix([[y1, y1*s], [0, y2]])
        M2inv = nct.unimod_inv(M2, s, time_dep_symbs=yy)

        product2a = nct.right_shift_all( nct.nc_mul(M2, M2inv), s, func_symbols=yya)
        product2b = nct.right_shift_all( nct.nc_mul(M2inv, M2), s, func_symbols=yya)

        res2a = nct.make_all_symbols_commutative( product2a)[0]
        res2b = nct.make_all_symbols_commutative( product2b)[0]
        self.assertEqual(res2a, sp.eye(2))
        self.assertEqual(res2b, sp.eye(2))
Example #8
0
    def test_unimod_inv4(self):
        path = make_abspath('test_data', 'unimod_matrix_unicycle.pcl')
        with open(path, 'rb') as pfile:
            pdict = pickle.load(pfile)

        PQ = pdict['PQ']
        s = [ symb for symb in PQ.s if str(symb) == "s"][0]
        self.assertTrue(s in PQ.s)

        abc = pdict['abc']
        #kk = pdict['kk']
        #JEh = pdict['JEh']

        inv = nct.unimod_inv(PQ, s, None, abc, max_deg=2)
        res = nct.nc_mul(inv, PQ)
        res2 = nct.right_shift_all(res, s, None, abc)
        res3, tmp = nct.make_all_symbols_commutative(res2)
        res4 = st.subs_random_numbers(res3, prime=True)
        self.assertEqual(res4, sp.eye(3))