Paul Francis, 9th March 2011
Aims of this lab
- To teach you enough programming that you can solve a simple iteration problem.
- To introduce you to the Python programming language, and its Visual module (VPython), which allows 3D simulation.
Lab Location and Preparation
The computer labs are held in room BOZO 112, not in the usual physics lab. This lab is located on the lowest level of Building 116.
What to Bring
- Your student card (to swipe to enter the lab)
- Earphones (for listening to webcasts)
- Your university computer password (the same that you use to log on to Wattle), so you can log onto the computers in the lab.
The Python Programming Language and Visual Python
This lab will use the Python programming language. We chose this because it is one of the ten most widely used programming languages in the world, because it is relatively easy to learn, and because those of you who do COMP1730 "Introduction to Scientific Programming" next semester will learn much more Python.
Visual Python is a free add-on to Python that allows easy 3D simulation. It is installed on all information commons PCs, and is free for you to download on your home machines: www.vpython.org.
Visual Python was developed by physics educators and has many special features which make it especially useful for teaching introductory physics.
Log on to a PC, using your University ID number and password (the same one you use for Wattle)
Click on the Windows button in the bottom left, select "Programs", then the "A-Z" list of programs. Find VPython, and run Vidle.
A window will appear. You will type programs into this window. When they have been typed, you will save them. Because this is an information commons machine, anything you put on the desktop will be deleted when you log out, so you should save the programs to "My Documents". That way they will be saved and you can access them from other campus machines.
To run a program, either select "Run" from the menu or press F5. This will being up a messages window, called the Python Shell. Here is where you will see anything you print out. This window is also where you will see error messages. So make sure you keep it visible somewhere on your screen. Running a program will also bring up a VPython window in which you see the virtual objects you have created.
Introduction to VPython
Some people learn best by watching Webcasts. Others prefer to read instructions. In this lab you can do either, or both. If you prefer learning from Webcasts, work through the webcast section below. If you prefer reading, work through the written notes below.
If you don't have a strong preference, I suggest that you try the Webcasts first. You may wish to do both, to make sure that you really understand the material well.
Projectile Motion Exercise
Show your program to your demonstrator
- Work out and write down the iteration equations for a ball flying through the air. You may ignore air resistance for the moment. Notes on how to write iteration equations can be found in Lecture 8 and Lecture 9.
- Write a vpython program to simulate a ball being fired up off the ground at some angle and arcing through the air. Your program should show the ball and the ground.
- Add an arrow to this program to show the velocity of the ball.
- Vary your timestep. How large can it get and still give a reasonably accurate result?
You have now completed the computer lab!
To get credit for this laboratory, you need to have worked through at least one of the introductions, doing all the exercises, and then completed the "Projectile Motion Exercise". You should make sure that your tutor has seen that you've done this.
Everyone should write their own programs. You are encouraged to help each other, but you must make sure that you personally understand what you've done. If your program for the projectile motion exercise is virtually identical to someone elses', that may be taken as evidence that you copied rather than figuring out something for yourself. Later in the course you will need to write your own VPython programs for assessment - this lab is your chance to make sure you can do this.
Back to Paul Francis' Web Page