All the Colors of the Rainbow!

Good things happen to those who have time!

Finals are over and its off to work! But until work starts on Monday, I have some time to work on the computer a bit. I won’t have personal internet service until Monday night, so I spend a good portion of the day working on the Bouncing Ball grapher. I rewrote it and used a While loop to repeatedly calculate each bounce. One thing I rarely do is write out my logic on paper first, but I decided to try it and it really did help. I might scan the paper and post it here just to show you how I did my notes. Looking at it now, Its pretty comical, but it helped a lot.

Here’s the revised code,

import numpy as np
import matplotlib.pyplot as plt
import math

h0 = input("Initial Height ")
e = input("Coefficient of Restitution ")
g = 9.806 #gravity at system

Tb = math.sqrt(2.0*h0/g)
Vf = math.sqrt(2.0*h0*g)
t = np.linspace(0,Tb,100)
h1 = -.5*g*t*t+h0
h2 = h1
Tstart = 0


while (np.amax(h2) > .1*h0):
  V0 = e * Vf
  Tstart = Tstart + Tb
  Tb = 2.0*V0/g
  t = np.linspace(Tstart, Tstart + Tb, 100)
  h2 = -.5*g*(t-Tstart)*(t-Tstart)+V0*(t-Tstart)
  Vf = math.sqrt(2.0*np.amax(h2)*g)
  h1 = h2

I haven’t commented everything yet. Maybe I’ll get around to it later.

Here’s an example of an output,
ooooo pretty colors

That’s with an initial height of 16 and a COE of .74. The program compares the height of the last bounce with the initial height to determine when to stop. If the bounce gets small enough, the program will terminate and show the final graph.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s