#NEWLINE# def Lagrangian( frame , * body ) : #NEWLINE# #INDENT# "Lagrangian of a multibody system.\n\n    This function returns the Lagrangian of a system of Particle's and/or\n    RigidBody's. The Lagrangian of such a system is equal to the difference\n    between the kinetic energies and potential energies of its constituents. If\n    T and V are the kinetic and potential energies of a system then it's\n    Lagrangian, L, is defined as\n\n    L = T - V\n\n    The Lagrangian is a scalar.\n\n    Parameters\n    ==========\n\n    frame : ReferenceFrame\n        The frame in which the velocity or angular velocity of the body is\n        defined to determine the kinetic energy.\n\n    body1, body2, body3... : Particle and/or RigidBody\n        The body (or bodies) whose Lagrangian is required.\n\n    Examples\n    ========\n\n    >>> from sympy.physics.mechanics import Point, Particle, ReferenceFrame\n    >>> from sympy.physics.mechanics import RigidBody, outer, Lagrangian\n    >>> from sympy import symbols\n    >>> M, m, g, h = symbols('M m g h')\n    >>> N = ReferenceFrame('N')\n    >>> O = Point('O')\n    >>> O.set_vel(N, 0 * N.x)\n    >>> P = O.locatenew('P', 1 * N.x)\n    >>> P.set_vel(N, 10 * N.x)\n    >>> Pa = Particle('Pa', P, 1)\n    >>> Ac = O.locatenew('Ac', 2 * N.y)\n    >>> Ac.set_vel(N, 5 * N.y)\n    >>> a = ReferenceFrame('a')\n    >>> a.set_ang_vel(N, 10 * N.z)\n    >>> I = outer(N.z, N.z)\n    >>> A = RigidBody('A', Ac, a, 20, (I, Ac))\n    >>> Pa.potential_energy = m * g * h\n    >>> A.potential_energy = M * g * h\n    >>> Lagrangian(N, Pa, A)\n    -M*g*h - g*h*m + 350\n\n    " #NEWLINE# if ( not isinstance ( body , ReferenceFrame ) ) : #NEWLINE# #INDENT# raise TypeError ( 'Please supply a valid ReferenceFrame' ) #NEWLINE# #UNINDENT# for e in body : #NEWLINE# #INDENT# if ( not isinstance ( e , ( RigidBody , Particle ) ) ) : #NEWLINE# #INDENT# raise TypeError ( '*body must have only Particle or RigidBody' ) #NEWLINE# #UNINDENT# #UNINDENT# return ( kinetic_energy ( frame , * body ) - potential_energy ( * body ) )