P

Python code posted
created at 03 Mar 02:50

Edit | Back
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
# -*- coding: utf-8 -*-
from pylab import *
import math

degree = 0
xrange = 0
rangemax = 0
maxpoint = 0


'''numeral values used in question #2'''

height = 75
freefallacc = 9.8
velocity = 36


'''define x(theta). Refer to analytical method'''

def xoftheta(theta):
    crange = ((-velocity * math.sin(theta) * velocity * math.cos(theta) - \
               velocity * math.cos(theta) * math.sqrt(velocity*velocity*\
                math.sin(theta)*math.sin(theta)+2*freefallacc*height)) \
                / (-freefallacc) )
    return crange;


'''for theta in [0,9.9], step = 0.1 in order to keep 2 sig figures'''

while degree < 10:
    radian = math.radians(degree)
    xrange = xoftheta(radian)
    if xrange > rangemax:
        rangemax = xrange
        maxpoint = degree
    degree = degree + 0.1
    
degree = 10


'''for theta in [10,90], step = 1 in order to keep 2 sig figures'''

while degree < 91:
    radian = math.radians(degree)
    xrange = xoftheta(radian)
    if xrange > rangemax:
        rangemax = xrange
        maxpoint = degree
    degree = degree + 1
    
print ('x attains its maximum value at ', maxpoint, 'degree')
1.17 KB in 3 ms with coderay