(self)
return self.eom
Method to form Lagrange's equations of motion.

        Returns a vector of equations of motion using Lagrange's equations of
        the second kind.
Method to form Lagrange's equations of motion.
Method to form Lagrange s equations of motion .
def form_lagranges_equations(self):
        """Method to form Lagrange's equations of motion.

        Returns a vector of equations of motion using Lagrange's equations of
        the second kind.

        """

        q = self._q
        qd = self._qdots
        qdd = self._qdoubledots
        n = len(q)

        #Putting the Lagrangian in a Matrix
        L = Matrix([self._L])

        #Determining the first term in Lagrange's EOM
        self._term1 = L.jacobian(qd)
        self._term1 = ((self._term1).diff(dynamicsymbols._t)).transpose()

        #Determining the second term in Lagrange's EOM
        self._term2 = (L.jacobian(q)).transpose()

        #term1 and term2 will be there no matter what so leave them as they are

        if self.coneqs is not None:
            coneqs = self.coneqs
            #If there are coneqs supplied then the following will be created
            coneqs = list(coneqs)
            if not isinstance(coneqs, list):
                raise TypeError('Enter the constraint equations in a list')

            o = len(coneqs)

            #Creating the multipliers
            self.lam_vec = Matrix(dynamicsymbols('lam1:' + str(o + 1)))

            #Extracting the coeffecients of the multipliers
            coneqs_mat = Matrix(coneqs)
            qd = self._qdots
            self.lam_coeffs = -coneqs_mat.jacobian(qd)

            #Determining the third term in Lagrange's EOM
            #term3 = ((self.lam_vec).transpose() * self.lam_coeffs).transpose()
            self._term3 = self.lam_coeffs.transpose() * self.lam_vec

            #Taking the time derivative of the constraint equations
            diffconeqs = [diff(i, dynamicsymbols._t) for i in coneqs]

            #Extracting the coeffecients of the qdds from the diff coneqs
            diffconeqs_mat = Matrix(diffconeqs)
            qdd = self._qdoubledots
            self._m_cd = diffconeqs_mat.jacobian(qdd)

            #The remaining terms i.e. the 'forcing' terms in diff coneqs
            qddzero = dict(zip(qdd, [0] * n))
            self._f_cd = -diffconeqs_mat.subs(qddzero)

        else:
            self._term3 = zeros(n, 1)

        if self.forcelist is not None:
            forcelist = self.forcelist
            N = self.inertial
            if not isinstance(N, ReferenceFrame):
                raise TypeError('Enter a valid ReferenceFrame')
            if not isinstance(forcelist, (list, tuple)):
                raise TypeError('Forces must be supplied in a list of: lists'
                        ' or tuples')
            self._term4 = zeros(n, 1)
            for i, v in enumerate(qd):
                for j, w in enumerate(forcelist):
                    if isinstance(w[0], ReferenceFrame):
                        speed = w[0].ang_vel_in(N)
                        self._term4[i] += speed.diff(v, N) & w[1]
                    elif isinstance(w[0], Point):
                        speed = w[0].vel(N)
                        self._term4[i] += speed.diff(v, N) & w[1]
                    else:
                        raise TypeError('First entry in force pair is a point'
                                        ' or frame')

        else:
            self._term4 = zeros(n, 1)

        self.eom = self._term1 - self._term2 - self._term3 - self._term4

        return self.eom
def form_lagranges_equations ( self ) : q = self . _q qd = self . _qdots qdd = self . _qdoubledots n = len ( q ) #Putting the Lagrangian in a Matrix L = Matrix ( [ self . _L ] ) #Determining the first term in Lagrange's EOM self . _term1 = L . jacobian ( qd ) self . _term1 = ( ( self . _term1 ) . diff ( dynamicsymbols . _t ) ) . transpose ( ) #Determining the second term in Lagrange's EOM self . _term2 = ( L . jacobian ( q ) ) . transpose ( ) #term1 and term2 will be there no matter what so leave them as they are if self . coneqs is not None : coneqs = self . coneqs #If there are coneqs supplied then the following will be created coneqs = list ( coneqs ) if not isinstance ( coneqs , list ) : raise TypeError ( 'Enter the constraint equations in a list' ) o = len ( coneqs ) #Creating the multipliers self . lam_vec = Matrix ( dynamicsymbols ( 'lam1:' + str ( o + 1 ) ) ) #Extracting the coeffecients of the multipliers coneqs_mat = Matrix ( coneqs ) qd = self . _qdots self . lam_coeffs = - coneqs_mat . jacobian ( qd ) #Determining the third term in Lagrange's EOM #term3 = ((self.lam_vec).transpose() * self.lam_coeffs).transpose() self . _term3 = self . lam_coeffs . transpose ( ) * self . lam_vec #Taking the time derivative of the constraint equations diffconeqs = [ diff ( i , dynamicsymbols . _t ) for i in coneqs ] #Extracting the coeffecients of the qdds from the diff coneqs diffconeqs_mat = Matrix ( diffconeqs ) qdd = self . _qdoubledots self . _m_cd = diffconeqs_mat . jacobian ( qdd ) #The remaining terms i.e. the 'forcing' terms in diff coneqs qddzero = dict ( zip ( qdd , [ 0 ] * n ) ) self . _f_cd = - diffconeqs_mat . subs ( qddzero ) else : self . _term3 = zeros ( n , 1 ) if self . forcelist is not None : forcelist = self . forcelist N = self . inertial if not isinstance ( N , ReferenceFrame ) : raise TypeError ( 'Enter a valid ReferenceFrame' ) if not isinstance ( forcelist , ( list , tuple ) ) : raise TypeError ( 'Forces must be supplied in a list of: lists' ' or tuples' ) self . _term4 = zeros ( n , 1 ) for i , v in enumerate ( qd ) : for j , w in enumerate ( forcelist ) : if isinstance ( w [ 0 ] , ReferenceFrame ) : speed = w [ 0 ] . ang_vel_in ( N ) self . _term4 [ i ] += speed . diff ( v , N ) & w [ 1 ] elif isinstance ( w [ 0 ] , Point ) : speed = w [ 0 ] . vel ( N ) self . _term4 [ i ] += speed . diff ( v , N ) & w [ 1 ] else : raise TypeError ( 'First entry in force pair is a point' ' or frame' ) else : self . _term4 = zeros ( n , 1 ) self . eom = self . _term1 - self . _term2 - self . _term3 - self . _term4 return self . eom