0
$\begingroup$

We have a list which is considered to be fitted by a suitable function. The list is given at the end of the text. It maybe important to mention that the first column of the list is not in the same interval I mean:

list[[All, 1]][[1 ;; 50]] has an interval of 2*10^-6
list[[All, 1]][[51 ;; 150]] has an interval of 10^-5

We have exploited of

nlf=NonlinearModelFit[list, a Exp[b g] + c, {a, {b, -1}, c},
g]

But we encountered the message: "Failed to converge to the requested accuracy or precision within 100 iterations."

How can we overcome this problem? Does the problem arise of the not same interval of the first column of data?

list={{0., 0.499999}, {2.*10^-7, 0.499311}, {4.*10^-7, 
0.499025}, {6.*10^-7, 0.498806}, {8.*10^-7, 0.498621}, {1.*10^-6, 
0.498459}, {1.2*10^-6, 0.498311}, {1.4*10^-6, 0.498176}, {1.6*10^-6,
 0.49805}, {1.8*10^-6, 0.497931}, {2.*10^-6, 0.497819}, {2.2*10^-6, 
0.497713}, {2.4*10^-6, 0.497611}, {2.6*10^-6, 0.497513}, {2.8*10^-6,
0.497419}, {3.*10^-6, 0.497328}, {3.2*10^-6, 0.49724}, {3.4*10^-6, 
0.497155}, {3.6*10^-6, 0.497072}, {3.8*10^-6, 0.496992}, {4.*10^-6, 
0.496914}, {4.2*10^-6, 0.496837}, {4.4*10^-6, 0.496752}, {4.6*10^-6,
0.496679}, {4.8*10^-6, 0.496607}, {5.*10^-6, 0.496537}, {5.2*10^-6,
0.496468}, {5.4*10^-6, 0.4964}, {5.6*10^-6, 0.496334}, {5.8*10^-6, 
0.496268}, {6.*10^-6, 0.496204}, {6.2*10^-6, 0.496141}, {6.4*10^-6, 
0.496079}, {6.6*10^-6, 0.496017}, {6.8*10^-6, 0.495957}, {7.*10^-6, 
0.495898}, {7.2*10^-6, 0.495839}, {7.4*10^-6, 0.495781}, {7.6*10^-6,
0.495724}, {7.8*10^-6, 0.495668}, {8.*10^-6, 0.495612}, {8.2*10^-6,
0.495557}, {8.4*10^-6, 0.495503}, {8.6*10^-6, 
0.495449}, {8.8*10^-6, 0.495396}, {9.*10^-6, 0.495344}, {9.2*10^-6, 
0.495292}, {9.4*10^-6, 0.495241}, {9.6*10^-6, 0.49519}, {9.8*10^-6, 
0.49514}, {0.00001, 0.49509}, {0.000011, 0.494848}, {0.000021, 
0.492857}, {0.000031, 0.491298}, {0.000041, 0.48997}, {0.000051, 
0.488791}, {0.000061, 0.487719}, {0.000071, 0.486728}, {0.000081, 
0.485803}, {0.000091, 0.48493}, {0.000101, 0.484102}, {0.000111, 
0.483312}, {0.000121, 0.482555}, {0.000131, 0.481827}, {0.000141, 
0.481125}, {0.000151, 0.480446}, {0.000161, 0.479788}, {0.000171, 
0.479148}, {0.000181, 0.478526}, {0.000191, 0.477919}, {0.000201, 
0.477328}, {0.000211, 0.476749}, {0.000221, 0.476184}, {0.000231, 
0.47563}, {0.000241, 0.475087}, {0.000251, 0.474555}, {0.000261, 
0.474032}, {0.000271, 0.473518}, {0.000281, 0.473013}, {0.000291, 
0.472516}, {0.000301, 0.472027}, {0.000311, 0.471545}, {0.000321, 
0.471071}, {0.000331, 0.470603}, {0.000341, 0.470141}, {0.000351, 
0.469686}, {0.000361, 0.469236}, {0.000371, 0.468792}, {0.000381, 
0.468354}, {0.000391, 0.467921}, {0.000401, 0.467492}, {0.000411, 
0.467069}, {0.000421, 0.46665}, {0.000431, 0.466236}, {0.000441, 
0.465826}, {0.000451, 0.46542}, {0.000461, 0.465018}, {0.000471, 
0.46462}, {0.000481, 0.464226}, {0.000491, 0.463836}, {0.000501, 
0.463449}, {0.000511, 0.463066}, {0.000521, 0.462685}, {0.000531, 
0.462309}, {0.000541, 0.461935}, {0.000551, 0.461564}, {0.000561, 
0.461197}, {0.000571, 0.460832}, {0.000581, 0.46047}, {0.000591, 
0.460111}, {0.000601, 0.459755}, {0.000611, 0.459401}, {0.000621, 
0.45905}, {0.000631, 0.458701}, {0.000641, 0.458355}, {0.000651, 
0.458011}, {0.000661, 0.45767}, {0.000671, 0.457331}, {0.000681, 
0.456994}, {0.000691, 0.456659}, {0.000701, 0.456326}, {0.000711, 
0.455996}, {0.000721, 0.455667}, {0.000731, 0.45534}, {0.000741, 
0.455016}, {0.000751, 0.454693}, {0.000761, 0.454373}, {0.000771, 
0.454054}, {0.000781, 0.453737}, {0.000791, 0.453421}, {0.000801, 
0.453108}, {0.000811, 0.452796}, {0.000821, 0.452486}, {0.000831, 
0.452177}, {0.000841, 0.45187}, {0.000851, 0.451565}, {0.000861, 
0.451261}, {0.000871, 0.450959}, {0.000881, 0.450658}, {0.000891, 
0.450359}, {0.000901, 0.450061}, {0.000911, 0.449765}, {0.000921, 
0.44947}, {0.000931, 0.449177}, {0.000941, 0.448885}, {0.000951, 
0.448594}, {0.000961, 0.448304}, {0.000971, 0.448016}, {0.000981, 
0.44773}, {0.000991, 0.447444}};
$\endgroup$
  • $\begingroup$ The simple answer is "No, that's not why it's getting stuck." It's getting stuck because the model is not appropriate for the data (even though that error message goes away when the option MaxIterations -> 2000 is included. You might want to try a - b g^0.5 for the model. $\endgroup$ – JimB May 27 '17 at 6:46
  • $\begingroup$ Very amazing. I thought Exp can fit the data!! $\endgroup$ – Unbelievable May 27 '17 at 7:12
2
$\begingroup$

Given the question:

Does fitting data get stuck by non-homogeneous interval of data?

and OP's comment:

I thought Exp can fit the data!!

I would say the situation could have been quickly diagnosed with FindFormula:

ff = FindFormula[list]

(* 0.497329 - 150.254 #1 + 306909. #1^2 - 3.56245*10^8 #1^3 + 1.5053*10^11 #1^4 & *)

ListPlot[{list, {#, ff[#]} & /@ list[[All, 1]]}, 
 PlotTheme -> "Detailed", PlotLegends -> {"data", "fit"}]

enter image description here

See Jim Baldwin's answer for more detailed analysis.

|improve this answer|||||
$\endgroup$
2
$\begingroup$

The irregular spacing of the data has nothing to do with it. You could eliminate the warning by just using MaxIterations=2000 but that wouldn't fix the problem that the functional form you're using gives a poor fit.

nlf = NonlinearModelFit[list, a Exp[b g] + c, {a, {b, -1}, c}, g, MaxIterations -> 2000];
Show[ListPlot[list], Plot[nlf[g], {g, 0, 0.001}]]

data and poor fit

For this data a function of the form $a-b g^c$ gives a good fit.

nlf = NonlinearModelFit[list, a - b  If[g == 0, 0, g^c], {{a, 0.5}, {b, 2}, {c, 0.5}}, g];
nlf["BestFitParameters"]
(* {a -> 0.49971290516938405, b -> 2.0435760088187127, c -> 0.5303297586312835} *)
Show[ListPlot[list], Plot[nlf[g], {g, 0, 0.001}]]

Data and fit

Note that rather than just using g^c I've had to use If[g==0, 0, g^c] because NonlinearFit complains with just g^c. (Alternatively with this much data and low variability about the curve one could just drop the first data point where g=0 using list[[2;;]] in place of list. But I'm adverse to dropping data.)

|improve this answer|||||
$\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.