Exemplo n.º 1
0
    def test_jet_extend_basis1(self):
        x1, x2, x3 = xx = sp.Matrix(sp.symbols("x1, x2, x3"))
        xx_tmp, ddx = pc.setup_objects(xx)

        self.assertTrue(xx is xx_tmp)

        # get the individual forms
        dx1, dx2, dx3 = ddx

        dx1.jet_extend_basis()
        self.assertTrue(len(dx1.basis) == 2 * len(xx))
        self.assertTrue(dx1.coeff[0] == 1)
        self.assertFalse(any(dx1.coeff[1:]))

        # derivative coordinates
        xdot1, xdot2, xdot3 = xxd = pc.st.time_deriv(xx, xx)
        ext_basis = pc.st.row_stack(xx, xxd)

        w1 = xdot1 * dx2
        w1.jet_extend_basis()
        self.assertEqual(w1.basis[3], w1.coeff[1])

        dw1 = w1.d
        res1 = pc.d(xdot1, ext_basis) ^ pc.d(x2, ext_basis)
        self.assertEqual(dw1, res1)

        w2 = x3 * dx2
        self.assertEqual(w2.dim_basis, len(xx))
        w2.jet_extend_basis()
        self.assertEqual(w2.dim_basis, len(ext_basis))

        dw2 = w2.d
        res2 = -dx2 ^ dx3
        res2.jet_extend_basis()
        self.assertEqual(dw2, res2)
Exemplo n.º 2
0
    def test_integrate1(self):
        x1, x2, x3, x4, x5 = self.xx

        a, b = sp.symbols('a, b', nonzero=True)

        if 1:
            y1 = x1 + sin(x3) * x2
            dy1 = pc.d(y1, self.xx)
            self.assertTrue(dy1.d.is_zero())
            y1b = dy1.integrate()
            self.assertEqual(y1, y1b)

            y1 = 0
            dy1 = pc.d(y1, self.xx)
            y1b = dy1.integrate()
            self.assertEqual(y1, y1b)

            y1 = x1
            dy1 = pc.d(y1, self.xx)
            y1b = dy1.integrate()
            self.assertEqual(y1, y1b)

            y1 = x1 + x2
            dy1 = pc.d(y1, self.xx)
            y1b = dy1.integrate()
            self.assertEqual(y1, y1b)

            y1 = x2 * cos(x1) + x5 * cos(x4)
            dy1 = pc.d(y1, self.xx)
            y1b = dy1.integrate()
            self.assertEqual(y1, y1b)

            y1 = sin(x1) * cos(x2) + x5 * cos(x4)
            dy1 = pc.d(y1, self.xx)
            y1b = dy1.integrate()
            self.assertEqual(y1, y1b)

            y1 = sin(x1 + x2 + x3)
            dy1 = pc.d(y1, self.xx)
            y1b = dy1.integrate()
            self.assertEqual(y1, y1b)

            y1 = a * x1 + b * x2 + a * b * cos(x3)
            dy1 = pc.d(y1, self.xx)
            y1b = dy1.integrate()
            self.assertEqual(sp.simplify(y1 - y1b), 0)

            y1 = x1 + sin(x3) * x2**2 * sp.exp(x1) + sin(x2) * x3
            # y1 = x1 + sin(x3)*x2**1*sp.exp(x1) + sin(x2)*x3
            dy1 = pc.d(y1, self.xx)
            y1b = dy1.integrate()
            self.assertEqual(y1, y1b)

            y1 = sin(x1 + x2 + x3)
            dy1 = pc.d(y1, self.xx)
            w = x1 * dy1
            self.assertFalse(w.d.is_zero())
            with self.assertRaises(ValueError) as cm:
                w.integrate()
Exemplo n.º 3
0
    def test_gradient(self):
        x1, x2, x3, x4, x5 = self.xx

        h1 = x1
        h2 = x3 * x1 * sin(x4) * exp(x5) + x2

        dh1 = pc.d(h1, self.xx)
        dh2 = pc.d(h2, self.xx)

        self.assertEqual(dh1.coeff[0], 1)

        self.assertEqual(dh2.coeff[0], h2.diff(x1))
        self.assertEqual(dh2.coeff[1], h2.diff(x2))
        self.assertEqual(dh2.coeff[2], h2.diff(x3))
        self.assertEqual(dh2.coeff[3], h2.diff(x4))
        self.assertEqual(dh2.coeff[4], h2.diff(x5))
Exemplo n.º 4
0
    def test_integrate3(self):
        x1, x2, x3, x4, x5 = self.xx

        a, b = sp.symbols('a, b', nonzero=True)

        if 1:
            y1 = -x3 * cos(x1)
            dy1 = pc.d(y1, self.xx)
            self.assertTrue(dy1.d.is_zero())
            y1b = dy1.integrate()
            self.assertEqual(y1, y1b)
Exemplo n.º 5
0
    def test_pull_back_to_sphere(self):
        """
        pull back the differential of the function F = (y1**2 + y2**2 + y3**2)
        it must vanish on the sphere. Hereby we use spherical coordinates
        to consider the sphere as immersed submanifold of R3
        """

        yy = y1, y2, y3 = sp.symbols("y1:4")
        xx = x1, x2 = sp.symbols("x1:3")

        F = y1**2 + y2**2 + y3**2
        omega = pc.d(F, yy)  # omega = dF

        # spherical coordinates:
        phi = sp.Matrix([cos(x1) * cos(x2), sin(x1) * cos(x2), sin(x2)])

        # calculate the pull back transformation of omega along phi_*
        p = pc.pull_back(phi, xx, omega)

        self.assertTrue(p.is_zero())
Exemplo n.º 6
0
    def test_integrate2(self):
        x1, x2, x3, x4, x5 = self.xx

        a, b = sp.symbols('a, b', nonzero=True)

        if 1:
            # tests for some simplification problem

            y1 = sp.log(x2) + sp.log(cos(x1))
            dx1, dx2, dx3, dx4, dx5 = self.dx
            dy1 = (-sp.tan(x1)) * dx1 + (1 / x2) * dx2
            y1b = dy1.integrate()
            self.assertEqual(y1, y1b)

            y1 = sp.log(x2) + sp.log(sin(x1) - 1) / 2 + sp.log(sin(x1) + 1) / 2
            dx1, dx2, dx3, dx4, dx5 = self.dx
            dy1 = (-sp.tan(x1)) * dx1 + (1 / x2) * dx2
            y1b = dy1.integrate()
            difference = y1 - y1b
            # this is not zero but it does not depend on xx:
            grad = sp.simplify(st.gradient(difference, self.xx))
            self.assertEqual(grad, grad * 0)

            # another variant
            y1 = sp.log(x2) + sp.log(sin(x1) - 1) / 2 + sp.log(sin(x1) + 1) / 2
            dx1, dx2, dx3, dx4, dx5 = self.dx
            dy1 = (-sp.sin(x1) / sp.cos(x1)) * dx1 + (1 / x2) * dx2
            y1b = dy1.integrate()
            difference = y1 - y1b
            # this is not zero but it does not depend on xx:
            grad = sp.simplify(st.gradient(difference, self.xx))
            self.assertEqual(grad, grad * 0)

            y1 = a * sp.log(cos(b * x1))
            dy1 = pc.d(y1, self.xx)
            y1b = dy1.integrate()
            self.assertEqual(sp.simplify(y1 - y1b), 0)