我已编写此代码以找到机翼的最佳迎角以获得所需的升力但不确定错误是什么。 Vortex_panel是我的uni给我的一个函数。
from scipy.optimize import minimize
def find_alpha(target_cl, points, guess):
def fixed_lift(alpha, points, target_cl):
[cl,cp,xc,yc,dy,ds,theta,vt] = vortex_panel(points,alpha,0)
f = (target_cl - cl)**2
return f
alpha_limits = ((0,90),)
alpha = minimize(fixed_lift, guess, options={'eps':0.025}, bounds =alpha_limits, args = (points, target_cl))
[cl,cp,xc,yc,dy,ds,theta,vt] = vortex_panel(points,alpha,0)
return alpha, cl
target_cl =(0.7746 / (0.9 * 0.4)) /0.92
u2 = 0.5
guess = 5
points = parametric_aerofoil2(u2)
[alpha, cl] = find_alpha(target_cl, points, guess)
print(target_cl, alpha, cl)
当我运行它时会出现此错误。
TypeError Traceback (most recent call last)
<ipython-input-35-ac6f6a05eabb> in <module>()
3 guess = 5
4 points = parametric_aerofoil2(u2)
----> 5 [alpha, cl] = find_alpha(target_cl, points, guess)
6 print(target_cl, alpha, cl)
<ipython-input-34-d30e5083ae57> in find_alpha(target_cl, points, guess)
7 alpha_limits = ((0,90),)
8 alpha = minimize(fixed_lift, guess, options={'eps':0.025}, bounds = alpha_limits, args = (points, target_cl))
----> 9 [cl,cp,xc,yc,dy,ds,theta,vt] = vortex_panel(points,alpha,0)
10 return alpha, cl
~/Documents/Aerodynamic Wing Design/Code/aclabtools.py in vortex_panel(pointsDef, alpha_deg, plot)
62 psi=np.zeros((npanel+1))
63 U=1;
---> 64 alpha=alpha_deg*np.pi/180.0;
65 for i in range(0,npanel):
66 xc[i]=(xb[i]+xb[i+1])/2.0
TypeError: unsupported operand type(s) for *: 'OptimizeResult' and 'float'
答案 0 :(得分:0)
错误是因为解释器试图将两个对象相乘并且它们的数据类型不同。 Python是一种强类型PL,也就是说数据类型必须相同才能执行此类操作。
答案 1 :(得分:0)