Professional Documents
Culture Documents
as of Wednesday
(or last week)
Victor Miclovich
1
y(t) = v0 t − gt2
2
The above expression that says a lot about the trajectory of a ball.
It actually computes the height of a ball in vertical motion. What if we
throw the ball with an initial velocity having an angle θ with the horizontal
”plane”?
This kind of problem has been encountered by many of you... at least if
you went to a high school physics class. The ball will follow a trajectory
y = f (x) through the air, where
1 gx2
f (x) = x tan θ − + y0
2vo2 cos2 θ
In this expression, is a horizontal coordinate... the distance in the direc-
tion of the x axis, g is the acceleration of gravity, v0 is the size1 of the initial
velocity which makes an angle θ with the x axis, and (0, y0 ) is the initial
position of the ball. Our programming goal is to make a program evaluating
equation above. The program should write out the value of all the involved
variables and what their units are.
Solution: We use the SI System and assume that v0 has been given in
km/h; g = 9.81m/s2 ; x,y, and y0 are measure in meters; and θ in degrees.
The program has got four parts; that are natural.
• Initialization of input data
1
• And, finally, the evaluation of the right hand-side of the expression.
The complete program is shown below2 :
print """\
v0 = %.1f km/h
theta = %d degrees
y0 = %.1f m\
""" % (v0, theta, y0, x)
print ’y = %.1f m’ % y
Explanation of code
The backslash in the triple-quoted multi-line string makes the string con-
tinue on the next line without a newline. This means that removing the
backslash results in a blank line above the v0 line and a blank line between
x and y lines in t he output on the screen. Another point to note is the
expression 1/(2*v0**2), which might seem as a candidate for unintended
integer division. However, the conversion of v0 to m/s involves a division by
3.6, which results in v0 being float, and therefore 2*v0**2 being float.
2
Some pointers to take note of:
4
But objects can exist without being bound to a name:print ’Hello!’ first makes a
string object of the text in quotes and then the contents of this string object, without a
name, is printed
3
How to cook the perfect egg
As an egg cooks, the proteins first denature and then coagulate. When the
temperature exceeds a critical point, reactions begin and proceed faster as
the temperature increases. In the egg white the proteins start to coagulate
for temperatures above 70◦ C. For a hard boiled egg, the center of the yolk
should be allowed to reach 70◦ C.
The following formula expresses the time t it takes (in seconds) for the
center of the yolk to reach the temperature Ty (in Celsius degrees):
2 1
M 3 cρ 3 T0 − Tw
t= 2 ln 0.76
Kπ 2 ( 4π Ty − Tw
3 )
3
0 < t < T2 ,
1,
f (x) = 0, t = T2 ,
−1, T2 < t < T
4
Let S(=S(t; n)), t, alpha, and T be variables in the program. A new S,
corresponding to a new n, should be computed by adding one term to the
previous value of S, i.e., by a statement like S=S + term. Run the program
also for α = 14 . Does the approximation S(αT ; 4) seem to be better for
α = 1/4 than for α = 0.01? Name the program file: compare fun sum.py6
What next?
Over the next weeks, months or years, we shall be looking at various engi-
neering functions, interesting mathematics and the like... just be prepared
to use this tool in your work too!
6
Email me your answers: victor.miclovich@appfrica.org