0
$\begingroup$

I've been trying to fit logarithmic function to the data below:

d1 = {{3457, 4.22`}, {3000, 4.33`}, {2500, 4.35`}, {1200, 4.43`}, {600, 4.68`}, {300, 5.8`}, {150, 8.07`}}

I used the following code for the fitting:

nmf1 = NonlinearModelFit[d1, a + b Log[x], {a, b}, x]

g1 = ListPlot[d1];
g2 = Plot[nmf1[x], {x, 0, 3500}];
Show[g1,g2]

where g1 is the $ListPlot$ of the data d1. I got the below fit. enter image description here

I am wondering how to improve this fit. The expected function is the natural logarithm, although in this case I managed to do a much better fit with the 1/x. Additionally, I don't have an initial guess at the parameters, which I could use. Any ideas?

Thank you all for help!

$\endgroup$
  • $\begingroup$ Just an observation: your parameter c is redundant. $\endgroup$ – b.gates.you.know.what Jan 30 at 8:47
  • $\begingroup$ Right. Thanks for pointing this out. $\endgroup$ – Nejc Kejzar Jan 30 at 8:48
0
$\begingroup$

Why do you expect a logarithmic function?

Rational approximation gives a quite good fit:

nmf1 = NonlinearModelFit[d1, (a + b x)/(1 + c x), {a, b, c}, x,Method -> "NMinimize"];
Show[{ListPlot[d1],Plot[Normal[nmf1], {x, 150, 3500}, PlotRange -> All]}]

enter image description here

$\endgroup$
  • $\begingroup$ Ah, I just realized that my model was incorrect. I expected the logarithm, but for the inverse values of y. Still, your solution was and will be helpful in my analysis. May I ask - is the NMinimize the method of least-squares or something else? $\endgroup$ – Nejc Kejzar Jan 30 at 10:44
  • $\begingroup$ Usually I use "NMinimize" as a robust solver if I don't no initial parameter values. Don't no which method is used. $\endgroup$ – Ulrich Neumann Jan 30 at 10:47
  • $\begingroup$ Alright, will look into documentation. Thank you for your help! $\endgroup$ – Nejc Kejzar Jan 30 at 10:48
  • $\begingroup$ You're welcome! $\endgroup$ – Ulrich Neumann Jan 30 at 11:11

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.