我使用未校准的指南针在现场收集了简单的调查数据。意识到这个问题,在现场,将一个好的罗盘与未校准的罗盘进行了比较,并记录了 11 个方位的差异。该图显示差异非常接近 sin 函数。我希望将多项式(3 次)拟合到这个结果函数中,以使用未校准的罗盘来校正测量数据。我的曲线拟合程序产生的拟合曲线很差。谁能看到有什么问题?
import numpy as np
import scipy
import pylab
correctCompass=\
np.array([134.4,112.6,069.7,051.1,352.5,314.6,218.3,258.2,237.8,186.5,153.7])
errorCompass=\
np.array([131.6,108.9,065.6,047.0,349.8,314.0,284.6,262.7,243.4,189.8,153.2])
# sort compass values
for i in range(0,11):
for j in range(i+1,11):
if correctCompass[i] > correctCompass[j]:
tmp=correctCompass[j]
correctCompass[j]=correctCompass[i]
correctCompass[i]=tmp
tmp=errorCompass[j]
errorCompass[j]=errorCompass[i]
errorCompass[i]=tmp
diff = correctCompass - errorCompass + 15.0
height=diff.max() + 16.0
polycoeffs = scipy.polyfit(correctCompass, diff, 3)
# fit the data with a polynomial
yfit = scipy.polyval(polycoeffs,correctCompass)
pylab.plot(correctCompass, diff, 'k.')
pylab.plot(correctCompass, yfit, 'r-')
pylab.axis([0,360,-10.0,height])
pylab.show()