I have the following defined:

lvf1 = Table[{i, 1/(10 - i)}, {i, -100, 100}];

If I just run this, it gives me a "Power: Infinite expression 1/0 encountered." error, so I added this to remove that point from the dataset:

lvf1 = Delete[lvf1, 111];

It looks like this:


enter image description here

Now, when I run this:

nlm = NonlinearModelFit[lvf1, a/(b - x) + c, {a, b, c}, x];

I get all kinds of errors:

enter image description here

Why!? I've used the NonlinearModelFit function like this elsewhere, and it typically works. I can't seem to get it to work with any reciprocal/inverse type function. Please help!


Provide a non-integral initial point:

NonlinearModelFit[lvf1, a/(b - x) + c, {a, {b, π^2}, c}, x]
  • $\begingroup$ A non-integral initial point for b does remove the error messages but the initial value of $\pi$ doesn't result in an appropriate fit. If {a, {b, 9.1}, c} is used, then an appropriate fit is found. $\endgroup$ – JimB Nov 20 '18 at 1:08

You don't need initial points when using Method->"NMinimize"

nlm = NonlinearModelFit[lvf1, a/(b - x) + c, {a, b, c}, x,Method -> "NMinimize"];
Normal[nlm] (*  -8.88269*10^-9 + 1./(10. - x)  as expected*)

Show[{Plot[Normal[nlm], {x, -100, 100}, PlotStyle -> Thickness[.02]],ListPlot[lvf1, PlotStyle -> Red]}]

enter image description here

  • $\begingroup$ Do you mean that using Method -> "NMinimize" starts out with either better automatic initial points or that using that method is less sensitive in this case to the automatic initial points (which I thought was 1 for all parameters)? It's still an iterative method so there must be initial points. $\endgroup$ – JimB Nov 20 '18 at 14:26
  • $\begingroup$ @ JimB I don't know which initial points NMinimize uses, often the method is more robust than the default methods. $\endgroup$ – Ulrich Neumann Nov 20 '18 at 14:47
  • $\begingroup$ Thanks. I see now. That method is more robust which means that it is much less often that one needs to supply customized initial values. $\endgroup$ – JimB Nov 20 '18 at 15:13

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.