python - Is there a way i can use np.array in the code -
i wanted know if there way can covert code np.array code. add link. wanted add angle ball launches from.
import numpy np import scipy sp scipy.integrate import ode import matplotlib.pylab pl import matplotlib.pyplot plt import math matplotlib import* matplotlib.pyplot import * __future__ import division import math def projectile_xy(initpos,g,initvel): data_xy = [] inittime = 0.0 while true:
now calculate height y
y = initpos + (inittime * initvel * math.sin(theta)) - (g * inittime * inittime)/2
projectile has hit ground level
if y < 0: break
calculate distance x
x = initvel * math.cos(theta) * inittime
append (x, y) tuple list
data_xy.append((x, y))
use time in increments of 0.1 seconds
inittime += 0.1 return data_xy g = 9.8 #h = float(raw_input("enter height ")) initpos = float(raw_input("enter height ")) der = float(raw_input("enter angle ")) #v = float(raw_input("enter velocity ")) initvel = float(raw_input("enter velocity ")) theta = math.radians(der) # radians data_der = projectile_xy(initpos,g,initvel)
find maximum height ...
point_height_max = max(data_der, key = lambda q: q[1]) xm, ym = point_height_max x_max = max(data_der)[0] print(''' projectile motion ... using firing angle of {} degrees , muzzle velocity of {} meters/second maximum height {:0.1f} meters @ distance of {:0.1f} meters'''.format(der, initvel, ym, xm)) print "maximum distance" ,(x_max)
enter height 1 enter angle 45 enter velocity 30
projectile motion ... using firing angle of 45.0 degrees , muzzle velocity of 30.0 meters/second maximum height 24.0 meters @ distance of 46.7 meters maximum distance 91.2167747731
you can follow approach:
import numpy np linear_vel = 20 ang = np.pi/3 y=10 x=12 g=9.8 y_vel = linear_vel*np.cos(ang) x_vel = linear_vel*np.sin(ang) t = (y_vel+np.sqrt(y_vel**2+2*g*y))/g #time when projectile hits ground n= 20 #number of instances of time want time_values = np.linspace(0,int(t),n) axes = np.zeros((2,n)) in range(0,n): axes[0,i]=x_vel*time_values[i] axes[1,i]=y_vel*time_values[i]-0.5*g*time_values[i]**2 #print time_values #print axes
Comments
Post a Comment