Koding Optimasi

From ccitonlinewiki
Revision as of 13:12, 4 December 2019 by Geofany.rosady (talk | contribs) (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...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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**2+0.4312*x1+2.7716
   return drag

def calc_lift(x): #lift

   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
   return lift

def objective(x): #sudut yang diminimalkan

   return calc_lift(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))