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))
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))
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))
def test_unimod_inv2(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) # this Matrix is not unimodular due to factor 13 (should be 1) M3 = sp.Matrix([[ydot2, 13*y1*s], [y2*yddot2 + y2*ydot2*s, y1*yddot2 + y2*y1*s**2 + y2*ydot1*s + ydot2*ydot1]]) with self.assertRaises(ValueError) as cm: res = nct.unimod_inv(M3, s, time_dep_symbs=yya)
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))
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))