我的代码有一点问题:
def pval(x, p, i):
return sum(p[0]*(cos(i*x)) for i in range(1, p[1] + 1))
if __name__ == '__main__':
main()
x, y = loadtxt("Data.txt" , unpack=True)
errfunc = lambda p, x, y: pval(p, x, i) - y # Distance to the target function
p0 = [49, 100] # Initial guess for the parameters
p1, success = optimize.leastsq(errfunc, p0[:], args=(x, y))
我想出一个提示,说名称“优化”未定义,但我看不到错误来自哪里?