# [SciPy-User] A NonLinearModelFit algorithm

Martin Harrison martin.james.harrison@gmail....
Thu Mar 7 08:00:53 CST 2013

```Hi All - I am very new to scipy so bare with me please :-)

I have been using mathematica recently to mess around with my data. I have
a method of calculating an x,y coordinate from 2 or more distance
measurements coming from static devices (also x,y coords).

The function I use to do this most effectively with the data I have is the
mathematica function:

NonlinearModelFit[data, Norm[{x, y} - {x0, y0}], {x0, y0}, {x, y}, Weights
-> 1/observations^2]

where...

data = {{548189.217202, 5912779.96059, 93}, {548236.967784, 5912717.80716,
39}, {548359.406452, 5912752.54022, 88}, {548358.636206, 5912690.89573,
97}};

observations = {93, 39, 88, 97};

x0, y0 is my solution

The mathematica output to the above is:

FittedModel[{"Nonlinear", {x0 -> *548334.5910278788*, y0 -> *
5.912703316316227*^6*}, {{x, y}, Sqrt[Abs[x - x0]^2 + Abs[y - y0]^2]}},

{{1/9604, 1/16900, 1/3249, 1/676, 1/900}}, {{548236.967784,
5.91271780716*^6, 98}, {548236.967784, 5.91271780716*^6, 130},

{548359.406452, 5.91275254022*^6, 57}, {548358.636206, 5.91269089573*^6,
26}, {548358.636206, 5.91269089573*^6, 30}},

Function[Null, Internal`LocalizedBlock[{x, x0, y, y0}, #1], {HoldAll}]]

Figures in bold are my x0,y0 solution.

So I am not fitting a curve but fitting to a point (with weights inversely
proportional to the squared distance). I have looked around on google but
am simply not sure where to start with this.

Any help with this would be very much appreciated.

So why am I doing this if mathematica does it? Well to call
mathematicascript (using subprocess module) from python code is too slow
for what I want to do with live data so want to try rewriting in python to
see if the speed can be improved....
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20130307/b233f95e/attachment-0001.html
```

More information about the SciPy-User mailing list