CoCalc Public Filesassignments / פרוקייט גמר.ipynbOpen with one click!
Authors: Gabriela Dorfman Furman, Dvir Hamdi, yoav yefet
Views : 167
Compute Environment: Ubuntu 18.04 (Deprecated)
In [ ]:
In [ ]:
In [ ]:
In [12]:
def ternimal_vol(m,g,p,a,c):#הפונקציה מחזירהנ את המהירות המקסימלית שאובייקט יגיע אליה return ((2*m*h)/(p*a*c))**0.5
In [13]:
def Track_revaluation(m,s,vn,g,t): v_t = ternimal_vol(m,g,p,a,c) return v_t*math.tanh(v_t*t)
In [ ]:
In [ ]:
In [ ]:
In [14]:
def drag_force(Cd,A,P,V): #the sum of all forces which drag the rocket return (Cd*A*P*V**2)/2 #return the drag force #A - area #Cd - drag coefficient #P - density #V - flow veloctiy #https://he.wikipedia.org/wiki/%D7%92%D7%A8%D7%A8_(%D7%9B%D7%95%D7%97)
In [15]:
def Trust_force(m,v): #the power of the engine of the rocket return m*v #return the trusth force #m - the change of fule #v - the speed of the gass #https://he.wikipedia.org/wiki/%D7%93%D7%97%D7%A3_(%D7%9B%D7%95%D7%97)
In [16]:
#b - angle of launch #mr - mass of the rocket without fuel #fuel_tank #m = mr + fuel_tank - total mass of the rocket #A = 0.6 - Area of rocket [M**2] #g = 9.8 - gravity coefficient [N/kg , M/s**2] #W = m*g - weight of rocket [N] #p = 1.184 - dencity of fluid [kg/M**3] #dm = 100 - mass of burned fuel per second[Kg] #vw = 0 - velocity of wind [m/s] #t = 0 - time [s] #c = 0.04 - drag coefficient [no units of measurement] #lvy = [0] - list of velocitys on y axis #lvx = [0] - list of velocitys on x axis #x = [0] - list of x [M] #y = [0] - list of Y [M] #m = mr + fuel_tank - total mass of rocket #lah = [] list of acc #TFall = 0
In [17]:
def av(b,W,m): Dy = drag_force(c,A,p,lvy[t] - vw) #(Cd,A,P,V) #drag force on x axis av = ((Trust_force(dm,770) - Dy)*math.sin(b) - W) /m #vertical acceleration [N/kg , M/s**2] return av
In [18]:
def ah(b,m,c,p): Dx = drag_force(c,A,p,lvx[t] - vw) #(Cd,A,P,V) #drag force on y axis ah = ((Trust_force(dm,770) - Dx)*math.cos(b)) /m #horizonal acceleration [N/kg , M/s**2] return ah
In [19]:
def degrees(x): return(x*math.pi/180)
In [ ]:
In [20]:
import math import matplotlib.pyplot as plt import random def rocket(b,mr,fuel_tank,A,g,p,dm,vw,c): g = 9.8 m = mr + fuel_tank W = m*g lvx = [0] lvy = [0] x = [0] y = [0] lah = [] TFall = 0 time = [0] for t in range(0,2000): time.append(t) if y[-1] < 0: y.pop() x.pop() time.pop() break if fuel_tank > 0: Dx = drag_force(c,A,p,lvx[t] - vw) #(Cd,A,P,V) #drag force on y axis Dy = drag_force(c,A,p,lvy[t] - vw) #(Cd,A,P,V) #drag force on x axis av = ((Trust_force(dm,500) - Dy)*math.sin(b) - W)/m #vertical acceleration [N/kg , M/s**2] ah = ((Trust_force(dm,500) - Dx)*math.cos(b)) /m #horizonal acceleration [N/kg , M/s**2] lah.append(ah) lvy.append(lvy[-1]+av) lvx.append(lvx[-1]+ah) fuel_tank -= dm #every second the fuel ank loses mass of burned fuel m = mr + fuel_tank x.append(x[-1]+lvx[t]) y.append(y[-1]+lvy[t]) else: x.append(x[-1]+lvx[-1]) y.append(y[-1]+lvy[-1]*TFall+0.5*-g*(TFall**2)) TFall+=1 return x,y,lvx,lvy #rocket(degrees(45),100,1000,0.6,9.8,1.184,100,0,0.04)
In [21]:
def angle(): x = [] #list of x values y = [] #list of y values max_x = [] max_y = [] for k in range(91): x = rocket(degrees(k),100,1000,0.6,9.8,1.184,100,0,0.04)[0] y = rocket(degrees(k),100,1000,0.6,9.8,1.184,100,0,0.04)[1] max_x.append(max(x)) max_y.append(max(y)) return max_x,max_y
In [22]:
def angle_graph(): x,y = angle() for i in range(len(y)): plt.subplot(121) plt.plot(degrees(i),y[i],'g.') # in each point we took the highest point the rocket reached plt.xlabel('degrees(r)') plt.ylabel('y max [m]') plt.subplot(222) plt.plot(degrees(i),x[i],'b.') plt.xlabel('degrees(r)') plt.ylabel('x [m]') angle_graph()
/ext/anaconda-2019.03/lib/python3.7/site-packages/ipykernel/__main__.py:4: MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance. /ext/anaconda-2019.03/lib/python3.7/site-packages/ipykernel/__main__.py:8: MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.
In [23]:
def c(): k = 0.01 #the first value of c max_x = [] max_y = [] x = [] # list of x values y = [] # list of x values while k < 1: x = rocket(degrees(45),100,250,0.8,9.8,1.184,11,0,k)[0] y = rocket(degrees(45),100,250,0.6,9.8,1.184,11,0,k)[1] max_x.append(max(x)) # we took the max value of y from every max_y.append(max(y)) k += 0.01 return max_x,max_y def c_graph(): x,y = c() plt.subplot(121) plt.xlabel('c') plt.ylabel('y max [m]') for i in range(len(y)): plt.plot(i/100,y[i],'g.') plt.subplot(222) plt.xlabel('c') plt.ylabel('x [m]') for i in range(len(x)): plt.plot(i/100,x[i],'b.') c_graph()
In [24]:
def mass(): k = 0 max_x = [] max_y = [] x = [] # list of x values y = [] # list of x values while k < 500: x = rocket(degrees(48),k,k**3,0.8,9.8,1.184,(k**3)/2,0,0.04)[0] y = rocket(degrees(48),k,k**3,0.8,9.8,1.184,(k**3)/2,0,0.04)[1] max_x.append(max(y)) # we took the max value of y from every max_y.append(max(x)) k += 1 return max_x,max_y def mass_graph(): x,y = mass() l = [] for i in range(len(y)): l.append(i) plt.subplot(121) plt.plot(l,y,'g') plt.subplot(222) for i in range(len(x)): plt.plot(l,x,'b') mass_graph()
In [28]:
#מציאת הפרמטרים הכי טובים לטיל שיעוף הכי רחוק #print(degrees(5)) best_angle = angle()[0].index(max(angle()[0])) best_c = (c()[0].index(max(c()[0]))+1)/100 best_mass = mass()[0].index(max(mass()[0])) print(best_mass) #(b,mr,fuel_tank,A,g,p,dm,vw,c) print(best_angle) best_rocket = rocket(best_angle,best_mass,2.73*best_mass,0.8,9.8,1.184,best_mass**5,0,best_c) print(best_rocket[0]) plt.plot(best_rocket[0],'b')
499 48 [0, 0, -5320363000529.631]
[<matplotlib.lines.Line2D at 0x7f26681d0f50>]
In [26]:
lvx = rocket(degrees(45),100,273,0.8,9.8,1.184,135,0,0.04)[2] lvy = rocket(degrees(45),100,273,0.8,9.8,1.184,135,0,0.04)[3] print(math.sqrt(max(lvy)**2+max(lvx)**2)) #rocket(b,mr,fuel_tank,A,g,p,dm,vw,c)
1058.346985907718
In [ ]:
In [ ]: