# Finding a parametric curve fitting a two-dimensional dataset

I have a 2-dimensional data set where I want to find the function that fits best the points. My issue is that I am looking for a function of the for $$f(x,y)=c$$ with $$c$$ a constant. I could not find in the documentation a case representing my problem. Here is a plot of the data:

It is similar to two ellipses merging into each other. I know that my function should be of the form (or similarly to)

$$\qquad 1=\frac{a}{(x_0-x)^2+y^2}+\frac{b}{(x_0+x)^2+y^2}$$,

which plots like so:

How can I proceed to find a fit of the implicit form I show above?

Here is the data I used:

data =
{{-0.855887, 1.23263}, {-0.875589, 1.21228}, {-0.891327,
1.20512}, {-0.919476, 1.18699}, {-0.943601, 1.17521}, {-0.983361,
1.13633}, {-0.990515, 1.11895}, {-1.008, 1.08602}, {-1.04271,
1.05147}, {-1.04237, 0.997925}, {-1.06607, 0.963405}, {-1.06868,
0.924352}, {-1.08832, 0.89034}, {-1.10692, 0.866093}, {-1.11867,
0.808843}, {-1.11454, 0.766042}, {-1.13787, 0.74105}, {-1.1381,
0.693607}, {-1.15121, 0.652324}, {-1.17142, 0.640271}, {-1.15445,
0.608087}, {-1.15316, 0.572132}, {-1.16311, 0.549793}, {-1.18436,
0.471867}, {-1.17575, 0.456246}, {-1.17, 0.412655}, {-1.17564,
0.397491}, {-1.18967, 0.369696}, {-1.19634, 0.314264}, {-1.19521,
0.298567}, {-1.19089, 0.257741}, {-1.19223, 0.223899}, {-1.19144,
0.209369}, {-1.20502, 0.150798}, {-1.20081, 0.133374}, {-1.19028,
0.0793563}, {-1.19199, 0.0697826}, {-1.19732, 0.0495243}, {-1.20475,
0.0194175}, {-1.20256,
0.}, {-1.20475, -0.0194175}, {-1.19732, -0.0495243}, {-1.19199, \
-0.0697826}, {-1.19028, -0.0793563}, {-1.20081, -0.133374}, \
{-1.20502, -0.150798}, {-1.19144, -0.209369}, {-1.19223, -0.223899}, \
{-1.19089, -0.257741}, {-1.19521, -0.298567}, {-1.19634, -0.314264}, \
{-1.18967, -0.369696}, {-1.17564, -0.397491}, {-1.17, -0.412655}, \
{-1.17575, -0.456246}, {-1.18436, -0.471867}, {-1.16311, -0.549793}, \
{-1.15316, -0.572132}, {-1.15445, -0.608087}, {-1.17142, -0.640271}, \
{-1.15121, -0.652324}, {-1.1381, -0.693607}, {-1.13787, -0.74105}, \
{-1.11454, -0.766042}, {-1.11867, -0.808843}, {-1.10692, -0.866093}, \
{-1.08832, -0.89034}, {-1.06868, -0.924352}, {-1.06607, -0.963405}, \
{-1.04237, -0.997925}, {-1.04271, -1.05147}, {-1.008, -1.08602}, \
{-0.990515, -1.11895}, {-0.983361, -1.13633}, {-0.943601, -1.17521}, \
{-0.919476, -1.18699}, {-0.891327, -1.20512}, {-0.875589, -1.21228}, \
{-0.855887, -1.23263}, {-0.802557, -1.23442}, {-0.766103, -1.22296}, \
{-0.727905, -1.19628}, {-0.709136, -1.19182}, {-0.689144, -1.1763}, \
{-0.638388, -1.18462}, {-0.57201, -1.12417}, {-0.529868, -1.06153}, \
{-0.485215, -1.06533}, {-0.427717, -1.01831}, {-0.404904, -1.01607}, \
{-0.354497, -0.955641}, {-0.306101, -0.946854}, {-0.359628, \
-0.906339}, {-0.348301, -0.847555}, {-0.275226, -0.851686}, \
{-0.266341, -0.877628}, {-0.227224, -0.899483}, {-0.183498, \
-0.921461}, {-0.151174, -0.946527}, {-0.119097, -0.909398}, \
{-0.0447814, -0.87124}, {-0.0462163, -0.945964}, {-0.0492401, \
-0.993309}, {0.0206428, -1.01372}, {0.0750533, -1.04671}, {0.107607, \
-1.0703}, {0.132998, -1.11138}, {0.17688, -1.11099}, {0.211808, \
-1.15503}, {0.242667, -1.17074}, {0.287043, -1.18253}, {0.311801, \
-1.18394}, {0.340378, -1.21147}, {0.379188, -1.23046}, {0.404097, \
-1.24835}, {0.419931, -1.21946}, {0.450344, -1.20484}, {0.482074, \
-1.21409}, {0.513022, -1.19161}, {0.542811, -1.18659}, {0.556381, \
-1.15671}, {0.566781, -1.1386}, {0.580498, -1.11207}, {0.622429, \
-1.07523}, {0.630459, -1.04885}, {0.636735, -1.02733}, {0.659334, \
-0.997285}, {0.670562, -0.947068}, {0.683478, -0.908228}, {0.691492, \
-0.890117}, {0.70605, -0.870896}, {0.716609, -0.815818}, {0.721622, \
-0.774089}, {0.728854, -0.745383}, {0.724173, -0.718247}, {0.739427, \
-0.690035}, {0.748789, -0.666034}, {0.745515, -0.624616}, {0.761063, \
-0.586204}, {0.770141, -0.537633}, {0.76199, -0.517775}, {0.771748, \
-0.474633}, {0.78108, -0.45365}, {0.788651, -0.401977}, {0.787952, \
-0.351917}, {0.789077, -0.327533}, {0.795329, -0.287452}, {0.806661, \
-0.249158}, {0.798242, -0.224522}, {0.796495, -0.207547}, {0.809101, \
-0.142318}, {0.797597, -0.0916151}, {0.809132, -0.0522402}, {0.80739, \
-0.00323232}, {0.80739, 0.00323232}, {0.809132, 0.0522402}, {0.797597,
0.0916151}, {0.809101, 0.142318}, {0.796495, 0.207547}, {0.798242,
0.224522}, {0.806661, 0.249158}, {0.795329, 0.287452}, {0.789077,
0.327533}, {0.787952, 0.351917}, {0.788651, 0.401977}, {0.78108,
0.45365}, {0.771748, 0.474633}, {0.76199, 0.517775}, {0.770141,
0.537633}, {0.761063, 0.586204}, {0.745515, 0.624616}, {0.748789,
0.666034}, {0.739427, 0.690035}, {0.724173, 0.718247}, {0.728854,
0.745383}, {0.721622, 0.774089}, {0.716609, 0.815818}, {0.70605,
0.870896}, {0.691492, 0.890117}, {0.683478, 0.908228}, {0.670562,
0.947068}, {0.659334, 0.997285}, {0.636735, 1.02733}, {0.630459,
1.04885}, {0.622429, 1.07523}, {0.580498, 1.11207}, {0.566781,
1.1386}, {0.556381, 1.15671}, {0.542811, 1.18659}, {0.513022,
1.19161}, {0.482074, 1.21409}, {0.450344, 1.20484}, {0.419931,
1.21946}, {0.404097, 1.24835}, {0.379188, 1.23046}, {0.340378,
1.21147}, {0.311801, 1.18394}, {0.287043, 1.18253}, {0.242667,
1.17074}, {0.211808, 1.15503}, {0.17688, 1.11099}, {0.132998,
1.11138}, {0.107607, 1.0703}, {0.0750533, 1.04671}, {0.0206428,
1.01372}, {-0.0492401, 0.993309}, {-0.0462163,
0.945964}, {-0.0447814, 0.87124}, {-0.119097, 0.909398}, {-0.151174,
0.946527}, {-0.183498, 0.921461}, {-0.227224,
0.899483}, {-0.266341, 0.877628}, {-0.275226, 0.851686}, {-0.348301,
0.847555}, {-0.359628, 0.906339}, {-0.306101,
0.946854}, {-0.354497, 0.955641}, {-0.404904, 1.01607}, {-0.427717,
1.01831}, {-0.485215, 1.06533}, {-0.529868, 1.06153}, {-0.57201,
1.12417}, {-0.638388, 1.18462}, {-0.689144, 1.1763}, {-0.709136,
1.19182}, {-0.727905, 1.19628}, {-0.766103, 1.22296}, {-0.802557,
1.23442}, {-0.855887, 1.23263}}


A least squares approach:

model = a/((x - x01)^2 + c y^2) + a/((x - x02)^2 + c y^2)


$$\frac{a}{c y^2+(x-\text{x01})^2}+\frac{a}{c y^2+(x-\text{x02})^2}$$

If we assume the equation will be model==1, then the sum of the squares of the residuals will be:

errorfunc = Total[(1 - (model /. {x -> #[[1]], y -> #[[2]]} &) /@ data)^2];


Then, minimizing that expression, with some parameter guesses:

sol = FindMinimum[{errorfunc}, {{a, .2}, {x01, -.5}, {x02, .5}, {c, .2}}]
(* {0.715296, {a -> 0.190635, x01 -> -0.75599, x02 -> 0.360541, c -> 0.139609}} *)

Show[ListPlot[data],
ContourPlot[(model /. sol[[2]]) == 1, {x, -2, 2}, {y, -2, 2},
ContourStyle -> Red], PlotRange -> All]