
Lab 2 - VPython, simple mechanics
Thursday 6 September - Due: Thursday 13 September
In this lab we will experiment with solving some simple mechanics problems
using Python/VPython.
1 Simple Vpython codes
1.1 Harmonic oscillations in 2D
1. Open up a file window (see earlier).
2. Go to the labs link from the PHY307 homepage (http://wwws.phy.syr.edu/courses/PHY307)
and click on the two links to the codes euler.py and force.py discussed in class.
3. Cut and paste these codes into separate Python file windows. Save these codes to your
filespace.
4. Run this program by by selecting Run Module from the Run menu at the top of the
euler.py file window. Record what you see in your lab report. This motion corre-
sponds to the 2D harmonic oscillation we discussed in class.
5. Now we will add some code to draw the track of the ball.
•Replace the line starting with ball=sphere(.... with
ball=sphere(radius=0.5,track=curve(radius=0.1))
The variable track is the name I am using here for an object of type curve
which will contain the path of the ball. curve is a standard Vpython object with
many attributes of which the most important perhaps are its color and its radius
(width).
•Add the following line of code after the line ball.vel=...
ball.track.append(pos=ball.pos)
This is the python command to append the latest position of the ball to the track
object. Make sure it is indented at the same level as the position and velocity
update lines.
6. Now rerun the code. Record what you see. What is the shape of the orbit ? You may
want to cut and paste the graphics into your lab report.
7. Also, include your modified code in your lab report in the following way. Select the
whole program by finding Select all on the Edit menu
8. Copy your selection using Copy under Edit
9. Paste your selection into your report (Paste under the Edit menu in Word)