An other ball trajectory problem ... solved using Python 3 ... that illustrates what is constant acceleration.
# ballTrajectory.py # # 2016-04-21 #
INTRO = '''INTRODUCTION to solving QUADRATIC EQUATIONS and PARABOLAS ...
What does it actually mean ...
if we have *constant* acceleration ...
for constant acceleration, a,
in units of feet per cecond per second,
starting with initial velocity, vi = 0,
in units of feet per second,
if the constant acceleration, a = 32 feet per second per second?
This means that ...
at 1 second point, the velocity reached is 32 feet per second
st 2 second point, the velocity reached is 64 feet per second
st 3 second point, the velocity reached is 96 feet per second
st 4 second point, the velocity reached is 128 feet per second
etc...
So what is the distance traveled in each second?
We can easily find the average velocity over each second,
to see the total change in distance *for that second* ...
Then we can add up all the changes in distance over all the seconds.
Over the 1st second, the average velocity was (0+32)/2 feet per second.
So distance travelled then was: 16 feet
Over the 2nd second, the average velocity was (32+64)/2 feet per second.
So distance travelled then was: 16+32 feet = 48 feet
Over the 3rd second, the average velocity was (64+96)/2 feet per second.
So distance travelled then was: 32+48 feet = 80 feet
Over the 4th second, the average velocity was (96+128)/2 feet per second.
So distance travelled then was:, 48+64 feet = 112 feet
Thus at time zero, at (0, 0)
and at time 1, at (1, 16)
and at time 2, at (2, 64)
and at time 3, at (3, 144)
and at time 4, at (4, 256)
etc...
Can you see a pattern ?
Thus at time n, at (n, 16*n**2)
But notice that 16 is exactly 1/2 of 32,
(the constanct acceleration here) ...
Thus, we can see, here, that for constant acceleration, a, the distance, d, is:
d = (1/2)*a*t**2
but if we had an initial velocity, vi,
in the same direction as the constant acceleration, a,
the distance, d, then becomes:
d = vi*t + (1/2)*a*t**2
and if we started at initial distance, di,
then the distance. d = f(t), becomes:
d = di + vi*t + (1/2)*a*t*t
NOTE ALSO:
d(1) = (a*0 + a*1)/2
= a/2
= a/2 * (1)**2
d(2) = (a*0 + a*1)/2 + (a*1 + a*2)/2
= a/2 + a/2 + a
= 2*a
= a/2 * (2)**2
d(3) = (a*0 + a*1)/2 + (a*1 + a*2)/2 + (a*2 + a*3)/2
= a/2 + a/2 + a + a + 3*a/2
= 4.5*a
= a/2 * (3)**2
d(4) = (a*0 + a*1)/2 + (a*1 + a*2)/2 + (a*2 + a*3)/2 + (a*3 + a*4)/2
= a/2 + a/2 + a + a + 3*a/2 + 3*a/2 + 2*a
= 8*a
= a/2 * (4)**2
d(5) = (a*0 + a*1)/2 + (a*1 + a*2)/2 + (a*2 + a*3)/2 + (a*3 + a*4)/2 + (a*4 + a*5)/2
= 8*a + 4.5*a
= 12.5*a
= a/2 * (5)**2
Demo of 'proof by induction' ...
We assume: d(n) = a/2 * (n)**2
Then: d(n+1) = a/2 * (n+1)**2
= a/2 * (n**2 + 2*n + 1)
= a/2 * (n)**2 + a/2 *(2*n + 1)
= d(n) + a*(n + n+1)/2
And that fulfills the pattern ...
So ... d(n) = a/2 * n**2
AND d(t) = a/2 * t**2 = (1/2) * a * t**2
'''
print( INTRO, '\n' )
def getDiffs( lst ):
diffs = []
for i in range(1, len(lst)):
diffs.append(lst[i] - lst[i-1])
return diffs
# NEW example(s) ... ball is propelled up, at 8 feet above the ground
# with initial up velocity at 40 feet per second,
# and initial side-ways velocity component of 100 feet per second
# let distance up, be a function of time, d(t), then d(t) = ?
def d(t):
return 8 + 16*t*(2.5 - t) # i.e. d(t) = 8 + 40*t - 16*t*t #
# compare with NO initial velocity at all ...
# i.e. ball is dropped from 8 feet #
def d2( t ):
return 8 - 16*t*t # i.e. d2(t) = 8 - 16*t*t #
# compare with (positive) initial velocity at 40 feet per second DOWN,
# and ball is descending from 0 (as 8) feet
# but t here is starting from t = 0 (2.5) seconds
# so solving 8 = 16*t*(2.5 + t) ... and plotting ... (to find 'zeros')
def f( t ):
return -8 + 16*t*(2.5 + t) # i.e. f(t) = -8 + 40*t - 16*t*t #
print( "So we have 3 quadratic relations demo'd here ..." )
print( "d(t) = 8 + 16*t*(2.5 - t) " )
print( "d2(t) = 8 - 16*t*t " )
print( "f(t) = -8 + 16*t*(2.5 + t) " )
# get a Lst of pairs (t, d(t), d2( t), f(t)(t)) #
print( "\n\nNow let's get and print Python lists of (x, f(x)) for x in range -3..5" )
print( "Note that at t = 0, ball is at 8 feet up,\n"
"\n1st distance column in has vi(up component) = 40 feet per second,\n"
"i.e. (up) d(t) = 8 + 16*t*(2.5 - t) \n"
"\n2nd distance column in has vi = 0 feet per second,\n"
"i.e. (up) d2(t) = 8 - 16*t*t \n"
"\n3rd distance column in has vi(down component) = 40 feet per second,\n"
"and now find time it takes to go down 8 more feet to the ground,\n"
"i.e. for (down) d3(t) = 16*t*(2.5 + t), solve for d3(t) = 8 \n"
"i.e. solve f(t) = 0 for f(t) = -8 + 16*t*(2.5 + t) \n" )
print( "-"*24 )
print( "{:>3s} {:>6s} {:>6s} {:>6s}".format('t', 'd', 'd2', 'f(t)'),
"\n" + "-"*24 )
Lst3 = []
Lst2 = []
Lst = []
for t in range(-3, 6):
Lst3.append( f(t) )
Lst2.append( d2(t) )
Lst.append( d(t) )
print( '{:3} {:6} {:6} {:6}'.format(t, d(t), d2(t), f(t)) )
print( "\nFirst differences ... with ..." )
firstDiffsLst3 = getDiffs(Lst3)
firstDiffsLst2 = getDiffs(Lst2)
firstDiffsLst = getDiffs(Lst)
print("vi = 40, differences are:", firstDiffsLst)
print("vi = 0, differences are:", firstDiffsLst2)
print("vi = -40, differences are:", firstDiffsLst3)
print( "\nSecond differences ... with ..." )
secondDiffsLst3 = getDiffs(firstDiffsLst3)
secondDiffsLst2 = getDiffs(firstDiffsLst2)
secondDiffsLst = getDiffs(firstDiffsLst)
print("vi = 40, differences are:", secondDiffsLst)
print("vi = 0, differences are:", secondDiffsLst2)
print("vi = -40, differences are:", secondDiffsLst3)
print( "\nRecall extreme value for d(t) is reached at 't = -b/(2*a) " )
t_at_max = (-40)/(-2*16)
print( "For d(t), t_at_max =", t_at_max, "seconds, and d(t_at_max) =",
d(t_at_max), "feet.\n" )
def roots( a, b, c ):
return (-b - (b**2 - 4*a*c)**0.5)/(2*a), (-b + (b**2 - 4*a*c)**0.5)/(2*a)
# d(t) = 8 + 16*t*(2.5 - t) #
r1_1, r1_2 = roots( -16, 40, 8 )
print( "\nNow finding roots r1 and r2 for each ..." )
print( "for d(t), r1_1 = {}, r1_2 = {}".format(r1_1, r1_2) )
# d2(t) = 8 - 16*t*t #
r2_1, r2_2 = roots( -16, 0, 8 )
print( "for d2(t), r2_1 = {}, r2_2 = {}".format(r2_1, r2_2) )
# 8 = 16*t*(2.5 + t) implies f(t) = -8 + 16*t*(2.5 + t) #
r3_1, r3_2 = roots( 16, 40, -8 )
print( "for f(t) , r3_1 = {}, r3_2 = {}".format(r3_1, r3_2) )
print( '\nNote that {} + {} = {}'.format(2.5, r3_2, r1_1) )
print( "\nSo, if the ball also had a sideways constant velocity "
"of {} feet/second, \n"
"it would hit the ground at {} ft/sec * {:.4f} sec = {:.2f} feet away."
.format(100, 100, r1_1, 100*r1_1 ) )
input("\nPress 'Enter' to continue/exit ... " )
# output of running program #
'''
INTRODUCTION to solving QUADRATIC EQUATIONS and PARABOLAS ...
What does it actually mean ...
if we have *constant* acceleration ...
for constant acceleration, a,
in units of feet per cecond per second,
starting with initial velocity, vi = 0,
in units of feet per second,
if the constant acceleration, a = 32 feet per second per second?
This means that ...
at 1 second point, the velocity reached is 32 feet per second
st 2 second point, the velocity reached is 64 feet per second
st 3 second point, the velocity reached is 96 feet per second
st 4 second point, the velocity reached is 128 feet per second
etc...
So what is the distance traveled in each second?
We can easily find the average velocity over each second,
to see the total change in distance *for that second* ...
Then we can add up all the changes in distance over all the seconds.
Over the 1st second, the average velocity was (0+32)/2 feet per second.
So distance travelled then was: 16 feet
Over the 2nd second, the average velocity was (32+64)/2 feet per second.
So distance travelled then was: 16+32 feet = 48 feet
Over the 3rd second, the average velocity was (64+96)/2 feet per second.
So distance travelled then was: 32+48 feet = 80 feet
Over the 4th second, the average velocity was (96+128)/2 feet per second.
So distance travelled then was:, 48+64 feet = 112 feet
Thus at time zero, at (0, 0)
and at time 1, at (1, 16)
and at time 2, at (2, 64)
and at time 3, at (3, 144)
and at time 4, at (4, 256)
etc...
Can you see a pattern ?
Thus at time n, at (n, 16*n**2)
But notice that 16 is exactly 1/2 of 32,
(the constanct acceleration here) ...
Thus, we can see, here, that for constant acceleration, a, the distance, d, is:
d = (1/2)*a*t**2
but if we had an initial velocity, vi,
in the same direction as the constant acceleration, a,
the distance, d, then becomes:
d = vi*t + (1/2)*a*t**2
and if we started at initial distance, di,
then the distance. d = f(t), becomes:
d = di + vi*t + (1/2)*a*t*t
NOTE ALSO:
d(1) = (a*0 + a*1)/2
= a/2
= a/2 * (1)**2
d(2) = (a*0 + a*1)/2 + (a*1 + a*2)/2
= a/2 + a/2 + a
= 2*a
= a/2 * (2)**2
d(3) = (a*0 + a*1)/2 + (a*1 + a*2)/2 + (a*2 + a*3)/2
= a/2 + a/2 + a + a + 3*a/2
= 4.5*a
= a/2 * (3)**2
d(4) = (a*0 + a*1)/2 + (a*1 + a*2)/2 + (a*2 + a*3)/2 + (a*3 + a*4)/2
= a/2 + a/2 + a + a + 3*a/2 + 3*a/2 + 2*a
= 8*a
= a/2 * (4)**2
d(5) = (a*0 + a*1)/2 + (a*1 + a*2)/2 + (a*2 + a*3)/2 + (a*3 + a*4)/2 + (a*4 + a*5)/2
= 8*a + 4.5*a
= 12.5*a
= a/2 * (5)**2
Demo of 'proof by induction' ...
We assume: d(n) = a/2 * (n)**2
Then: d(n+1) = a/2 * (n+1)**2
= a/2 * (n**2 + 2*n + 1)
= a/2 * (n)**2 + a/2 *(2*n + 1)
= d(n) + a*(n + n+1)/2
And that fulfills the pattern ...
So ... d(n) = a/2 * n**2
AND d(t) = a/2 * t**2 = (1/2) * a * t**2
So we have 3 quadratic relations demo'd here ...
d(t) = 8 + 16*t*(2.5 - t)
d2(t) = 8 - 16*t*t
f(t) = -8 + 16*t*(2.5 + t)
Now let's get and print Python lists of (x, f(x)) for x in range -3..5
Note that at t = 0, ball is at 8 feet up,
1st distance column in has vi(up component) = 40 feet per second,
i.e. (up) d(t) = 8 + 16*t*(2.5 - t)
2nd distance column in has vi = 0 feet per second,
i.e. (up) d2(t) = 8 - 16*t*t
3rd distance column in has vi(down component) = 40 feet per second,
and now find time it takes to go down 8 more feet to the ground,
i.e. for (down) d3(t) = 16*t*(2.5 + t), solve for d3(t) = 8
i.e. solve f(t) = 0 for f(t) = -8 + 16*t*(2.5 + t)
------------------------
t d d2 f(t)
------------------------
-3 -256.0 -136 16.0
-2 -136.0 -56 -24.0
-1 -48.0 -8 -32.0
0 8.0 8 -8.0
1 32.0 -8 48.0
2 24.0 -56 136.0
3 -16.0 -136 256.0
4 -88.0 -248 408.0
5 -192.0 -392 592.0
First differences ... with ...
vi = 40, differences are: [120.0, 88.0, 56.0, 24.0, -8.0, -40.0, -72.0, -104.0]
vi = 0, differences are: [80, 48, 16, -16, -48, -80, -112, -144]
vi = -40, differences are: [-40.0, -8.0, 24.0, 56.0, 88.0, 120.0, 152.0, 184.0]
Second differences ... with ...
vi = 40, differences are: [-32.0, -32.0, -32.0, -32.0, -32.0, -32.0, -32.0]
vi = 0, differences are: [-32, -32, -32, -32, -32, -32, -32]
vi = -40, differences are: [32.0, 32.0, 32.0, 32.0, 32.0, 32.0, 32.0]
Recall extreme value for d(t) is reached at 't = -b/(2*a)
For d(t), t_at_max = 1.25 seconds, and d(t_at_max) = 33.0 feet.
Now finding roots r1 and r2 for each ...
for d(t), r1_1 = 2.686140661634507, r1_2 = -0.18614066163450715
for d2(t), r2_1 = 0.7071067811865476, r2_2 = -0.7071067811865476
for f(t) , r3_1 = -2.686140661634507, r3_2 = 0.18614066163450715
Note that 2.5 + 0.18614066163450715 = 2.686140661634507
So, if the ball also had a sideways constant velocity of 100 feet/second,
it would hit the ground at 100 ft/sec * 2.6861 sec = 268.61 feet away.
Press 'Enter' to continue/exit ...
'''