leastSquaresFit
Fernando Pérez
fperez528 at yahoo.com
Wed Jul 10 12:59:19 EDT 2002
Alex Tournier wrote:
> Fernando Pérez <fperez528 at yahoo.com> wrote in message
>> Many numeric functions do not
>> implicitly convert lists to arrays (though some can operate on lists as
>> well as arrays). Try data = Numeric.array(data) and see what happens.
>>
>> f
>
> I tried as you said, putting it through array(), but still get the same
> message! Could there be a problem with the FirstDerivatives.py module??
> Alex
Well, it seems like you need to upgrade numeric or you need to upgrade
python. On my machine (python 2.2, Numeric 20.3) it works just fine:
IPython profile: tutorial
*** Pasting of code with ">>>" or "..." has been enabled.
In [1]: >>> from Scientific.Functions.LeastSquares import leastSquaresFit
In [2]: >>> import Numeric
In [3]: >>> # The mathematical model.
In [4]: ... def exponential(parameters, x):
...: ... a = parameters[0]
...: ... b = parameters[1]
...: ... return a*Numeric.exp(-b/x)
...:
In [5]: >>> # The data to be fitted to.
In [6]: ... data = [(100, 4.999e-8),
...: ... (200, 5.307e+2),
...: ... (300, 1.289e+6),
...: ... (400, 6.559e+7)]
In [7]:
In [8]: >>> fit = leastSquaresFit(exponential, (1e13, 4700), data)
In [9]: fit
Out[9]: ([8641551709749.7666, 4715.4677901570467], 1080.2526437958597)
cheers,
f.
More information about the Python-list
mailing list