# 'FindFit' ignoring certain data points to optimise r^2 value

As shown in the code below,

datax = {0.001, 0.002, 0.003, 0.004, 0.005, 0.006, 0.007, 0.008,
0.009, 0.01, 0.011};
datay = {0.067361, 0.057375, 0.043718, 0.031625, 0.026091, 0.021463,
0.017203, 0.014835, 0.012202, 0.010441, 0.008802};
dataxy = Transpose[{datax, datay}];
model = (Subscript[\[Mu], 0] i R^2)/(
2 (y^2 + R^2)^(3/2)) /. {Subscript[\[Mu], 0] -> 4 \[Pi]*10^-7,
R -> 0.0065};
s = FindFit[dataxy, model, {{i}}, y]
nlm = NonlinearModelFit[dataxy, model, {{i}}, y]

p1 = ListPlot[dataxy, PlotStyle -> Red];
p2 = Plot[model /. s, {y, 0, 0.011}];
Show[p1, p2]


Mathematica outputs that the optimal value of i would be {i -> 639.813}. However, when I tried to fit for i using Desmos with i=700, the fit seems to be better.

Meanwhile, an i value of 639 gives the following graph.

Is it possible to make mathematica not ignore any of the data points just to optimise the R^2 value? Thank you.

• Mathematica is not ignoring any data points: it is optimizing the sum of the squares of the discrepancies between the calculated and experimental values. Your curve is, unfortunately, not a great fit for this data with the parameter values you gave. – MarcoB Feb 26 at 16:36

{0.000157719, 0.000269005}