[SciPy-user] leastsquare N>M ?

Stefan van der Walt stefan at sun.ac.za
Wed Oct 4 11:23:34 EDT 2006


On Wed, Oct 04, 2006 at 07:20:55AM -0700, Daniel Fish wrote:
> I receive the following error from scipy.optimize.leastsq() (in scipy version
> 0.5.0.2033, python 2.4 (windows)):
>  
> # CODE--------------------------------------
> 1. from scipy.optimize import *
> 2. def func(x):
> 3.     return x[0]**2
> 4. x0=[1,0]
> 5. (y,msg)=leastsq(func,x0)
> 6. print y
>  
> #
> OUTPUT----------------------------------------------------------------------------------------------------
> File "C:/cygwin/Ksim/PythonCode/Database/test.py", line 5, in ?
> (y,msg)=leastsq(func,x0)
> File "C:\Python24\lib\site-packages\scipy\optimize\minpack.py", line 257, in
> leastsq raise errors[info][1], errors[info][0]
> TypeError: Improper input parameters.
> 2 1 1 0.000000 0.000000 0.000000 600 100.000000
> #
> -----------------------------------------------------------------------------------------------------------------
>  
> But have no problem if I let x0=[1]. Does leastsq not work with more unknowns
> than equations, or am I doing something wrong?

Leastsq is used when you have more equations than unknowns, to provide
you with an answer that minimises some norm.  In your case, rather use
'fmin', i.e.

y,msg = fmin(func,x0)

to produce y = 6.22301527786e-61

Regards
Stéfan



More information about the SciPy-User mailing list