Esempio n. 1
0
    def simple_root(self, i):
        """The ith simple root of F_4

        Every lie algebra has a unique root system.
        Given a root system Q, there is a subset of the
        roots such that an element of Q is called a
        simple root if it cannot be written as the sum
        of two elements in Q.  If we let D denote the
        set of simple roots, then it is clear that every
        element of Q can be written as a linear combination
        of elements of D with all coefficients non-negative.

        Examples
        ========

        >>> from sympy.liealgebras.cartan_type import CartanType
        >>> c = CartanType("F4")
        >>> c.simple_root(3)
        [0, 0, 0, 1]

        """

        if i < 3:
            return self.basic_root(i-1, i)
        if i == 3:
            root = [0]*4
            root[3] = 1
            return root
        if i == 4:
            root = [Rational(-1, 2)]*4
            return root
Esempio n. 2
0
def test_linearize_rolling_disc_kane():
    # Symbols for time and constant parameters
    t, r, m, g, v = symbols('t r m g v')

    # Configuration variables and their time derivatives
    q1, q2, q3, q4, q5, q6 = q = dynamicsymbols('q1:7')
    q1d, q2d, q3d, q4d, q5d, q6d = qd = [qi.diff(t) for qi in q]

    # Generalized speeds and their time derivatives
    u = dynamicsymbols('u:6')
    u1, u2, u3, u4, u5, u6 = u = dynamicsymbols('u1:7')
    u1d, u2d, u3d, u4d, u5d, u6d = [ui.diff(t) for ui in u]

    # Reference frames
    N = ReferenceFrame('N')                   # Inertial frame
    NO = Point('NO')                          # Inertial origin
    A = N.orientnew('A', 'Axis', [q1, N.z])   # Yaw intermediate frame
    B = A.orientnew('B', 'Axis', [q2, A.x])   # Lean intermediate frame
    C = B.orientnew('C', 'Axis', [q3, B.y])   # Disc fixed frame
    CO = NO.locatenew('CO', q4*N.x + q5*N.y + q6*N.z)      # Disc center

    # Disc angular velocity in N expressed using time derivatives of coordinates
    w_c_n_qd = C.ang_vel_in(N)
    w_b_n_qd = B.ang_vel_in(N)

    # Inertial angular velocity and angular acceleration of disc fixed frame
    C.set_ang_vel(N, u1*B.x + u2*B.y + u3*B.z)

    # Disc center velocity in N expressed using time derivatives of coordinates
    v_co_n_qd = CO.pos_from(NO).dt(N)

    # Disc center velocity in N expressed using generalized speeds
    CO.set_vel(N, u4*C.x + u5*C.y + u6*C.z)

    # Disc Ground Contact Point
    P = CO.locatenew('P', r*B.z)
    P.v2pt_theory(CO, N, C)

    # Configuration constraint
    f_c = Matrix([q6 - dot(CO.pos_from(P), N.z)])

    # Velocity level constraints
    f_v = Matrix([dot(P.vel(N), uv) for uv in C])

    # Kinematic differential equations
    kindiffs = Matrix([dot(w_c_n_qd - C.ang_vel_in(N), uv) for uv in B] +
                        [dot(v_co_n_qd - CO.vel(N), uv) for uv in N])
    qdots = solve(kindiffs, qd)

    # Set angular velocity of remaining frames
    B.set_ang_vel(N, w_b_n_qd.subs(qdots))
    C.set_ang_acc(N, C.ang_vel_in(N).dt(B) + cross(B.ang_vel_in(N), C.ang_vel_in(N)))

    # Active forces
    F_CO = m*g*A.z

    # Create inertia dyadic of disc C about point CO
    I = (m * r**2) / 4
    J = (m * r**2) / 2
    I_C_CO = inertia(C, I, J, I)

    Disc = RigidBody('Disc', CO, C, m, (I_C_CO, CO))
    BL = [Disc]
    FL = [(CO, F_CO)]
    KM = KanesMethod(N, [q1, q2, q3, q4, q5], [u1, u2, u3], kd_eqs=kindiffs,
            q_dependent=[q6], configuration_constraints=f_c,
            u_dependent=[u4, u5, u6], velocity_constraints=f_v)
    with warns_deprecated_sympy():
        (fr, fr_star) = KM.kanes_equations(FL, BL)

    # Test generalized form equations
    linearizer = KM.to_linearizer()
    assert linearizer.f_c == f_c
    assert linearizer.f_v == f_v
    assert linearizer.f_a == f_v.diff(t)
    sol = solve(linearizer.f_0 + linearizer.f_1, qd)
    for qi in qd:
        assert sol[qi] == qdots[qi]
    assert simplify(linearizer.f_2 + linearizer.f_3 - fr - fr_star) == Matrix([0, 0, 0])

    # Perform the linearization
    # Precomputed operating point
    q_op = {q6: -r*cos(q2)}
    u_op = {u1: 0,
            u2: sin(q2)*q1d + q3d,
            u3: cos(q2)*q1d,
            u4: -r*(sin(q2)*q1d + q3d)*cos(q3),
            u5: 0,
            u6: -r*(sin(q2)*q1d + q3d)*sin(q3)}
    qd_op = {q2d: 0,
             q4d: -r*(sin(q2)*q1d + q3d)*cos(q1),
             q5d: -r*(sin(q2)*q1d + q3d)*sin(q1),
             q6d: 0}
    ud_op = {u1d: 4*g*sin(q2)/(5*r) + sin(2*q2)*q1d**2/2 + 6*cos(q2)*q1d*q3d/5,
             u2d: 0,
             u3d: 0,
             u4d: r*(sin(q2)*sin(q3)*q1d*q3d + sin(q3)*q3d**2),
             u5d: r*(4*g*sin(q2)/(5*r) + sin(2*q2)*q1d**2/2 + 6*cos(q2)*q1d*q3d/5),
             u6d: -r*(sin(q2)*cos(q3)*q1d*q3d + cos(q3)*q3d**2)}

    A, B = linearizer.linearize(op_point=[q_op, u_op, qd_op, ud_op], A_and_B=True, simplify=True)

    upright_nominal = {q1d: 0, q2: 0, m: 1, r: 1, g: 1}

    # Precomputed solution
    A_sol = Matrix([[0, 0, 0, 0, 0, 0, 0, 1],
                    [0, 0, 0, 0, 0, 1, 0, 0],
                    [0, 0, 0, 0, 0, 0, 1, 0],
                    [sin(q1)*q3d, 0, 0, 0, 0, -sin(q1), -cos(q1), 0],
                    [-cos(q1)*q3d, 0, 0, 0, 0, cos(q1), -sin(q1), 0],
                    [0, Rational(4, 5), 0, 0, 0, 0, 0, 6*q3d/5],
                    [0, 0, 0, 0, 0, 0, 0, 0],
                    [0, 0, 0, 0, 0, -2*q3d, 0, 0]])
    B_sol = Matrix([])

    # Check that linearization is correct
    assert A.subs(upright_nominal) == A_sol
    assert B.subs(upright_nominal) == B_sol

    # Check eigenvalues at critical speed are all zero:
    assert A.subs(upright_nominal).subs(q3d, 1/sqrt(3)).eigenvals() == {0: 8}
Esempio n. 3
0
    def positive_roots(self):
        """
        This method generates all the positive roots of
        A_n.  This is half of all of the roots of E_n;
        by multiplying all the positive roots by -1 we
        get the negative roots.

        Examples
        ========

        >>> from sympy.liealgebras.cartan_type import CartanType
        >>> c = CartanType("A3")
        >>> c.positive_roots()
        {1: [1, -1, 0, 0], 2: [1, 0, -1, 0], 3: [1, 0, 0, -1], 4: [0, 1, -1, 0],
                5: [0, 1, 0, -1], 6: [0, 0, 1, -1]}
        """
        n = self.n
        if n == 6:
            posroots = {}
            k = 0
            for i in range(n - 1):
                for j in range(i + 1, n - 1):
                    k += 1
                    root = self.basic_root(i, j)
                    posroots[k] = root
                    k += 1
                    root = self.basic_root(i, j)
                    root[i] = 1
                    posroots[k] = root

            root = [
                Rational(1, 2),
                Rational(1, 2),
                Rational(1, 2),
                Rational(1, 2),
                Rational(1, 2),
                Rational(-1, 2),
                Rational(-1, 2),
                Rational(1, 2)
            ]
            for a in range(0, 2):
                for b in range(0, 2):
                    for c in range(0, 2):
                        for d in range(0, 2):
                            for e in range(0, 2):
                                if (a + b + c + d + e) % 2 == 0:
                                    k += 1
                                    if a == 1:
                                        root[0] = Rational(-1, 2)
                                    if b == 1:
                                        root[1] = Rational(-1, 2)
                                    if c == 1:
                                        root[2] = Rational(-1, 2)
                                    if d == 1:
                                        root[3] = Rational(-1, 2)
                                    if e == 1:
                                        root[4] = Rational(-1, 2)
                                    posroots[k] = root

            return posroots
        if n == 7:
            posroots = {}
            k = 0
            for i in range(n - 1):
                for j in range(i + 1, n - 1):
                    k += 1
                    root = self.basic_root(i, j)
                    posroots[k] = root
                    k += 1
                    root = self.basic_root(i, j)
                    root[i] = 1
                    posroots[k] = root

            k += 1
            posroots[k] = [0, 0, 0, 0, 0, 1, 1, 0]
            root = [
                Rational(1, 2),
                Rational(1, 2),
                Rational(1, 2),
                Rational(1, 2),
                Rational(1, 2),
                Rational(-1, 2),
                Rational(-1, 2),
                Rational(1, 2)
            ]
            for a in range(0, 2):
                for b in range(0, 2):
                    for c in range(0, 2):
                        for d in range(0, 2):
                            for e in range(0, 2):
                                for f in range(0, 2):
                                    if (a + b + c + d + e + f) % 2 == 0:
                                        k += 1
                                        if a == 1:
                                            root[0] = Rational(-1, 2)
                                        if b == 1:
                                            root[1] = Rational(-1, 2)
                                        if c == 1:
                                            root[2] = Rational(-1, 2)
                                        if d == 1:
                                            root[3] = Rational(-1, 2)
                                        if e == 1:
                                            root[4] = Rational(-1, 2)
                                        if f == 1:
                                            root[5] = Rational(1, 2)
                                        posroots[k] = root

            return posroots
        if n == 8:
            posroots = {}
            k = 0
            for i in range(n):
                for j in range(i + 1, n):
                    k += 1
                    root = self.basic_root(i, j)
                    posroots[k] = root
                    k += 1
                    root = self.basic_root(i, j)
                    root[i] = 1
                    posroots[k] = root

            root = [
                Rational(1, 2),
                Rational(1, 2),
                Rational(1, 2),
                Rational(1, 2),
                Rational(1, 2),
                Rational(-1, 2),
                Rational(-1, 2),
                Rational(1, 2)
            ]
            for a in range(0, 2):
                for b in range(0, 2):
                    for c in range(0, 2):
                        for d in range(0, 2):
                            for e in range(0, 2):
                                for f in range(0, 2):
                                    for g in range(0, 2):
                                        if (a + b + c + d + e + f +
                                                g) % 2 == 0:
                                            k += 1
                                            if a == 1:
                                                root[0] = Rational(-1, 2)
                                            if b == 1:
                                                root[1] = Rational(-1, 2)
                                            if c == 1:
                                                root[2] = Rational(-1, 2)
                                            if d == 1:
                                                root[3] = Rational(-1, 2)
                                            if e == 1:
                                                root[4] = Rational(-1, 2)
                                            if f == 1:
                                                root[5] = Rational(1, 2)
                                            if g == 1:
                                                root[6] = Rational(1, 2)
                                            posroots[k] = root

            return posroots
Esempio n. 4
0
    def positive_roots(self):
        """Generate all the positive roots of A_n

        This is half of all of the roots of F_4; by multiplying all the
        positive roots by -1 we get the negative roots.

        Examples
        ========

        >>> from sympy.liealgebras.cartan_type import CartanType
        >>> c = CartanType("A3")
        >>> c.positive_roots()
        {1: [1, -1, 0, 0], 2: [1, 0, -1, 0], 3: [1, 0, 0, -1], 4: [0, 1, -1, 0],
                5: [0, 1, 0, -1], 6: [0, 0, 1, -1]}

        """

        n = self.n
        posroots = {}
        k = 0
        for i in range(0, n-1):
            for j in range(i+1, n):
               k += 1
               posroots[k] = self.basic_root(i, j)
               k += 1
               root = self.basic_root(i, j)
               root[j] = 1
               posroots[k] = root

        for i in range(0, n):
            k += 1
            root = [0]*n
            root[i] = 1
            posroots[k] = root

        k += 1
        root = [Rational(1, 2)]*n
        posroots[k] = root
        for i in range(1, 4):
            k += 1
            root = [Rational(1, 2)]*n
            root[i] = Rational(-1, 2)
            posroots[k] = root

        posroots[k+1] = [Rational(1, 2), Rational(1, 2), Rational(-1, 2), Rational(-1, 2)]
        posroots[k+2] = [Rational(1, 2), Rational(-1, 2), Rational(1, 2), Rational(-1, 2)]
        posroots[k+3] = [Rational(1, 2), Rational(-1, 2), Rational(-1, 2), Rational(1, 2)]
        posroots[k+4] = [Rational(1, 2), Rational(-1, 2), Rational(-1, 2), Rational(-1, 2)]

        return posroots
Esempio n. 5
0
    def matrix_form(self, weylelt):
        """
        This method takes input from the user in the form of products of the
        generating reflections, and returns the matrix corresponding to the
        element of the Weyl group.  Since each element of the Weyl group is
        a reflection of some type, there is a corresponding matrix representation.
        This method uses the standard representation for all the generating
        reflections.

        Examples
        ========

        >>> from sympy.liealgebras.weyl_group import WeylGroup
        >>> f = WeylGroup("F4")
        >>> f.matrix_form('r2*r3')
        Matrix([
        [1, 0, 0,  0],
        [0, 1, 0,  0],
        [0, 0, 0, -1],
        [0, 0, 1,  0]])

        """
        elts = list(weylelt)
        reflections = elts[1::3]
        n = self.cartan_type.rank()
        if self.cartan_type.series == "A":
            matrixform = eye(n + 1)
            for elt in reflections:
                a = int(elt)
                mat = eye(n + 1)
                mat[a - 1, a - 1] = 0
                mat[a - 1, a] = 1
                mat[a, a - 1] = 1
                mat[a, a] = 0
                matrixform *= mat
            return matrixform

        if self.cartan_type.series == "D":
            matrixform = eye(n)
            for elt in reflections:
                a = int(elt)
                mat = eye(n)
                if a < n:
                    mat[a - 1, a - 1] = 0
                    mat[a - 1, a] = 1
                    mat[a, a - 1] = 1
                    mat[a, a] = 0
                    matrixform *= mat
                else:
                    mat[n - 2, n - 1] = -1
                    mat[n - 2, n - 2] = 0
                    mat[n - 1, n - 2] = -1
                    mat[n - 1, n - 1] = 0
                    matrixform *= mat
            return matrixform

        if self.cartan_type.series == "G":
            matrixform = eye(3)
            for elt in reflections:
                a = int(elt)
                if a == 1:
                    gen1 = Matrix([[1, 0, 0], [0, 0, 1], [0, 1, 0]])
                    matrixform *= gen1
                else:
                    gen2 = Matrix(
                        [
                            [Rational(2, 3), Rational(2, 3), Rational(-1, 3)],
                            [Rational(2, 3), Rational(-1, 3), Rational(2, 3)],
                            [Rational(-1, 3), Rational(2, 3), Rational(2, 3)],
                        ]
                    )
                    matrixform *= gen2
            return matrixform

        if self.cartan_type.series == "F":
            matrixform = eye(4)
            for elt in reflections:
                a = int(elt)
                if a == 1:
                    mat = Matrix(
                        [[1, 0, 0, 0], [0, 0, 1, 0], [0, 1, 0, 0], [0, 0, 0, 1]]
                    )
                    matrixform *= mat
                elif a == 2:
                    mat = Matrix(
                        [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0]]
                    )
                    matrixform *= mat
                elif a == 3:
                    mat = Matrix(
                        [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, -1]]
                    )
                    matrixform *= mat
                else:

                    mat = Matrix(
                        [
                            [
                                Rational(1, 2),
                                Rational(1, 2),
                                Rational(1, 2),
                                Rational(1, 2),
                            ],
                            [
                                Rational(1, 2),
                                Rational(1, 2),
                                Rational(-1, 2),
                                Rational(-1, 2),
                            ],
                            [
                                Rational(1, 2),
                                Rational(-1, 2),
                                Rational(1, 2),
                                Rational(-1, 2),
                            ],
                            [
                                Rational(1, 2),
                                Rational(-1, 2),
                                Rational(-1, 2),
                                Rational(1, 2),
                            ],
                        ]
                    )
                    matrixform *= mat
            return matrixform

        if self.cartan_type.series == "E":
            matrixform = eye(8)
            for elt in reflections:
                a = int(elt)
                if a == 1:
                    mat = Matrix(
                        [
                            [
                                Rational(3, 4),
                                Rational(1, 4),
                                Rational(1, 4),
                                Rational(1, 4),
                                Rational(1, 4),
                                Rational(1, 4),
                                Rational(1, 4),
                                Rational(-1, 4),
                            ],
                            [
                                Rational(1, 4),
                                Rational(3, 4),
                                Rational(-1, 4),
                                Rational(-1, 4),
                                Rational(-1, 4),
                                Rational(-1, 4),
                                Rational(1, 4),
                                Rational(-1, 4),
                            ],
                            [
                                Rational(1, 4),
                                Rational(-1, 4),
                                Rational(3, 4),
                                Rational(-1, 4),
                                Rational(-1, 4),
                                Rational(-1, 4),
                                Rational(-1, 4),
                                Rational(1, 4),
                            ],
                            [
                                Rational(1, 4),
                                Rational(-1, 4),
                                Rational(-1, 4),
                                Rational(3, 4),
                                Rational(-1, 4),
                                Rational(-1, 4),
                                Rational(-1, 4),
                                Rational(1, 4),
                            ],
                            [
                                Rational(1, 4),
                                Rational(-1, 4),
                                Rational(-1, 4),
                                Rational(-1, 4),
                                Rational(3, 4),
                                Rational(-1, 4),
                                Rational(-1, 4),
                                Rational(1, 4),
                            ],
                            [
                                Rational(1, 4),
                                Rational(-1, 4),
                                Rational(-1, 4),
                                Rational(-1, 4),
                                Rational(-1, 4),
                                Rational(3, 4),
                                Rational(-1, 4),
                                Rational(1, 4),
                            ],
                            [
                                Rational(1, 4),
                                Rational(-1, 4),
                                Rational(-1, 4),
                                Rational(-1, 4),
                                Rational(-1, 4),
                                Rational(-1, 4),
                                Rational(-3, 4),
                                Rational(1, 4),
                            ],
                            [
                                Rational(1, 4),
                                Rational(-1, 4),
                                Rational(-1, 4),
                                Rational(-1, 4),
                                Rational(-1, 4),
                                Rational(-1, 4),
                                Rational(-1, 4),
                                Rational(3, 4),
                            ],
                        ]
                    )
                    matrixform *= mat
                elif a == 2:
                    mat = eye(8)
                    mat[0, 0] = 0
                    mat[0, 1] = -1
                    mat[1, 0] = -1
                    mat[1, 1] = 0
                    matrixform *= mat
                else:
                    mat = eye(8)
                    mat[a - 3, a - 3] = 0
                    mat[a - 3, a - 2] = 1
                    mat[a - 2, a - 3] = 1
                    mat[a - 2, a - 2] = 0
                    matrixform *= mat
            return matrixform

        if self.cartan_type.series == "B" or self.cartan_type.series == "C":
            matrixform = eye(n)
            for elt in reflections:
                a = int(elt)
                mat = eye(n)
                if a == 1:
                    mat[0, 0] = -1
                    matrixform *= mat
                else:
                    mat[a - 2, a - 2] = 0
                    mat[a - 2, a - 1] = 1
                    mat[a - 1, a - 2] = 1
                    mat[a - 1, a - 1] = 0
                    matrixform *= mat
            return matrixform