"Harold Fellermann" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > I am trying to fit a powerlaw to a small dataset using > Scientific.Functions.LeastSquares fit.
This is a bit off-topic here, and normally better for the scipy list, but I have some experience with nonlinear least squares. > Unfortunately, the algorithm seems to diverge and throws an > OverflowException. Assuming the program is okay, this means that either the function mismatches the data or the initial values are too far off to converge. > Here is how I try it: >>>> from Scientific.Functions.LeastSquares import leastSquaresFit >>>> >>>> data = [ > ... (2.5, 589.0, 0.10000000000000001), > ... (7.5, 442.0, 0.10000000000000001), > ... (12.5, 96.0, 0.10000000000000001), I presume that tuples are x, y, some_error_indicator. But the last does not matter here. >>>> def powerlaw((a,b),x) : > ... return a*x**b Did you try plotting logx versus log y to see if you get approximately a straight line? If so, the intercept and slope are estimates of loga and b. > ... >>>> params,chisq = leastSquaresFit(powerlaw,(10,-3),data) I presume (10,-3) is the starting (a,b). But, for instance 10*7.5**-3 = .02, which has no relation to 442, whereas, for instance, 1000*7.5-.75 = 221, which is in the ballpark, at least. So (a,b)=(1000, -.75) might have a chance. Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list