# [SciPy-user] segfault in scipy.optimize.leastsq

Nils Wagner nwagner at iam.uni-stuttgart.de
Thu Aug 3 08:18:53 CDT 2006

```basvandijk at home.nl wrote:
> Hello,
>
> When running the following example from http://www.tau.ac.il/~kineret/amit/scipy_tutorial I get an segmentationfault in leastsq:
>
> --------------------------
> from scipy import *
> from numpy import *
>
> x = arange(0,6e-2,6e-2/30)
> A,k,theta = 10, 1.0/3e-2, pi/6s
> y_true = A*sin(2*pi*k*x+theta)
> y_meas = y_true + 2*randn(len(x))
>
> def residuals(p, y, x):
>     A,k,theta = p
>     err = y-A*sin(2*pi*k*x+theta)
>     return err
>
> def peval(x, p):
>     return p[0]*sin(2*pi*p[1]*x+p[2])
>
> p0 = [8, 1/2.3e-2, pi/3]
> print array(p0)
>
> from scipy.optimize import leastsq
> plsq = leastsq(residuals, p0, args=(y_meas, x))
> print plsq[0]
>
> print array([A, k, theta])
> --------------------------
>
> Note that C:\Python24\Lib\site-packages\scipy\optimize\tests\test_optimize.py also gives an error.
>
> I'm running Python 2.4.3, Scipy 0.5.0 and numpy 1.0b1.
>
> What can be the problem?
>
> Greetings,
>
> Bas van Dijk
> _______________________________________________
> SciPy-user mailing list
> SciPy-user at scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user
>
I cannot confirm your problems on Linux.
python -i
/usr/lib64/python2.4/site-packages/scipy/optimize/tests/test_optimize.py
Found 6 tests for __main__
......
----------------------------------------------------------------------
Ran 6 tests in 0.028s

OK

The example results in
[  8.          43.47826087   1.04719755]
[-10.43031241  33.94233618   3.55891069]
[ 10.          33.33333333   0.52359878]

1.0b2.dev2946
0.5.0.2142

Nils

```

More information about the SciPy-user mailing list