# [SciPy-User] leastsq (probably simple) question

Kevin Gullikson kevin.gullikson@gmail....
Sun Feb 24 20:40:56 CST 2013

```Hey all,

I am trying to use scipy.optimize.leastsq to do a one-parameter fit. The
final result is not very sensitive to the exact value, so I am wondering
how you can limit leastsq to stop iterating once the values it is testing
are reasonably close together? Example output from my code:

Resolution-fitting X^2 =  1056.95654172 at R =  [ 51908.71176496]
Resolution-fitting X^2 =  1054.42705462 at R =  [ 51908.71170349]
Resolution-fitting X^2 =  1054.42705427 at R =  [ 51908.71174447]
Resolution-fitting X^2 =  1056.95654172 at R =  [ 51908.71176496]
Resolution-fitting X^2 =  1056.95654172 at R =  [ 51908.71176496]
Resolution-fitting X^2 =  1054.42705436 at R =  [ 51908.71173423]
Resolution-fitting X^2 =  1056.95654181 at R =  [ 51908.71175472]
Resolution-fitting X^2 =  1054.42705431 at R =  [ 51908.71173935]
Resolution-fitting X^2 =  1054.42705427 at R =  [ 51908.71174447]
Resolution-fitting X^2 =  1054.42705427 at R =  [ 51908.71174447]
Resolution-fitting X^2 =  1054.42705427 at R =  [ 51908.71174447]
Resolution-fitting X^2 =  3408043.11138 at R =  [ 216058.47126214]
Resolution-fitting X^2 =  1054.8705442 at R =  [ 51857.89239384]
Resolution-fitting X^2 =  1054.64687339 at R =  [ 51883.47239909]
Resolution-fitting X^2 =  1054.53612148 at R =  [ 51896.17634439]
Resolution-fitting X^2 =  1054.48119765 at R =  [ 51902.48582026]
Resolution-fitting X^2 =  1054.4539391 at R =  [ 51905.61951157]
Resolution-fitting X^2 =  1054.44040558 at R =  [ 51907.1759188]
Resolution-fitting X^2 =  1054.4336851 at R =  [ 51907.9489416]
Resolution-fitting X^2 =  1054.43034753 at R =  [ 51908.33288072]
Resolution-fitting X^2 =  1054.42868992 at R =  [ 51908.52357292]
Resolution-fitting X^2 =  1054.42786665 at R =  [ 51908.61828465]
Resolution-fitting X^2 =  1054.42745775 at R =  [ 51908.66532545]
Resolution-fitting X^2 =  1054.42725467 at R =  [ 51908.68868937]
Resolution-fitting X^2 =  1054.4271538 at R =  [ 51908.70029361]
Resolution-fitting X^2 =  1054.4271037 at R =  [ 51908.70605713]
Resolution-fitting X^2 =  1054.42707882 at R =  [ 51908.70891972]
Resolution-fitting X^2 =  1054.42706646 at R =  [ 51908.71034149]

The parameter I am adjusting is R (the resolution of a spectrograph), and
as you can see it is doing these tiny changes which have very little affect
on the X^2 value (that is not reduced X^2, so don't worry that it isn't
near 1!)

Is there a way to tell leastsq to stop once it gets to say 51908 (in this
example)?

Kevin Gullikson
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20130224/b094889f/attachment-0001.html
```