@@ -6,7 +6,7 @@ operates. The first step is to open up your python interpreter. This varies
6
6
depending on your work style, but the simplest way is to type python in a
7
7
command prompt:
8
8
9
- .. code-block :: bash
9
+ .. code :: bash
10
10
11
11
$ python
12
12
@@ -15,14 +15,14 @@ functionality from SymPy and the Mechanics module, otherwise you will only have
15
15
basic python commands available to work with. We will use the import * method
16
16
to bring in all functions from the two modules:
17
17
18
- .. code-block :: python
18
+ .. code :: python
19
19
20
20
>> > from sympy import *
21
21
>> > from sympy.physics.mechanics import *
22
22
23
23
You can now see what functions and variables that are available to you with:
24
24
25
- .. code-block :: python
25
+ .. code :: python
26
26
27
27
>> > dir ()
28
28
@@ -37,45 +37,45 @@ know the name of the command that you want to use simply use the builtin help
37
37
function to bring up the documentation for the function. In our case we need to
38
38
use the ReferenceFrame class:
39
39
40
- .. code-block :: python
40
+ .. code :: python
41
41
42
42
>> > help (ReferenceFrame)
43
43
44
44
Press `q ` to return to the command line. Now create an inertial reference frame
45
45
called N for Newtonian as was described in the help:
46
46
47
- .. code-block :: python
47
+ .. code :: python
48
48
49
49
>> > N = ReferenceFrame(' N' )
50
50
51
51
Keep in mind that N is the variable name of which the reference frame named 'N'
52
52
is stored. It is important to note that `N ` is an object and it has properties
53
53
and functions associated with it. To see a list of them type:
54
54
55
- .. code-block :: python
55
+ .. code :: python
56
56
57
57
>> > dir (N)
58
58
Notice that three of the properties are `x `, `y `, and `z `. These are the
59
59
orthonormal unit vectors associated with the reference frame and are the
60
60
building blocks for creating vectors. We can create a vector by simply building
61
61
a linear combination of the unit vectors:
62
62
63
- .. code-block :: python
63
+ .. code :: python
64
64
65
65
>> > v = 1 * N.x + 2 * N.y + 3 * N.z
66
66
67
67
Now a vector expressed in the N reference frame is stored in the variable `v `.
68
68
We can print `v ` to the screen by typing:
69
69
70
- .. code-block :: python
70
+ .. code :: python
71
71
72
72
>> > print (v)
73
73
N.x + 2 * N.y + 3 * N.z
74
74
75
75
The vector `v ` can be manipulated as expected. You can multiply and divide them
76
76
by scalars:
77
77
78
- .. code-block :: python
78
+ .. code :: python
79
79
80
80
>> > 2 * v
81
81
2 * N.x + 4 * N.y + 6 * N.z
@@ -88,7 +88,7 @@ remember to always declare numbers as floats (i.e. include a decimal).
88
88
89
89
You can add and subtract vectors:
90
90
91
- .. code-block :: python
91
+ .. code :: python
92
92
93
93
>> > v + v
94
94
2 * N.x + 4 * N.y + 6 * N.z
@@ -98,28 +98,28 @@ You can add and subtract vectors:
98
98
99
99
Vectors also have some useful properties:
100
100
101
- .. code-block :: python
101
+ .. code :: python
102
102
103
103
>> > dir (v)
104
104
105
105
You can find the magnitude of a vector by typing:
106
106
107
- .. code-block :: python
107
+ .. code :: python
108
108
109
109
>> > v.magnitude()
110
110
sqrt(14 )
111
111
112
112
You can compute a unit vector in the direction of `v `:
113
113
114
- .. code-block :: python
114
+ .. code :: python
115
115
116
116
>> > v.normalize()
117
117
sqrt(14 )/ 14 * N.x + sqrt(14 )/ 7 * N.y + 3 * sqrt(14 )/ 14 * N.z
118
118
119
119
You can find the measure numbers and the reference frame the vector was defined
120
120
in with:
121
121
122
- .. code-block :: python
122
+ .. code :: python
123
123
124
124
>> > v.args
125
125
[([1 ]
@@ -128,7 +128,7 @@ in with:
128
128
129
129
Dot and cross products of vectors can also be computed:
130
130
131
- .. code-block :: python
131
+ .. code :: python
132
132
133
133
>> > dot(v, w)
134
134
19
@@ -139,14 +139,14 @@ We've only used numbers as our measure numbers so far, but it is just as easy
139
139
to use symbols. We will introduce six symbols for our measure numbers with the
140
140
SymPy `symbols ` [`help(symbols) for the documentation `] function:
141
141
142
- .. code-block :: python
142
+ .. code :: python
143
143
144
144
>> > a1, a2, a3 = symbols(' a1 a2 a3' )
145
145
>> > b1, b2, b3 = symbols(' b1 b2 b3' )
146
146
147
147
And create two new vectors that are completely symbolic:
148
148
149
- .. code-block :: python
149
+ .. code :: python
150
150
151
151
>> > x = a1 * N.x + a2 * N.y + a3 * N.z
152
152
>> > y = b1 * N.x + b2 * N.y + b3 * N.z
@@ -157,15 +157,15 @@ And create two new vectors that are completely symbolic:
157
157
158
158
Numbers and symbols work together seamlessly:
159
159
160
- .. code-block :: python
160
+ .. code :: python
161
161
162
162
>> > dot(v, x)
163
163
a1 + 2 * a2 + 3 * a3
164
164
165
165
You can also differentiate a vector with respect to a variable in a reference
166
166
frame:
167
167
168
- .. code-block :: python
168
+ .. code :: python
169
169
170
170
>> > x.diff(a1, N)
171
171
N.x
@@ -175,7 +175,7 @@ create a new reference frame and orient it with respect to the `N` frame that
175
175
has already been created. We will use the `orient ` method of the new frame to
176
176
do a simple rotation through `alpha ` about the `N.x ` axis:
177
177
178
- .. code-block :: python
178
+ .. code :: python
179
179
180
180
>> > A = ReferenceFrame(' A' )
181
181
>> > alpha = symbols(' alpha' )
@@ -184,7 +184,7 @@ do a simple rotation through `alpha` about the `N.x` axis:
184
184
Now the direction cosine matrix with of `A ` with respect to `N ` can be
185
185
computed:
186
186
187
- .. code-block :: python
187
+ .. code :: python
188
188
189
189
>> > A.dcm(N)
190
190
[1 , 0 , 0 ]
@@ -194,7 +194,7 @@ computed:
194
194
Now that SymPy knows that `A ` and `N ` are oriented with respect to each other
195
195
we can express the vectors that we originally wrote in the `A ` frame:
196
196
197
- .. code-block :: python
197
+ .. code :: python
198
198
199
199
>> > v.express(A)
200
200
A.x + (3 * sin(alpha) + 2 * cos(alpha))* A.y + (- 2 * sin(alpha) + 3 * cos(alpha))* A.z
@@ -208,7 +208,7 @@ frames and vectors are time varying. The mechanics module provides a way to
208
208
specify quantities as time varying. Let's define two variables `beta ` and `d `
209
209
as variables which are functions of time:
210
210
211
- .. code-block :: python
211
+ .. code :: python
212
212
213
213
>> > beta, d = dynamicsymbols(' beta d' )
214
214
@@ -217,23 +217,23 @@ frame by `beta` and create a vector in that new frame that is a function of
217
217
`d `. This time we will use the `orientnew ` method of the `A ` frame to create
218
218
the new reference frame `B `:
219
219
220
- .. code-block :: python
220
+ .. code :: python
221
221
222
222
>> > B = A.orientnew(' B' , ' Axis' , [beta, A.y])
223
223
>> > vec = d * B.z
224
224
225
225
We can now compute the angular velocity of the reference frame `B ` with respect
226
226
to other reference frames:
227
227
228
- .. code-block :: python
228
+ .. code :: python
229
229
230
230
>> > B.ang_vel_in(N)
231
231
beta' *A.y
232
232
233
233
This allows us to now differentiate the vector, `vec `, with respect to time and
234
234
a reference frame:
235
235
236
- .. code-block :: python
236
+ .. code :: python
237
237
238
238
>> > vecdot = vec.dt(N)
239
239
>> > vecdot
@@ -248,7 +248,7 @@ varying variables. For example, we can define `omega` as the first time
248
248
derivative of `beta` which allows you to explicitly interact with the
249
249
derivatives:
250
250
251
- .. code- block :: python
251
+ .. code:: python
252
252
253
253
>> > theta = dynamicsymbols(' theta' )
254
254
>> > omega = dynamicsymbols(' theta' , 1 )
@@ -257,33 +257,33 @@ At this point we now have all the tools needed to setup the kinematics for a
257
257
dynamic system. Let' s start with a simple system where a point can move back
258
258
and forth on a spinning disc. First create an inertial reference frame:
259
259
260
- .. code- block :: python
260
+ .. code:: python
261
261
262
262
>> > N = ReferenceFrame(' N' )
263
263
264
264
Now create a reference frame for the disc:
265
265
266
- .. code- block :: python
266
+ .. code:: python
267
267
268
268
>> > D = ReferenceFrame(' D' )
269
269
270
270
The disc rotates with respect to `N` about the `N.x` axis through `theta` :
271
271
272
- .. code- block :: python
272
+ .. code:: python
273
273
274
274
>> > theta = dynamicsymbols(' theta' )
275
275
>> > D.orient(N, ' Axis' , [theta, N.x])
276
276
277
277
Define one point at the origin of rotation which is fixed in `N` :
278
278
279
- .. code- block :: python
279
+ .. code:: python
280
280
281
281
>> > no = Point(' no' )
282
282
>> > no.set_vel(N, 0 )
283
283
284
284
The second point, `p` , can move through `x` along the `D.y` axis:
285
285
286
- .. code- block :: python
286
+ .. code:: python
287
287
288
288
>> > p = Point(' p' )
289
289
>> > x = dynamicsymbols(' x' )
@@ -293,7 +293,7 @@ The second point, `p`, can move through `x` along the `D.y` axis:
293
293
294
294
The velocity of the point in the `N` frame can now be computed:
295
295
296
- .. code- block :: python
296
+ .. code:: python
297
297
298
298
>> > p.vel(N)
299
299
x' *D.y + x*theta' * D.z
@@ -302,7 +302,7 @@ The velocity of the point in the `N` frame can now be computed:
302
302
303
303
The acceleration of the point can also be computed:
304
304
305
- .. code- block :: python
305
+ .. code:: python
306
306
307
307
>> > p.acc(N)
308
308
(- x* theta' **2 + x' ' )*D.y + (x*theta' ' + 2*theta' * x' )*D.z
0 commit comments