Title / Description
Code # -*- 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')
Author
Highlight as C C++ CSS Clojure Delphi ERb Groovy (beta) HAML HTML JSON Java JavaScript PHP Plain text Python Ruby SQL XML YAML diff code