[SciPy-user] chi square value on leastsq

Fernando Avila Castro favilac at cosmos.astro.uson.mx
Wed Jun 29 13:52:25 EDT 2005


>
> x, mesg = optimize.leastsq(f, x0, ...)
>
> chi2 = sum(power(f(x), 2))
>

 	Thanks, but i'm unable to adapt it to my code:

  >>def residuals(p, y, x):
  >>    A,B,C = p
  >>    err = y - (A-B*(x**C))
  >>    return err
  >>
  >>def peval(x, p):
  >>    return (p[0] - p[1]*(x**p[2]))
  >>
  >>p0 = [ 1, 1, 1]
  >>
  >>from scipy.optimize import leastsq
  >>plsq = leastsq(residuals, p0, args=(y_meas, x))


my guess is that the last line should be changed to

  >>p, plsq = leastsq(residuals, p0, args=(y_meas, x))
  >>chi2 =sum(power(residuals,2))

but it doesn't work.

What I'm doing wrong?




More information about the SciPy-User mailing list