Picture
By modifying the code of the tutorial students will model their first real physical system: A simple bouncy ball

Outcomes

- Modify tutorial code so that the bouncy ball obeys free-fall kinematics and bounces perfectly elastically
- Measure the rebound height of a bouncy ball dropped from 1 m
- Modify the code to reproduce this rebound height and predict subsequent rebound heights
- Explain why modifications work using kinematics equations

Lesson Plan

1.  Students load their tutorial program from the previous class and run it.

2. Teacher circulates to ensure that students all have working tutorial code and answers questions

3. Students modify code so that there is only a floor and a ball that falls to the floor and bounces

4. Students modify (or teacher shows students) how to modify code to incorporate gravity. The specific code I added was:
ball.velocity.y = ball.velocity.y - 9.8*deltat
5. If Students used modified code given by the instructor, the instructor should informally assess that students can explain the how the code works line by line. Here is the code actually used
from visual import *
ball = sphere(pos=(-5,10,0), radius=0.5, color=color.cyan)
wallB = box(pos=(0,0,0), size=(12,0.2,12), color=color.green)
ball.velocity = vector(1,0,0)
ball.trail = curve(color=ball.color)
deltat = 0.005
t=0
while t < 12:
    rate(100)
    if ball.pos.y < wallB.pos.y:
#note to have the ball bounce realistically change the code below:
    ball.velocity.y = - ball.velocity.y
# to this:ball.velocity.y = C*ball.velocity.y
# where 'C' is a tuneable parameter less than 1
    ball.velocity.y = ball.velocity.y - 9.8 * deltat
    ball.pos = ball.pos + ball.velocity*deltat
    ball.trail.append(pos=ball.pos)
    print (t,ball.pos.y)
    t = t + deltat
6. Students obtain a bouncy ball and a meter stick. Students drop the bouncy ball from a height of 1 m and measure its rebound height a number of times and average

7. Students then tune the parameter 'C' (see code above) so that the program reproduces the first bounce height. They do this by checking the printout in the python shell.

8. Students verify that the second and third bounce by the ball has been reproduced by the python code.

9. The instructor should ask students to explain why the parameter
C has the value it does. Ask them to explain this in terms of either kinematics, energy conservation, or other physics formulas they might find useful.

10. (Answer Key, For teacher's eyes only) The tunable parameter 'C' is the squareroot of the ratio of sequential heights. This can be shown using conservation of energy and a bar graph of the real experiment, or by using kinematics.

11. Once the students complete their code and explanations they may want to play with their code and modify it for the sheer enjoyment of it. This should be encouraged. ;-)

Before Class

Picture
1. Purchase Bouncy Balls. Here is where I got mine

2. Judgement call: Think about if you want them to create their own code, or do you want to give them code? My experience has been that it was really hard for them. They were able to understand the code, but could not invent it themselves. Below is the completed code for a bouncy ball that bounces perfectly elastically.

elastic.bouncy.ball.py
File Size: 0 kb
File Type: py
Download File

3. Judgement call: Think about whether you want the students to modify the code to have the ball rebound realistically, or whether you want to give them the code with the arbitrary parameter that they tune.

4. You might want to think about front-loading: It might be helpful to have a discussion about inelastic vs. elastic bouncing. Having students draw energy bar graphs of the ball at the top and bottom of each bounce might be helpful for students.

5. You might want to think about front-loading: Students may also want to take an approach that uses kinematics to solve a problem being dropped or being launched from the ground

6. Lesson Plan Summary:
lesson.plan.summary.doc
File Size: 29 kb
File Type: doc
Download File

7. Answer Key to explaining code:
answer.key.pdf
File Size: 89 kb
File Type: pdf
Download File

 
Picture
Although there are lots of resources available on the web to help students learn Visual Python, I wanted to write about my own experience getting the process started in a classroom. This post represents my distilled experience in both AP Physics - Mechanics C, and in an algebra-based physics class with sophomores and juniors.


Lesson Plan

Below is a detailed lesson plan I did in class with my students. My school operates on a block schedule with 75 minute blocks per class:


1.  Students open IDLE environment. If the shell opens, have them open a new window.

2. Have them type the following code:
from visual import*
sphere()
3.
Picture






At this point have students open the tutorial document. Explain the following points to them:
  • They will write an app for a bouncy ball bouncing around a box.
  • Don't worry about why the code has the form it does. Just as babies learn a language by hearing and repeating words, so do we learn programming.
  • The tutorial will at first be simple commands. They should type these and run the code after every line.
  • As the tutorial goes further, they will be expected adapt previous code to solve new puzzles.
  • They may find the coding frustrating at first, but if they have some patience they'll be hooked soon enough
4. Let them begin coding and circulate around the room.

5. As the students code, they will find that the code does not behave as they think it should. The language in the tutorial explains why. Draw their attention to this in the tutorial

6. When a student succeeds in making a ball bounce off a wall, have the student walk you through the logic of why the conditional works to make the ball bounce. The code looks like this:

if ball.pos.x > wallR.pos.x:
    ball.velocity.x = -ball.velocity.x
7. They will then realize that bouncing off a second wall requires a tweak to this code. Walk them through the logic and only give them more help if it seems that they will not be able to figure it out.

8. They will find themselves more or less self-sufficient at this point. Some will be comfortable enough that they will experiment with different colors, ball sizes, rates etc. This is all to the good.

9. If students are done early, give them additional challenges such as
  • add extra bouncy balls (easy)
  • customize colors (easy)
  • incorporating gravity into their code (medium)
  • creating a diagonal wall and have a barrier inside their box and have their ball bounce off it (hard)

Before Class

0.  Each student should have a single laptop or desktop computer with Visual Python installed, and the document Vpython_Intro.pdf

1. VPython Website to download and install VPython:

2. Link to the tutorial (click where it says Tutorial) or just download the attached file below

3.  Lesson plan summary to download and have on-hand in your classroom:


vpython_intro.pdf
File Size: 125 kb
File Type: pdf
Download File

vpython.intro.lesson.plan.doc
File Size: 31 kb
File Type: doc
Download File

Caveats

It has been my experience that after the first few minutes of independent coding, they will start making many syntax errors. When this happens inform them that common errors include misspellings, improper indentation, and missing punctuation. Remind them that this is what they should check for whenever their code fails to run.

Also when they have to adapt their code to new problems, there may be some initial resistance. Asking probing questions and having them explain how their existing code works often gives them the ability to deduce what their new code ought to look like.

Finally, some kids will be very comfortable with code, and others may need more help. After awhile the students will probably start looking at each others code to get ideas. I have found this to be a good thing, in that the majority of students are engaged and are looking for a small hint to get them through a challenge rather than copying and pasting code.

Finished Product

    Riaz Abdulla

    I hope that this blog becomes a useful resource for teachers to find lesson plans, code, and ideas for getting their high school students to explore the science of Mechanics via computational physics and Visual Python.

    Archives

    June 2012

    Categories

    All