-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem317.py
More file actions
67 lines (52 loc) · 1.7 KB
/
Copy pathproblem317.py
File metadata and controls
67 lines (52 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import math
def get_distance(v, r, h, g=9.81):
r = math.radians(r)
d = v*math.cos(r) / g
d *= (v*math.sin(r) + math.sqrt((v*math.sin(r))**2 + 2*g*h))
return d
def get_max_height(v, r, h, g=9.81):
return h + (v * math.sin(math.radians(r))) ** 2 / (g*2)
def get_max_distance(v, h, iteration=20):
increment = 1.0/1000
max_d = 0
r = 0
while iteration > 0:
d = get_distance(20, r, 100)
if d > max_d:
max_d = d
r += increment
else:
r -= increment
increment /= 10
iteration -= 1
return max_d
def problem317():
"""
A firecracker explodes at a height of 100 m above level ground. It
breaks into a large number of very small fragments, which move in every
direction; all of them have the same initial velocity of 20 m/s.
We assume that the fragments move without air resistance, in a uniform
gravitational field with g=9.81 m/s2.
Find the volume (in m3) of the region through which the fragments move
before reaching the ground. Give your answer rounded to four decimal
places. """
#
# equation of parabola: y = a*x^2 + b
# find a,b using (0, max_h) and (max_x, 0)
# and calc solid of revolution
#
max_x = get_max_distance(20, 100)
b = get_max_height(20, 90, 100)
a = -b / (max_x**2)
f = lambda x: a*x**2 + b
# integrate x=[0..max_x]
x = 0
volume = 0
increment = 0.0001
while x <= max_x:
h = (f(x) + f(x+increment)) / 2.0
volume += math.pi * ((x+increment)**2-x**2) * h
x += increment
return round(volume,4)
if __name__=="__main__":
print problem317()