What follows is a short rundown of the commands used in PyDy. All commands that you would type in an interactive session are preceded by ‘’>>> ‘’.
>>> from sympy import *
This imports all of the classes and functions in the ‘’SymPy’’ package. Now we can do some symbolic math:
>>> x, y, z = symbols('x y z') >>> e = x**2 + y**2 + z**2 >>> print(e) x**2 + y**2 + z**2 >>> diff(e, x) 2*x
This creates 3 symbols, x, y, and z, and illustrates how to form a SymPy expression and take its derivative.
What follows is a list of objects you can create, and functions you can run. The first step is to import the functions and classes related to mechanics:
>>> from sympy.physics.mechanics import *
- Here is a list of classes:
- Vector - not created directly
- Dyadic - not created directly
You can call ‘’help(class)’’ to see the help entry for ‘’class’‘. For example, ‘’help(ReferenceFrame)’’ to see the help entry for ‘’ReferenceFrame’‘.
Here are some brief usage examples of common functions and classes.
>>> q1, q2 = dynamicsymbols('q1 q2')
Creates two time varying symbols, ‘’q1’’ and ‘’q2’‘
>>> N = ReferenceFrame('N')
This creates a new reference frame named N.
Access to the ‘’x’’ basis vector in the ‘’N’’ reference frame
>>> a = N.x + N.y
Creates a new vector, ‘’a’‘, which is the sum of the ‘’x’’ and ‘’y’’ basis vectors in the ‘’N’’ reference frame.
>>> P = Point('P')
Creates a point named P.
>>> K = KanesMethod(N)
FIXME Creates a new ‘’KanesMethod’’ object, used to generate \(F_r + F_r^*\), with ‘’N’’ as the inertial reference frame.
>>> D = RigidBody('BodyD', masscenter=P, frame=N, mass=2, inertia=I)
Creates a rigid body container and defines the center of mass location, the body fixed frame, the mass and the inertia.
>>> Par = Particle()
Creates a new particle container.
- Here is a list of functions:
- kinematic equations
On each of them, you can call ‘’help(function)’’ to see the help entry for ‘’function’‘. For example, ‘’help(inertia)’’ will describe what the ‘’inertia’’ function is and how to use it.
Sets the default printing to use the mechanics printing.
Prints ‘’q1’’ using the mechanics printer; use if mechanics_printing is not on.
>>> I = inertia(N, 1, 2, 3)
Creates an inertia dyadic in the frame N with principle measure numbers of 1, 2, and 3.
>>> mprint(kinematic_equations([u1,u2,u3], [q1,q2,q3], 'body', '313'))
Prints out kinematic differential equations which relate the body fixed angular velocity measure numbers ‘’u1, u2, u3’’ to the time derivatives of the coordinates ‘’q1, q2, q3’‘, assuming a 313 (ZXZ) body fixed rotations.