Difference between revisions of "Koding Optimasi"

From ccitonlinewiki
Jump to: navigation, search
(Created page with "import numpy as np from scipy.optimize import minimize def calc_drag(x):#drag x1 = x[0] drag = 0.000000001*x1**6-0.0000003*x1**5+0.00003*x1**4-0.0008*x1**3-0.0002*x1...")
 
 
Line 5: Line 5:
 
def calc_drag(x):#drag
 
def calc_drag(x):#drag
 
     x1 = x[0]
 
     x1 = x[0]
     drag = 0.000000001*x1**6-0.0000003*x1**5+0.00003*x1**4-0.0008*x1**3-0.0002*x1**2+0.4312*x1+2.7716
+
     drag = 21.185*x1**2-125.62*x1 + 143.69
 
     return drag
 
     return drag
  
 
def calc_lift(x): #lift
 
def calc_lift(x): #lift
 
     x1 = x[0]
 
     x1 = x[0]
     lift = -0.00000001*x1**5-0.000002*x1**4+0.0004*x1**3-0.0147*x1**2+0.0705*x1+5.313
+
     lift = -3.5089*x1**2 + 34.626*x1 - 43.619
 
     return lift
 
     return lift
  
 
def objective(x): #sudut yang diminimalkan
 
def objective(x): #sudut yang diminimalkan
     return calc_lift(x)
+
     return calc_drag(x)
  
 
def constraint1(x): #variable SUDUT yang meminimalkan persamaan garis drag
 
def constraint1(x): #variable SUDUT yang meminimalkan persamaan garis drag
Line 37: Line 37:
 
liftopt = calc_lift(xopt) # lift optimal
 
liftopt = calc_lift(xopt) # lift optimal
  
print ('sudut optimal = '+str(xopt[0]))
+
print ('sudut optimal = '+str(-xopt[0]))
print ('total force optimal = '+str(-forceopt))
+
print ('total force optimal = '+str(forceopt))
print ('drag force optimal = '+str(dragopt))
+
print ('drag force optimal = '+str(-dragopt))
 
print ('lift force optimal = '+str(liftopt))
 
print ('lift force optimal = '+str(liftopt))

Latest revision as of 13:26, 4 December 2019

import numpy as np from scipy.optimize import minimize


def calc_drag(x):#drag

   x1 = x[0]
   drag =  21.185*x1**2-125.62*x1 + 143.69
   return drag

def calc_lift(x): #lift

   x1 = x[0]
   lift = -3.5089*x1**2 + 34.626*x1 - 43.619
   return lift

def objective(x): #sudut yang diminimalkan

   return calc_drag(x)

def constraint1(x): #variable SUDUT yang meminimalkan persamaan garis drag

   return 90 - calc_drag(x)

def constraint2(x): #variable SUDUT yang meminimalkan persamaan garis lift

   return 90 - calc_lift(x)

con1=({'type':'ineq','fun':constraint1}) con2=({'type':'ineq','fun':constraint2}) cons = (con1,con2)

x1_guess = 50

x0 = np.array([x1_guess])

sol = minimize(objective,x0, method='SLSQP',constraints=cons, options={'disp':True})

xopt = sol.x forceopt = -sol.fun

dragopt = calc_drag(xopt) # drag optimal liftopt = calc_lift(xopt) # lift optimal

print ('sudut optimal = '+str(-xopt[0])) print ('total force optimal = '+str(forceopt)) print ('drag force optimal = '+str(-dragopt)) print ('lift force optimal = '+str(liftopt))