示例#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))
示例#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))
示例#3
0
    def test_right_shift_all2(self):
        a, b = sp.symbols("a, b", commutative=False)

        ab = sp.Matrix([a, b])
        adot, bdot = ab_dot = st.time_deriv(ab, ab)

        sab = sp.Matrix([s*a, s*b])

        res1 = nct.right_shift_all(sab, func_symbols=ab)
        res2 = ab_dot + nct.nc_mul(ab, s)

        self.assertEqual(res1, res2)

        res = nct.right_shift_all(s, s, t)
        self.assertEqual(res, s)

        res = nct.right_shift_all(s**2, s, t)
        self.assertEqual(res, s**2)

        res = nct.right_shift_all(a, s, t)
        self.assertEqual(res, a)

        res = nct.right_shift_all(a**(sp.S(1)/2), s, t)
        self.assertEqual(res, a**(sp.S(1)/2))

        res = nct.right_shift_all(s*1/a, s, func_symbols=ab)
        self.assertEqual(res, 1/a*s -1/a**2*adot)

        res = nct.right_shift_all(s + sp.sin(a), s, func_symbols=ab)
        self.assertEqual(res, s + sp.sin(a))

        self.assertRaises( ValueError, nct.right_shift_all, s**(sp.S(1)/2), s, t)

        self.assertRaises( ValueError, nct.right_shift_all, sp.sin(s), s, t)
示例#4
0
    def test_right_shift_all_naive(self):
        a, b = sp.symbols("a, b", commutative=False)

        ab = sp.Matrix([a, b])
        adot, bdot = ab_dot = st.time_deriv(ab, ab)
        addot, bddot = ab_ddot = st.time_deriv(ab, ab, order=2)

        sab = sp.Matrix([s*a, s*b])
        abs = sp.Matrix([a*s, b*s])

        res1 = nct.right_shift_all(sab, func_symbols=None)
        self.assertEqual(res1, abs)

        # normally derivatives are recognized as time dependent automatically
        res2 = nct.right_shift_all(s*adot)
        self.assertEqual(res2, addot + adot*s)

        # if func_symbols=None derivatives are like constants
        res3 = nct.right_shift_all(s*adot, func_symbols=None)
        self.assertEqual(res3, adot*s)
示例#5
0
    def right_shift_all_in_matrix(self, matrix):
        # does nct-package provide this already?
        m,n = matrix.shape
        matrix_shifted = sp.Matrix([])
        t_dep_symbols = [symb for symb in st.atoms(matrix, sp.Symbol) if not symb == s]
        for i in xrange(n):
            col = matrix.col(i)
            col_shifted = sp.Matrix([nct.right_shift_all(expr,s,t, t_dep_symbols) for expr in col])
            matrix_shifted = st.concat_cols(matrix_shifted, col_shifted)

        return matrix_shifted
示例#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))
示例#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))
示例#8
0
    def test_right_shift_all(self):
        a, b = sp.symbols("a, b", commutative=False)
        f1 = sp.Function('f1', commutative=False)(t)
        f2 = sp.Function('f2', commutative=False)(t)
        f1d = f1.diff(t)
        f2d = f2.diff(t)

        p1 = s*(f1 + f2)

        ab = sp.Matrix([a, b])
        adot, bdot = st.time_deriv(ab, ab)

        res1 = nct.right_shift_all(p1)
        self.assertEqual(res1, f1d + f1*s + f2d + f2*s)

        res2 = nct.right_shift_all(f1**-1, s, t)
        self.assertEqual(res2, 1/f1)

        res3 = nct.right_shift_all(s*a + s*a*b, s, t, [])
        self.assertEqual(res3, a*s + a*b*s)

        res4 = nct.right_shift_all(s*a + s*a*b, s, t, [a, b])
        self.assertEqual(res4, a*s + a*b*s + adot + a*bdot + adot*b)
示例#9
0
    def right_shift_all_in_matrix(self, matrix):
        # does nct-package provide this already?
        m, n = matrix.shape
        matrix_shifted = sp.Matrix([])
        t_dep_symbols = [
            symb for symb in st.atoms(matrix, sp.Symbol) if not symb == s
        ]
        for i in range(n):
            col = matrix.col(i)
            col_shifted = sp.Matrix([
                nct.right_shift_all(expr, s, t, t_dep_symbols) for expr in col
            ])
            matrix_shifted = st.concat_cols(matrix_shifted, col_shifted)

        return matrix_shifted
示例#10
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))
示例#11
0
文件: core.py 项目: cknoll/pycartan
    def left_mul_by(self, matrix, s=None, additional_symbols=None):
        """ Performs matrix*vectorform and returns the new vectorform.
            additional_symbols is an optional list of time_dependent symbols
            Note: matrix is assumed to be polynomial in s
        """
        assert isinstance(matrix, sp.MatrixBase)

        m1, n1 = matrix.shape
        assert n1 == self.m, "Matrix Dimesion does not fit vector form!"

        # right shift s:
        matrix_shifted = nct.right_shift_all(matrix,
                                             s=s,
                                             func_symbols=additional_symbols)

        # if s is of higher order, raise not implemented
        if not s == None and matrix_shifted.diff(s).has(s):
            raise NotImplementedError

        if s == None:
            M0 = matrix_shifted
        else:
            M1 = matrix_shifted.diff(s)
            M0 = matrix_shifted - M1 * s

        new_vector_form = VectorDifferentialForm(self.degree, self.basis)
        for i in range(0, m1):
            new_wi = DifferentialForm(1, self.basis)
            for j in range(0, n1):
                new_wi += M0[i, j] * self.get_differential_form(j)
                if not s == None:
                    new_wi += M1[i, j] * self.get_differential_form(j).dot(
                        additional_symbols)
            new_vector_form.append(new_wi)

        return new_vector_form