I have been using mathematica recently to mess around with my data. I have a method of calculating an x,y coordinate from 4 or more distance measurements coming from static receivers (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/distances, Method->"LevenbergMarquardt"]
where...
data = {{548189.217202, 5912779.96059, 93}, {548236.967784, 5912717.80716, 39},
{548359.406452, 5912752.54022, 88}, {548358.636206, 5912690.89573, 97}};
distances = {93, 39, 88, 97};
x0, y0 is the solution it finds
The mathematica output to the above is:
FittedModel[{"Nonlinear", {x0 -> 548272.0043962265,
y0 -> 5.912735710367113*^6},
{{x, y}, Sqrt[Abs[x - x0]^2 + Abs[y - y0]^2]}},
{{1/93, 1/39, 1/88, 1/97}}, {{548189.217202, 5.91277996059*^6, 93},
{548236.967784, 5.91271780716*^6, 39},
{548359.406452, 5.91275254022*^6, 88},
{548358.636206, 5.91269089573*^6, 97}},
Function[Null, Internal`LocalizedBlock[{x, x0, y, y0}, #1], {HoldAll}]]
x0, y0
are my solution.
So I am not fitting a curve but fitting to a point (with weights inversely proportional to the distance). I have looked around on google but am simply not sure where to start with the scipy function scipy.optimize.leastsq algorithm to introduce the weighting functionality...
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.