我的阻力极坐标曲线拟合得到了很大的 CD 值。
以下是我的升力和阻力系数值:
升力系数
[-0.2863876 -0.15198764 -0.00709039 0.1414652 0.28727075 0.43092027
0.57339435 0.71901446 0.95383017 1.00155515 1.04740696 0.93310272]
阻力系数
[-0.02768897 -0.03168675 -0.03116817 -0.02166403 -0.00677296 0.01566423
0.04477065 0.08153319 0.16150749 0.19508941 0.21802003 0.12811101]
以下是我的代码:
def test_func(CL, k, CD_0):
return k*(CL**2) + CD_0 # drag polar function
popt, pcov = curve_fit(test_func, CD, CL, p0=[1, 0.01])
k_opt, CD_0_opt = popt
CL_model = np.linspace(min(CL), max(CL), 100)
CD_model = test_func(CL_model, k_opt, CD_0_opt)
我尝试调整初始猜测p0,对曲线拟合没有影响。
你已经快到了,但我认为你刚刚颠倒了你头脑中的“x”和“y”。如果您查看您提供的绘图,您怎么能期望曲线拟合能够拟合函数呢?它未通过功能测试,因为 $C_L$ 有多个值对应于 $C_D$ 的单个值。看看你的函数,它似乎从 $C_L$ 的值预测 $C_D$ 的值,所以在这种情况下,你的“x”是升力系数,y 是阻力系数。如果你翻转它并使用
curve_fit
它对我来说效果很好 - 请使用你的系数数据查看下面的代码和绘图:
#copying data from your post, but note that your last two data points are a little weird (either outliers with high error or maybe you copied them wrong or out of order?)
CL = numpy.array([-0.2863876, -0.15198764, -0.00709039, 0.1414652, 0.28727075, 0.43092027, 0.57339435, 0.71901446, 0.95383017, 1.00155515, 1.04740696, 0.93310272])
CD = numpy.array([-0.02768897, -0.03168675, -0.03116817, -0.02166403, -0.00677296, 0.01566423, 0.04477065, 0.08153319, 0.16150749, 0.19508941, 0.21802003, 0.12811101])
def test_func(CL, k, CD_0):
return k*(CL**2) + CD_0 # your test function, which predicts CD (y) from values of CL (x)
popt, pcov = curve_fit(test_func,CL,CD,p0=[1.,0.01]) #note that CL is first because it is the "x" variable and CD is second because that's what we are trying to match for "y"
#plot results
plt.scatter(CL,CD,marker="x",label="Data",c="dodgerblue",)
plt.plot(CL_model,CD_model,label=r"model: k = {:.2f}, $CD_0$ = {:.2f}".format(popt[0],popt[1]),c="orange")
plt.legend()
plt.xlabel(r"$C_L$")
plt.ylabel(r"$C_D$")
plt.show()