2
$\begingroup$

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. enter image description here

Meanwhile, an i value of 639 gives the following graph. enter image description here

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

$\endgroup$
1
  • 3
    $\begingroup$ 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. $\endgroup$ – MarcoB Feb 26 at 16:36
8
$\begingroup$

If you draw the plot a bit less squeezed along the horizontal axis it looks like:

enter image description here

The blue curve is from MMA and the orange one from you. Although your curves fits the first 2 points better it is far worse for the other points. In fact, the error square sum for the first and second curve are:

{0.000157719, 0.000269005}

You see, the squared error sum is smaller for the MMA curve.

If you want to fit the first 2 points better, you may use a weighted fit.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.