Python least square
<p>I just have a little problem with my code:</p>

<pre><code>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))
</code></pre>

<p>I come up with a prompt saying name 'optimize' is not defined but I don't see where the error come from?</p>
